Skip to content

Commit

Permalink
Merge pull request #880 from NoodleOfDeath/dev
Browse files Browse the repository at this point in the history
~api fix achievements
  • Loading branch information
NoodleOfDeath authored Mar 14, 2024
2 parents 74d150f + 39742fc commit 6da2fbe
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
2 changes: 2 additions & 0 deletions src/server/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import winston from 'winston';
import v1router from './v1';
import { preprocessHeadersMiddleware, rateLimitMiddleware } from './v1/middleware';
import {
Achievement,
Category,
Locale,
Publisher,
Expand All @@ -19,6 +20,7 @@ import { DBService } from '../services';
async function main() {

await DBService.prepare();
Achievement.prepare();
Locale.prepare();
Queue.prepare();
Role.prepare();
Expand Down
21 changes: 0 additions & 21 deletions src/server/src/worker/NotificationsWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import ms from 'ms';
import { Op } from 'sequelize';

import {
Achievement,
Queue,
Subscription,
User,
Expand All @@ -18,12 +17,10 @@ import {
async function main() {
await DBService.prepare();
await Queue.prepare();
await Achievement.prepare();
ScribeService.prepare();
doWork();
sendDailyPushNotifications();
//sendStreakPushNotifications();
detectAndAssignAchievements();
}

export async function doWork() {
Expand Down Expand Up @@ -134,22 +131,4 @@ export async function sendStreakPushNotifications() {
}
}

async function detectAndAssignAchievements() {
try {
for (const criteria of Achievement.ACHIEVEMENT_CRITERIA) {
const achievement = await Achievement.findOne({ where: { name: criteria.name } });
if (!achievement || (criteria.beforeDateBased && criteria.beforeDateBased < new Date())) {
continue;
}
const users = await criteria.findCandidates();
console.log(`found ${users.length} candidates for achievement ${achievement.name}`);
users.forEach(async (user) => await user.grantAchievement(achievement));
}
} catch (e) {
console.error(e);
} finally {
setTimeout(() => detectAndAssignAchievements(), 30_000);
}
}

main();

0 comments on commit 6da2fbe

Please sign in to comment.