mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-13 20:57:24 +01:00
* make comment more accurate: members are removed, not banned They can rejoin with an invitation in a private group or at any time in a public group. * change windows line breaks to unix line breaks * change flavour text of Golden Knight collection quest to reduce number of testimonies * fix grammatical error noticed by mandyzhou * improve message about not being able to send PMs because we often see people report it as a bug * update instructions for cancelling Google subscriptions (thanks to Scea for noticing) * change Delete Completed on-hover message - fixes #8598 * correct the Orb of Rebirth's text about pets and mounts (they are not locked)
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
import Bluebird from 'Bluebird';
|
|
|
|
import { model as Challenges } from '../../website/server/models/challenge';
|
|
import { model as User } from '../../website/server/models/user';
|
|
|
|
async function syncChallengeToMembers (challenges) {
|
|
let challengSyncPromises = challenges.map(async function (challenge) {
|
|
let users = await User.find({
|
|
// _id: '',
|
|
challenges: challenge._id,
|
|
}).exec();
|
|
|
|
let promises = [];
|
|
users.forEach(function (user) {
|
|
promises.push(challenge.syncToUser(user));
|
|
promises.push(challenge.save());
|
|
promises.push(user.save());
|
|
});
|
|
|
|
return Bluebird.all(promises);
|
|
});
|
|
|
|
return await Bluebird.all(challengSyncPromises);
|
|
}
|
|
|
|
async function syncChallenges (lastChallengeDate) {
|
|
let query = {
|
|
// _id: '',
|
|
};
|
|
|
|
if (lastChallengeDate) {
|
|
query.createdOn = { $lte: lastChallengeDate };
|
|
}
|
|
|
|
let challengesFound = await Challenges.find(query)
|
|
.limit(10)
|
|
.sort('-createdAt')
|
|
.exec();
|
|
|
|
let syncedChallenges = await syncChallengeToMembers(challengesFound)
|
|
.catch(reason => console.error(reason));
|
|
let lastChallenge = challengesFound[challengesFound.length - 1];
|
|
if (lastChallenge) syncChallenges(lastChallenge.createdAt);
|
|
return syncedChallenges;
|
|
};
|
|
|
|
module.exports = syncChallenges;
|