From 04b2a6338791de4a6fc586e192b970b82e45c56c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20FAMIBELLE-PRONZOLA?= Date: Mon, 24 Oct 2022 00:08:42 +0400 Subject: [PATCH] Fix requested user error & throw exception --- src/api/parole/content-types/parole/lifecycles.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/api/parole/content-types/parole/lifecycles.js b/src/api/parole/content-types/parole/lifecycles.js index ef195b3..704e372 100644 --- a/src/api/parole/content-types/parole/lifecycles.js +++ b/src/api/parole/content-types/parole/lifecycles.js @@ -47,7 +47,14 @@ const jwennUserEpiId = async userId => { return null } - const user = await strapi.db.query('plugin::users-permissions.user').findOne({id: userId}) + const user = await strapi.db.query('plugin::users-permissions.user').findOne({ + where: {id: userId} + }) + + if (!user) { + throw new ValidationError('Utilisateur introuvable.') + } + return user } @@ -179,7 +186,7 @@ module.exports = { }, afterCreate: async event => { const {data} = event.params - const user = await jwennUserEpiId(data.user) + const user = await jwennUserEpiId(data?.user?.id) const userAdmin = await jwennUserAdminEpiId(data?.createdBy) const superAdmin = await jwennSuperAdminEpiId(data?.createdBy) const traductionsId = data.traductions.id