Days off workouts on Tracker view
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user