feat: complete platform operations roadmap
This commit is contained in:
@@ -18,7 +18,9 @@ export const courseSelect = (publicOnly = false, includeUnreadyMedia = false) =>
|
||||
c.title,
|
||||
c.description,
|
||||
c.category,
|
||||
c.cover_image_url as "coverImageUrl",
|
||||
coalesce(c.cover_image_url, (
|
||||
select value #>> '{}' from platform_settings where key = 'media.defaultCoverImageUrl'
|
||||
)) as "coverImageUrl",
|
||||
c.status,
|
||||
c.published_at as "publishedAt",
|
||||
jsonb_build_object(
|
||||
@@ -100,9 +102,27 @@ export const courseRoutes: FastifyPluginAsync = async (app) => {
|
||||
}
|
||||
};
|
||||
|
||||
app.get('/categories', async () => {
|
||||
const result = await pool.query<{ name: string }>(`select name from course_categories where is_active order by position, name`);
|
||||
return { data: result.rows.map((row) => row.name) };
|
||||
});
|
||||
|
||||
app.get('/', async (request) => {
|
||||
const authenticated = await hasSession(request);
|
||||
const result = await pool.query(`${courseSelect()} where c.status = 'published' order by c.published_at desc`);
|
||||
const result = await pool.query(
|
||||
`${courseSelect()}
|
||||
left join platform_settings featured_setting on featured_setting.key = 'home.featuredCourseId'
|
||||
left join platform_settings order_setting on order_setting.key = 'home.courseOrder'
|
||||
where c.status = 'published'
|
||||
order by
|
||||
case when c.id::text = coalesce(featured_setting.value #>> '{}', '') then 0 else 1 end,
|
||||
coalesce((
|
||||
select position::int
|
||||
from jsonb_array_elements_text(coalesce(order_setting.value, '[]'::jsonb)) with ordinality as ordered(id, position)
|
||||
where ordered.id = c.id::text
|
||||
), 999999),
|
||||
c.published_at desc`,
|
||||
);
|
||||
return { data: authenticated ? result.rows : result.rows.map(withoutProtectedMedia) };
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user