fix: allow editing empty draft trails
This commit is contained in:
@@ -58,7 +58,15 @@ const learningPathSchema = z.object({
|
||||
coverImagePositionX: z.number().min(0).max(100).default(50),
|
||||
coverImagePositionY: z.number().min(0).max(100).default(50),
|
||||
status: z.enum(['draft', 'published']).default('draft'),
|
||||
courseIds: z.array(z.string().uuid()).min(1).max(100),
|
||||
courseIds: z.array(z.string().uuid()).max(100),
|
||||
}).superRefine((input, context) => {
|
||||
if (input.status === 'published' && input.courseIds.length === 0) {
|
||||
context.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
path: ['courseIds'],
|
||||
message: 'Adicione pelo menos um curso antes de publicar a trilha.',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
type LearningPathInput = z.infer<typeof learningPathSchema>;
|
||||
@@ -143,6 +151,17 @@ export const adminRoutes: FastifyPluginAsync = async (app) => {
|
||||
|
||||
app.get('/paths', adminAccess, async () => ({ data: await getLearningPaths() }));
|
||||
|
||||
app.get('/path-courses', adminAccess, async () => {
|
||||
const result = await pool.query<{ id: string; title: string; status: string; category: string; coverImageUrl: string | null }>(
|
||||
`select id, title, status, category,
|
||||
coalesce(cover_image_url, (select value #>> '{}' from platform_settings where key = 'media.defaultCoverImageUrl')) as "coverImageUrl"
|
||||
from courses
|
||||
where status <> 'archived'
|
||||
order by category, title`,
|
||||
);
|
||||
return { data: result.rows };
|
||||
});
|
||||
|
||||
app.get('/home-banners', adminAccess, async () => ({ data: await selectHomeBanners() }));
|
||||
|
||||
app.put('/home-banners', adminAccess, async (request) => {
|
||||
@@ -189,7 +208,7 @@ export const adminRoutes: FastifyPluginAsync = async (app) => {
|
||||
return reply.code(201).send({ data: paths.find((item) => item.id === path.rows[0].id) });
|
||||
} catch (error) {
|
||||
await client.query('rollback');
|
||||
if (error instanceof Error && /course|Publish/.test(error.message)) return reply.code(400).send({ error: error.message });
|
||||
if (error instanceof Error && /curso|publique/i.test(error.message)) return reply.code(400).send({ error: error.message });
|
||||
throw error;
|
||||
} finally {
|
||||
client.release();
|
||||
@@ -223,7 +242,7 @@ export const adminRoutes: FastifyPluginAsync = async (app) => {
|
||||
return { data: paths.find((item) => item.id === pathId) };
|
||||
} catch (error) {
|
||||
await client.query('rollback');
|
||||
if (error instanceof Error && /course|Publish/.test(error.message)) return reply.code(400).send({ error: error.message });
|
||||
if (error instanceof Error && /curso|publique/i.test(error.message)) return reply.code(400).send({ error: error.message });
|
||||
throw error;
|
||||
} finally {
|
||||
client.release();
|
||||
|
||||
Reference in New Issue
Block a user