Days off workouts on Tracker view

This commit is contained in:
AG
2025-12-13 19:40:40 +02:00
parent dbb4beb56d
commit 003c045621
9 changed files with 145 additions and 4 deletions

View File

@@ -40,6 +40,17 @@ export class SessionController {
}
}
static async getLastSession(req: any, res: Response) {
try {
const userId = req.user.userId;
const session = await SessionService.getLastWorkoutSession(userId);
return sendSuccess(res, { session });
} catch (error) {
logger.error('Error in getLastSession', { error });
return sendError(res, 'Server error', 500);
}
}
static async updateActiveSession(req: any, res: Response) {
try {
const userId = req.user.userId;

View File

@@ -11,6 +11,7 @@ router.use(authenticateToken);
router.get('/', SessionController.getAllSessions);
router.post('/', validate(sessionSchema), SessionController.saveSession);
router.get('/active', SessionController.getActiveSession);
router.get('/active/last', SessionController.getLastSession);
router.put('/active', validate(sessionSchema), SessionController.updateActiveSession);
router.get('/quick-log', SessionController.getTodayQuickLog);
router.post('/quick-log/set', validate(logSetSchema), SessionController.logSetToQuickLog);

View File

@@ -25,6 +25,19 @@ export class SessionService {
}));
}
static async getLastWorkoutSession(userId: string) {
const session = await prisma.workoutSession.findFirst({
where: {
userId,
type: { not: 'QUICK_LOG' },
endTime: { not: null }
},
orderBy: { endTime: 'desc' },
select: { endTime: true }
});
return session;
}
static async saveSession(userId: string, data: any) {
const { id, startTime, endTime, userBodyWeight, note, planId, planName, sets } = data;