11import { withSentry } from "@sentry/nextjs" ;
22import type { NextApiHandler , NextApiRequest } from "next" ;
33import { getSession } from "next-auth/react" ;
4- import prisma from "src/lib/prismaClient" ;
54import superjson from "superjson" ;
65
6+ import { PrismaClient , Prisma } from '@prisma/client'
7+ const client = new PrismaClient ( )
8+
79const handler : NextApiHandler = async ( req , res ) => {
810 const session = await getSession ( { req } ) ;
911 if (
@@ -40,14 +42,14 @@ const get: NextApiHandler = async (req, res) => {
4042 ? await getUpcomingCommissionsNotEmpty ( req )
4143 : await getUpcomingCommissions ( )
4244 : await getUpcomingCommissionsByDepartement ( departements as string ) ;
43- await prisma ?. $disconnect ( )
45+ await client ?. $disconnect ( )
4446 res . status ( 200 ) . json ( superjson . stringify ( commissions ) ) ;
4547} ;
4648
4749const post : NextApiHandler = async ( req , res ) => {
4850 const data = JSON . parse ( req . body as string ) ;
4951 try {
50- await prisma ?. commission . create ( { data } ) ;
52+ await client ?. commission . create ( { data } ) ;
5153 } catch ( e : unknown ) {
5254 console . log ( e ) ;
5355 }
@@ -57,7 +59,7 @@ const post: NextApiHandler = async (req, res) => {
5759const remove : NextApiHandler = async ( req , res ) => {
5860 const commissionId = Number ( req . body as string ) ;
5961 try {
60- await prisma ?. commission . delete ( {
62+ await client ?. commission . delete ( {
6163 where : { id : commissionId } ,
6264 } ) ;
6365 res . status ( 200 ) . json ( { message : "Commission supprimée" } ) ;
@@ -69,7 +71,7 @@ const remove: NextApiHandler = async (req, res) => {
6971
7072const getUpcomingCommissions = async ( ) => {
7173 console . log ( 'upcoming' )
72- return prisma ?. commission . findMany ( {
74+ return client ?. commission . findMany ( {
7375 include : {
7476 dossiers : {
7577 include : {
@@ -88,7 +90,7 @@ const getUpcomingCommissions = async () => {
8890const getUpcomingCommissionsNotEmpty = async ( req : NextApiRequest ) => {
8991 const session = await getSession ( { req } ) ;
9092 console . log ( 'upcoming not empty !!!' )
91- return await prisma ?. commission . findMany ( {
93+ return await client ?. commission . findMany ( {
9294 include : {
9395 dossiers : {
9496 where : session ?. dbUser . role !== "MEDECIN" ?
@@ -152,7 +154,7 @@ const getUpcomingCommissionsNotEmpty = async (req: NextApiRequest) => {
152154const getUpcomingCommissionsByDepartement = async ( departements : string ) => {
153155 console . log ( 'upcoming by departement' )
154156 console . log ( "departements : " , departements . split ( "," ) ) ;
155- return prisma . commission . findMany ( {
157+ return client . commission . findMany ( {
156158 include : {
157159 dossiers : {
158160 include : {
@@ -177,7 +179,7 @@ const getUpcomingCommissionsByDepartement = async (departements: string) => {
177179
178180const getPastCommissions = async ( ) => {
179181 console . log ( 'past commissions' )
180- return prisma . commission . findMany ( {
182+ return client . commission . findMany ( {
181183 include : {
182184 dossiers : {
183185 include : {
0 commit comments