mirror of
https://github.com/Floriansylvain/PopCorn.git
synced 2026-08-19 11:43:23 +02:00
Ajout des routes upload : upload, uploadGroupe
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { optional, string, z } from "zod";
|
import { optional, string, z } from "zod";
|
||||||
|
|
||||||
const groupeValidation = z.object({
|
const groupeValidation = z.object({
|
||||||
|
id : z.number().optional(),
|
||||||
name : z.string(),
|
name : z.string(),
|
||||||
logo : z.string(),
|
logo : z.string(),
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { optional, string, z } from "zod";
|
import { optional, string, z } from "zod";
|
||||||
|
|
||||||
const jeuxValidation = z.object({
|
const jeuxValidation = z.object({
|
||||||
|
id : z.number().optional(),
|
||||||
Title : z.string(),
|
Title : z.string(),
|
||||||
Description : z.string(),
|
Description : z.string(),
|
||||||
Picture: z.string(),
|
Picture: z.string(),
|
||||||
|
|||||||
@@ -6,7 +6,36 @@ import groupeValidation from "../groupeValidator.js";
|
|||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
const prisma = new PrismaClient();
|
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)=>{
|
router.post('/groupe', async(req,res)=>{
|
||||||
let groupData;
|
let groupData;
|
||||||
|
|||||||
@@ -7,7 +7,42 @@ const router = express.Router()
|
|||||||
const prisma = new PrismaClient();
|
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)=>{
|
router.post('/jeux',async (req,res,next)=>{
|
||||||
let jeuxData;
|
let jeuxData;
|
||||||
|
|||||||
Reference in New Issue
Block a user