From 620f6cb1d9c89c4386720e4625f6c4358e09a0f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20FAMIBELLE-PRONZOLA?= Date: Sat, 14 May 2022 19:51:35 +0400 Subject: [PATCH] Create validateParoles --- .../parole/content-types/parole/lifecycles.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/api/parole/content-types/parole/lifecycles.js b/src/api/parole/content-types/parole/lifecycles.js index c28913e..5b4f9c2 100644 --- a/src/api/parole/content-types/parole/lifecycles.js +++ b/src/api/parole/content-types/parole/lifecycles.js @@ -91,9 +91,25 @@ const translateTeks = async teksFR => { } } +const validateParoles = (tit, transkripsyon) => { + if (!tit || tit.trim().length === 0) { + throw new ValidationError('Champ obligatoire. Veuillez choisir un titre.'); + } + + if (!transkripsyon || transkripsyon.trim().length === 0) { + throw new ValidationError('Champ obligatoire. Veuillez renseigner la transcription.') + } + + if (transkripsyon.trim().length < 10) { + throw new ValidationError('La transcription doit contenir au moins 10 caractères.') + } +} + module.exports = { beforeCreate: async event => { let {data} = event.params + validateParoles(data.tit, data.transkripsyon) + const user = await jwennUserEpiId(data?.user?.id) const userAdmin = await jwennUserAdminEpiId(data?.createdBy) @@ -120,6 +136,8 @@ module.exports = { }, beforeUpdate: async event => { let {data} = event.params + validateParoles(data.tit, data.transkripsyon) + const {where} = event.params if(!data.publishedAt) {