Secure teks update
This commit is contained in:
@@ -21,6 +21,31 @@ const {parseMultipartData, sanitizeEntity} = require('strapi-utils')
|
||||
entity = await strapi.services.teks.create(body)
|
||||
}
|
||||
|
||||
return sanitizeEntity(entity, {model: strapi.models.teks})
|
||||
},
|
||||
|
||||
async update(ctx) {
|
||||
const {id} = ctx.params;
|
||||
|
||||
let entity
|
||||
|
||||
const teks = await strapi.query('teks').findOne({
|
||||
id: ctx.params.id,
|
||||
'user.id': ctx.state.user.id,
|
||||
published_at: null
|
||||
})
|
||||
|
||||
if (!teks) {
|
||||
return ctx.unauthorized(`Vous ne pouvez pas mettre à jour cet élément.`)
|
||||
}
|
||||
|
||||
if (ctx.is('multipart')) {
|
||||
const {data} = parseMultipartData(ctx);
|
||||
entity = await strapi.services.teks.update({id}, data)
|
||||
} else {
|
||||
entity = await strapi.services.teks.update({id}, ctx.request.body)
|
||||
}
|
||||
|
||||
return sanitizeEntity(entity, {model: strapi.models.teks})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user