fix: valider data.user/data.artistes avant déréférencement
This commit is contained in:
@@ -59,4 +59,15 @@ describe('artiste.create', () => {
|
||||
|
||||
expect(artisteDocuments.create).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('refuse sans planter quand data.user est absent', async () => {
|
||||
const {strapi} = buildStrapi({dbUser})
|
||||
const controller = createController({strapi})
|
||||
const ctx = buildCtx(buildData({user: undefined}))
|
||||
|
||||
await controller.create(ctx)
|
||||
|
||||
expect(ctx.badRequest).toHaveBeenCalled()
|
||||
expect(strapi.documents).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -12,6 +12,10 @@ module.exports = createCoreController('api::artiste.artiste', ({strapi}) => ({
|
||||
const {body} = ctx.request
|
||||
let {data} = body
|
||||
|
||||
if (!data?.user?.documentId) {
|
||||
return ctx.badRequest('Informations manquantes.')
|
||||
}
|
||||
|
||||
const user = await strapi.documents('plugin::users-permissions.user').findOne({
|
||||
documentId: body.data.user.documentId
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user