feat(simulations): persistance session — autosave + sujet_id + getById tolère rapport=null (FTD-21)
This commit is contained in:
parent
fc76fac981
commit
fcd8fe7017
3 changed files with 533 additions and 77 deletions
|
|
@ -92,4 +92,74 @@ simulations.get('/:id', authMiddleware, async (c) => {
|
|||
return c.json(result.data, 200)
|
||||
})
|
||||
|
||||
// FTD-21 — autosave du contenu d'une simulation en cours.
|
||||
simulations.patch('/:id/contenu', authMiddleware, async (c) => {
|
||||
const id = c.req.param('id')!
|
||||
|
||||
let body: { contenu?: unknown }
|
||||
try {
|
||||
body = await c.req.json()
|
||||
} catch {
|
||||
return c.json(
|
||||
{ error: true, code: 'VALIDATION_ERROR', message: 'Corps de la requête invalide.' },
|
||||
400
|
||||
)
|
||||
}
|
||||
|
||||
if (typeof body.contenu !== 'string') {
|
||||
return c.json(
|
||||
{
|
||||
error: true,
|
||||
code: 'VALIDATION_ERROR',
|
||||
message: 'Le champ `contenu` est requis et doit être une chaîne.',
|
||||
},
|
||||
400
|
||||
)
|
||||
}
|
||||
|
||||
const profile = c.get('profile')
|
||||
const result = await simulationController.autosaveContenu(id, profile.id, body.contenu)
|
||||
|
||||
if ('error' in result) {
|
||||
return c.json(result, result.status as 400 | 401 | 404 | 500)
|
||||
}
|
||||
|
||||
return c.json(result.data, 200)
|
||||
})
|
||||
|
||||
// FTD-21 — met à jour le sujet d'une simulation en cours.
|
||||
simulations.patch('/:id/sujet', authMiddleware, async (c) => {
|
||||
const id = c.req.param('id')!
|
||||
|
||||
let body: { sujet_id?: unknown }
|
||||
try {
|
||||
body = await c.req.json()
|
||||
} catch {
|
||||
return c.json(
|
||||
{ error: true, code: 'VALIDATION_ERROR', message: 'Corps de la requête invalide.' },
|
||||
400
|
||||
)
|
||||
}
|
||||
|
||||
if (!body.sujet_id || typeof body.sujet_id !== 'string') {
|
||||
return c.json(
|
||||
{
|
||||
error: true,
|
||||
code: 'VALIDATION_ERROR',
|
||||
message: 'Le champ `sujet_id` est requis et doit être une chaîne.',
|
||||
},
|
||||
400
|
||||
)
|
||||
}
|
||||
|
||||
const profile = c.get('profile')
|
||||
const result = await simulationController.updateSujet(id, profile.id, body.sujet_id)
|
||||
|
||||
if ('error' in result) {
|
||||
return c.json(result, result.status as 400 | 401 | 404 | 500)
|
||||
}
|
||||
|
||||
return c.json(result.data, 200)
|
||||
})
|
||||
|
||||
export default simulations
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue