feat: Update enrollment last accessed timestamp on course content access and correct k6 test comment typo.
This commit is contained in:
parent
096b5bbc52
commit
ce2a472cac
2 changed files with 23 additions and 12 deletions
|
|
@ -340,6 +340,17 @@ export class CoursesStudentService {
|
||||||
throw new ForbiddenError('You are not enrolled in this course');
|
throw new ForbiddenError('You are not enrolled in this course');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update last_accessed_at (fire-and-forget — ไม่ block response)
|
||||||
|
prisma.enrollment.update({
|
||||||
|
where: {
|
||||||
|
unique_enrollment: {
|
||||||
|
user_id: decoded.id,
|
||||||
|
course_id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data: { last_accessed_at: new Date() },
|
||||||
|
}).catch(err => logger.warn(`Failed to update last_accessed_at: ${err}`));
|
||||||
|
|
||||||
// Get all lesson progress for this user and course
|
// Get all lesson progress for this user and course
|
||||||
const lessonIds = course.chapters.flatMap(ch => ch.lessons.map(l => l.id));
|
const lessonIds = course.chapters.flatMap(ch => ch.lessons.map(l => l.id));
|
||||||
const lessonProgress = await prisma.lessonProgress.findMany({
|
const lessonProgress = await prisma.lessonProgress.findMany({
|
||||||
|
|
@ -1249,17 +1260,17 @@ export class CoursesStudentService {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error completing lesson: ${error}`);
|
logger.error(`Error completing lesson: ${error}`);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: decoded?.id || 0,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'LessonProgress',
|
entityType: 'LessonProgress',
|
||||||
entityId: input.lesson_id,
|
entityId: input.lesson_id,
|
||||||
metadata: {
|
metadata: {
|
||||||
operation: 'complete_lesson',
|
operation: 'complete_lesson',
|
||||||
lesson_id: input.lesson_id,
|
lesson_id: input.lesson_id,
|
||||||
error: error instanceof Error ? error.message : String(error)
|
error: error instanceof Error ? error.message : String(error)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ export const options = {
|
||||||
thresholds: {
|
thresholds: {
|
||||||
http_req_duration: ['p(95)<2000'], // 95% of requests < 2s
|
http_req_duration: ['p(95)<2000'], // 95% of requests < 2s
|
||||||
errors: ['rate<0.1'], // Error rate < 10%
|
errors: ['rate<0.1'], // Error rate < 10%
|
||||||
login_duration: ['p(95)<2000'], // 95% of logins < 2s
|
login_duration: ['p(95)<2000'], // 95% pof logins < 2s
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue