From ff0cb60890ef0f90e4aaaa112b05ca9a682b2c9c Mon Sep 17 00:00:00 2001 From: ETHEVE Fabien Date: Thu, 9 Feb 2023 17:07:54 +0100 Subject: [PATCH] Ajout des routes upload : upload, uploadGroupe --- groupeValidator.js | 1 + jeuxValidator.js | 1 + route/groupe.js | 31 ++++++++++++++++++++++++++++++- route/jeux.js | 37 ++++++++++++++++++++++++++++++++++++- 4 files changed, 68 insertions(+), 2 deletions(-) diff --git a/groupeValidator.js b/groupeValidator.js index 8521e3a..6047f4a 100644 --- a/groupeValidator.js +++ b/groupeValidator.js @@ -1,6 +1,7 @@ import { optional, string, z } from "zod"; const groupeValidation = z.object({ + id : z.number().optional(), name : z.string(), logo : z.string(), diff --git a/jeuxValidator.js b/jeuxValidator.js index 4ada8ba..411cc53 100644 --- a/jeuxValidator.js +++ b/jeuxValidator.js @@ -1,6 +1,7 @@ import { optional, string, z } from "zod"; const jeuxValidation = z.object({ + id : z.number().optional(), Title : z.string(), Description : z.string(), Picture: z.string(), diff --git a/route/groupe.js b/route/groupe.js index 8a93939..3a2d46d 100644 --- a/route/groupe.js +++ b/route/groupe.js @@ -6,7 +6,36 @@ import groupeValidation from "../groupeValidator.js"; const router = express.Router() const prisma = new PrismaClient(); - +router.patch('/uploadGroupe',async(req,res,next)=>{ + let modifyData; + try{ + modifyData = groupeValidation.parse(req.body) + }catch(error){ + return res.status(400).json({ errors: error.issues }) + } + const id = await prisma.groupe.findFirst({ + where:{ + id : modifyData.id + } + }) + // on va verifier si le mail de la personne est bon , sinon il peut pas modifier son mot de passe + if(!id) return next(createError(200, "Vérifiez l'existence de ce groupe ")); + + await prisma.groupe.update({ + where:{ + id : modifyData.id + }, + data:{ + + name : modifyData.name, + logo : modifyData.logo + + } + }) + .then(()=>{ + res.json({"message" : "Modification de la page"}) + }) +}) router.post('/groupe', async(req,res)=>{ let groupData; diff --git a/route/jeux.js b/route/jeux.js index edef0f0..a7e03e4 100644 --- a/route/jeux.js +++ b/route/jeux.js @@ -7,7 +7,42 @@ const router = express.Router() const prisma = new PrismaClient(); - +router.patch('/upload',async(req,res,next)=>{ + let modifyData; + try{ + modifyData = jeuxValidation.parse(req.body) + }catch(error){ + return res.status(400).json({ errors: error.issues }) + } + const id = await prisma.jeux.findFirst({ + where:{ + id : modifyData.id + } + }) + // on va verifier si le mail de la personne est bon , sinon il peut pas modifier son mot de passe + if(!id) return next(createError(200, "Vérifiez l'existence de ce jeux ")); + + await prisma.jeux.update({ + where:{ + id : modifyData.id + }, + data:{ + + Title : modifyData.Title, + Description : modifyData.Description, + Picture : modifyData.Picture, + lien : modifyData.lien, + groupe:{ + connect:{ + id : modifyData.groupe_id + } + } + } + }) + .then(()=>{ + res.json({"message" : "Modification de la page"}) + }) +}) router.post('/jeux',async (req,res,next)=>{ let jeuxData;