mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-04-14 19:47:03 +00:00
fix(sunset): Challenge filtering, transactions
This commit is contained in:
parent
14518b8213
commit
3109a03055
2 changed files with 12 additions and 35 deletions
|
|
@ -28,7 +28,12 @@ async function updateGroup (guild) {
|
|||
return console.warn(`Leader not found for Guild ${guild._id}`);
|
||||
}
|
||||
|
||||
await leader.updateOne({ $inc: { balance: guild.balance }}).exec();
|
||||
await leader.updateBalance(
|
||||
guild.balance,
|
||||
'create_guild',
|
||||
'',
|
||||
'Guild Bank refund',
|
||||
);
|
||||
|
||||
return guild.updateOne({ $set: { balance: 0 } }).exec();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -303,23 +303,17 @@ schema.statics.getGroups = async function getGroups (options = {}) {
|
|||
}));
|
||||
break;
|
||||
}
|
||||
case 'guilds': {
|
||||
const query = {
|
||||
type: 'guild',
|
||||
_id: { $in: user.guilds, $ne: TAVERN_ID },
|
||||
};
|
||||
_.assign(query, filters);
|
||||
const userGuildsQuery = this.find(query).select(groupFields);
|
||||
if (populateLeader === true) userGuildsQuery.populate('leader', nameFields);
|
||||
userGuildsQuery.sort(sort).exec();
|
||||
queries.push(userGuildsQuery);
|
||||
break;
|
||||
}
|
||||
case 'privateGuilds': {
|
||||
const query = {
|
||||
type: 'guild',
|
||||
privacy: 'private',
|
||||
_id: { $in: user.guilds },
|
||||
'purchased.plan.customerId': { $exists: true },
|
||||
$or: [
|
||||
{ 'purchased.plan.dateTerminated': null },
|
||||
{ 'purchased.plan.dateTerminated': { $exists: false } },
|
||||
{ 'purchased.plan.dateTerminated': { $gt: new Date() }},
|
||||
],
|
||||
};
|
||||
_.assign(query, filters);
|
||||
const privateGuildsQuery = this.find(query).select(groupFields);
|
||||
|
|
@ -328,28 +322,6 @@ schema.statics.getGroups = async function getGroups (options = {}) {
|
|||
queries.push(privateGuildsQuery);
|
||||
break;
|
||||
}
|
||||
// NOTE: when returning publicGuilds we use `.lean()` so all
|
||||
// mongoose methods won't be available.
|
||||
// Docs are going to be plain javascript objects
|
||||
case 'publicGuilds': {
|
||||
const query = {
|
||||
type: 'guild',
|
||||
privacy: 'public',
|
||||
_id: { $ne: TAVERN_ID },
|
||||
};
|
||||
_.assign(query, filters);
|
||||
|
||||
const publicGuildsQuery = this.find(query).select(groupFields);
|
||||
|
||||
if (populateLeader === true) publicGuildsQuery.populate('leader', nameFields);
|
||||
if (paginate === true) {
|
||||
publicGuildsQuery.limit(GUILDS_PER_PAGE).skip(page * GUILDS_PER_PAGE);
|
||||
}
|
||||
publicGuildsQuery.sort(sort).lean().exec();
|
||||
queries.push(publicGuildsQuery);
|
||||
|
||||
break;
|
||||
}
|
||||
case 'tavern': {
|
||||
if (types.indexOf('publicGuilds') === -1) {
|
||||
queries.push(this.getGroup({ user, groupId: TAVERN_ID, fields: groupFields }));
|
||||
|
|
|
|||
Loading…
Reference in a new issue