feat: improve learning and platform operations
This commit is contained in:
@@ -100,6 +100,29 @@ export const courseRoutes: FastifyPluginAsync = async (app) => {
|
||||
return { data: authenticated ? result.rows : result.rows.map(withoutProtectedMedia) };
|
||||
});
|
||||
|
||||
app.get('/me/learning', { preHandler: app.authenticate }, async (request) => {
|
||||
const result = await pool.query(
|
||||
`select base.*, coalesce(progress.progress, 0)::int as progress, progress."lastActivity"
|
||||
from (
|
||||
${courseSelect()}
|
||||
where c.status = 'published'
|
||||
) base
|
||||
left join lateral (
|
||||
select
|
||||
case when count(l.id) = 0 then 0
|
||||
else floor(100.0 * count(l.id) filter (where lp.completed_at is not null) / count(l.id))::int end as progress,
|
||||
max(lp.updated_at) as "lastActivity"
|
||||
from lessons l
|
||||
left join lesson_progress lp on lp.lesson_id = l.id and lp.user_id = $1
|
||||
where l.course_id = base.id
|
||||
) progress on true
|
||||
where progress."lastActivity" is not null
|
||||
order by progress."lastActivity" desc`,
|
||||
[request.user.id],
|
||||
);
|
||||
return { data: result.rows };
|
||||
});
|
||||
|
||||
app.get('/:courseId', async (request, reply) => {
|
||||
const authenticated = await hasSession(request);
|
||||
const { courseId } = paramsSchema.parse(request.params);
|
||||
|
||||
Reference in New Issue
Block a user