From 39742fceaa78124b59c3bc253bcba1d551d104ba Mon Sep 17 00:00:00 2001 From: noodleofdeath Date: Thu, 14 Mar 2024 13:03:34 -0400 Subject: [PATCH] api fix achievements --- src/server/src/api/index.ts | 2 ++ src/server/src/worker/NotificationsWorker.ts | 21 -------------------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/src/server/src/api/index.ts b/src/server/src/api/index.ts index e4a67881..534b1a05 100644 --- a/src/server/src/api/index.ts +++ b/src/server/src/api/index.ts @@ -7,6 +7,7 @@ import winston from 'winston'; import v1router from './v1'; import { preprocessHeadersMiddleware, rateLimitMiddleware } from './v1/middleware'; import { + Achievement, Category, Locale, Publisher, @@ -19,6 +20,7 @@ import { DBService } from '../services'; async function main() { await DBService.prepare(); + Achievement.prepare(); Locale.prepare(); Queue.prepare(); Role.prepare(); diff --git a/src/server/src/worker/NotificationsWorker.ts b/src/server/src/worker/NotificationsWorker.ts index c6576c65..6aa1d3f9 100644 --- a/src/server/src/worker/NotificationsWorker.ts +++ b/src/server/src/worker/NotificationsWorker.ts @@ -2,7 +2,6 @@ import ms from 'ms'; import { Op } from 'sequelize'; import { - Achievement, Queue, Subscription, User, @@ -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() { @@ -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();