fix(routine): resolove routine blocker logic bug and white screen
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
feat(gamification): add streak bonuses, tooltip, and improved history details fix(ep): resolve double counting ep bug ui: update app icon and translations
This commit is contained in:
+46
-2
@@ -151,8 +151,52 @@ export function setupAuth(app: Express) {
|
||||
});
|
||||
});
|
||||
|
||||
app.get("/api/user", (req, res) => {
|
||||
app.get("/api/user", async (req, res) => {
|
||||
if (!req.isAuthenticated()) return res.sendStatus(401);
|
||||
res.json(req.user);
|
||||
|
||||
// Check for Daily Streak
|
||||
const user = req.user as User;
|
||||
const now = new Date();
|
||||
const lastActive = user.lastActive ? new Date(user.lastActive) : new Date(0);
|
||||
|
||||
// Normalize to dates (ignore time)
|
||||
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
||||
const lastDate = new Date(lastActive.getFullYear(), lastActive.getMonth(), lastActive.getDate());
|
||||
const yesterday = new Date(today);
|
||||
yesterday.setDate(yesterday.getDate() - 1);
|
||||
|
||||
// If last active was yesterday, increment streak
|
||||
// If last active was today, do nothing
|
||||
// If last active was before yesterday, reset streak (unless we decide to be lenient)
|
||||
|
||||
// We need GamificationService here
|
||||
const { GamificationService } = await import("./gamification");
|
||||
const gamificationService = new GamificationService(storage);
|
||||
|
||||
if (lastDate.getTime() < today.getTime()) {
|
||||
if (lastDate.getTime() === yesterday.getTime()) {
|
||||
// Perfect streak
|
||||
await gamificationService.awardXP(user.id, 'daily_streak');
|
||||
// Check bonuses
|
||||
const updatedUser = await storage.getUser(user.id);
|
||||
if (updatedUser) {
|
||||
await gamificationService.checkStreakBonuses(user.id, updatedUser.currentStreak);
|
||||
}
|
||||
} else if (lastDate.getTime() < yesterday.getTime()) {
|
||||
// Streak broken
|
||||
// Reset streak to 1 (today is day 1)
|
||||
await storage.updateUser(user.id, { currentStreak: 1 });
|
||||
// Still award daily XP for today? Yes.
|
||||
await gamificationService.awardXP(user.id, 'daily_streak');
|
||||
} else {
|
||||
// Should not happen if < today
|
||||
}
|
||||
// Update lastActive
|
||||
await storage.updateUser(user.id, { lastActive: now });
|
||||
}
|
||||
|
||||
// Re-fetch user to get latest XP and Streak
|
||||
const freshUser = await storage.getUser(user.id);
|
||||
res.json(freshUser);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user