feat: complete platform operations roadmap
All checks were successful
CI / Validate frontend and API (push) Successful in 1m58s
CI / Build and publish Docker images (push) Successful in 22s

This commit is contained in:
Cauê Faleiros
2026-09-04 10:07:07 -03:00
parent 2c137529bc
commit 9b6fea4b81
19 changed files with 589 additions and 66 deletions

View File

@@ -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) };
});