fix notifications not clearing

This commit is contained in:
Face 2025-07-15 19:11:50 +03:00
parent edca4d5ceb
commit 6956149a3d
4 changed files with 44 additions and 28 deletions

View file

@ -55,24 +55,22 @@ export const PATCH: RequestHandler = async ({ request }) => {
if (!session?.user) throw error(401, 'Not authenticated');
const userId = Number(session.user.id);
const { ids, markAsRead } = await request.json();
const { markAsRead } = await request.json();
if (!Array.isArray(ids) || typeof markAsRead !== 'boolean') {
if (typeof markAsRead !== 'boolean') {
throw error(400, 'Invalid request body');
}
try {
await db
.update(notifications)
.set({ isRead: markAsRead })
.where(and(
eq(notifications.userId, userId),
inArray(notifications.id, ids)
));
if (markAsRead) {
await db.update(notifications)
.set({ isRead: true })
.where(eq(notifications.userId, userId));
}
return json({ success: true });
} catch (e) {
console.error('Failed to update notifications:', e);
throw error(500, 'Failed to update notifications');
}
};
};

View file

@ -13,10 +13,32 @@ const REWARD_TIERS = [
1500, // Day 2
1800, // Day 3
2100, // Day 4
2500, // Day 5
3000, // Day 6
3500, // Day 7
4000, // Day 8+
2500, // Day 5
3000, // Day 6
3500, // Day 7
4000, // Day 8
4200, // Day 9
4400, // Day 10
4600, // Day 11
4800, // Day 12
5000, // Day 13
5200, // Day 14
5400, // Day 15
5600, // Day 16
5800, // Day 17
6000, // Day 18
6200, // Day 19
6400, // Day 20
6600, // Day 21
6800, // Day 22
7000, // Day 23
7200, // Day 24
7400, // Day 25
7600, // Day 26
7800, // Day 27
8000, // Day 28
8200, // Day 29
8500 // Day 30+
];
const PRESTIGE_MULTIPLIERS = {

View file

@ -33,9 +33,7 @@
const unreadIds = ($NOTIFICATIONS || []).filter((n) => !n.isRead).map((n) => n.id);
newNotificationIds = unreadIds;
if (unreadIds.length > 0) {
await markNotificationsAsRead(unreadIds);
}
await markNotificationsAsRead();
} catch (error) {
toast.error('Failed to load notifications');
} finally {