You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
940 B
50 lines
940 B
import prisma from '../../../lib/prisma';
|
|
import { NextApiRequest, NextApiResponse } from 'next';
|
|
import { getSession } from 'next-auth/react';
|
|
|
|
export default async function updateOrCreate(req: NextApiRequest, res: NextApiResponse) {
|
|
const session = await getSession({ req })
|
|
const { targetUserMail } = req.body;
|
|
|
|
// est-ce la méthode est un POST ou PUT?
|
|
if (!(['POST'].indexOf(req.method) > -1)) {
|
|
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: targetUserMail },
|
|
})
|
|
|
|
|
|
res.status(200).send({ message: 'user :', res: user });
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|