parent
f59662740f
commit
0b9bbe44d6
@ -1,7 +1,2 @@
|
||||
{
|
||||
"workbench.colorCustomizations": {
|
||||
"activityBar.background": "#521342",
|
||||
"titleBar.activeBackground": "#731B5D",
|
||||
"titleBar.activeForeground": "#FDF8FC"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
import prisma from '../../../lib/prisma';
|
||||
import chance from 'chance'
|
||||
import cryptoRandomString from 'crypto-random-string';
|
||||
|
||||
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { getSession } from 'next-auth/react';
|
||||
import { Cadeaux } from '../../../enum/cadeaux.enum';
|
||||
import { Role } from '../../../enum/role.enum';
|
||||
|
||||
|
||||
|
||||
//API gain qui va generer un code cadeau qui sera sur la facture du client
|
||||
//On part du principe qu'une 'API caisse'(qu'on ne gere pas) déclenche l'appel à l'API gain
|
||||
|
||||
export default async function updateOrCreate(req: NextApiRequest, res: NextApiResponse) {
|
||||
const session = await getSession({ req })
|
||||
const { address, name, phoneNumber, surname, zipCode } = req.body;
|
||||
|
||||
// est-ce la méthode est un POST ou PUT?
|
||||
if (req.method !== ("POST" || "PUT")) {
|
||||
throw new Error(
|
||||
`The HTTP ${req.method} method is not supported at this route.`
|
||||
);
|
||||
}
|
||||
|
||||
// est-ce que utilisateur est connecté ?
|
||||
if (!session) {
|
||||
res.status(401).json({ err: "Vous devez être connecté" });
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//récupération des informations de l'utilisateur connecté
|
||||
const user = await prisma.user.findFirst({
|
||||
where: { email: session.user.email },
|
||||
})
|
||||
|
||||
//mise a jour ou création des données pour l'utilisateur
|
||||
const upsertUser = await prisma.user.upsert({
|
||||
where: {
|
||||
email: user.email,
|
||||
},
|
||||
update: {
|
||||
name,
|
||||
surname,
|
||||
address,
|
||||
phoneNumber,
|
||||
zipCode
|
||||
},
|
||||
create: {
|
||||
name,
|
||||
surname,
|
||||
address,
|
||||
phoneNumber,
|
||||
zipCode
|
||||
},
|
||||
})
|
||||
res.status(200).send({ message: 'Vos informations ont été mise à jours !', res: upsertUser });
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- The `phoneNumber` column on the `users` table would be dropped and recreated. This will lead to data loss if there is data in the column.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" DROP COLUMN "phoneNumber",
|
||||
ADD COLUMN "phoneNumber" INTEGER;
|
||||
@ -0,0 +1,9 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- The `zipCode` column on the `users` table would be dropped and recreated. This will lead to data loss if there is data in the column.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" DROP COLUMN "zipCode",
|
||||
ADD COLUMN "zipCode" INTEGER;
|
||||
Loading…
Reference in new issue