diff --git a/formulaire/pages/api/comments/index.tsx b/formulaire/pages/api/comments/index.tsx index 1359e7b1e..8de9aa1f6 100644 --- a/formulaire/pages/api/comments/index.tsx +++ b/formulaire/pages/api/comments/index.tsx @@ -32,10 +32,8 @@ const get: NextApiHandler = async (req, res) => { dossierId: parseInt(dossierId), }, }); - await prisma?.$disconnect(); res.status(200).json(comments); } catch (e: unknown) { - await prisma?.$disconnect(); console.log(e); } }; @@ -69,7 +67,6 @@ const updateCommentairesNotifications: NextApiHandler = async (req, res) => { }, }, }); - await prisma?.$disconnect(); res.status(200).json(updateComments); }; @@ -81,10 +78,8 @@ const post: NextApiHandler = async (req, res) => { console.log("comment to create : ", data); try { const comment = await prisma.comments.create({ data }); - await prisma?.$disconnect(); res.status(200).json(comment); } catch (e: unknown) { - await prisma?.$disconnect(); console.log(e); } }; diff --git a/formulaire/pages/api/demandeur/index.tsx b/formulaire/pages/api/demandeur/index.tsx index 11367fba0..da155e051 100644 --- a/formulaire/pages/api/demandeur/index.tsx +++ b/formulaire/pages/api/demandeur/index.tsx @@ -4,7 +4,7 @@ import type { NextApiHandler } from "next"; import { DemandeurModel } from "prisma/zod"; import prisma from "../../../src/lib/prismaClient"; import { getServerSession } from "next-auth"; -import { authOptions } from '../auth/[...nextauth]' +import { authOptions } from "../auth/[...nextauth]"; const handler: NextApiHandler = async (req, res) => { const session = await getServerSession(req, res, authOptions); @@ -49,7 +49,6 @@ const update: NextApiHandler = async (req, res) => { data: { ...demandeurData.parse(parsed) }, where: { id: parsed.id }, }); - await prisma?.$disconnect() res.status(200).json(dempandeurUpdated); }; diff --git a/formulaire/pages/api/dossier/index.tsx b/formulaire/pages/api/dossier/index.tsx index f3e22549d..4156473fe 100644 --- a/formulaire/pages/api/dossier/index.tsx +++ b/formulaire/pages/api/dossier/index.tsx @@ -6,7 +6,7 @@ import { STATUS_EN_COURS, STATUS_TERMINES, CATEGORIES } from "src/lib/helpers"; import { statusGroup } from "src/lib/types"; import prisma from "../../../src/lib/prismaClient"; import { getServerSession } from "next-auth"; -import { authOptions } from '../auth/[...nextauth]' +import { authOptions } from "../auth/[...nextauth]"; const handler: NextApiHandler = async (req, res) => { const session = await getServerSession(req, res, authOptions); @@ -167,7 +167,6 @@ const get: NextApiHandler = async (req, res) => { ], }, }); - await prisma?.$disconnect() res.status(200).json({ dossiers: dossiers, countCurrent: countCurrent, @@ -175,7 +174,6 @@ const get: NextApiHandler = async (req, res) => { countTermines: countTermines, }); } catch (e: unknown) { - await prisma?.$disconnect() console.log(e); } }; @@ -220,7 +218,6 @@ const update: NextApiHandler = async (req, res) => { data: parsed, where: { id: parsed.id }, }); - await prisma?.$disconnect() res.status(200).json(produitupdated); }; diff --git a/formulaire/pages/api/enfants/index.tsx b/formulaire/pages/api/enfants/index.tsx index 3bc5a7abf..da50dec37 100644 --- a/formulaire/pages/api/enfants/index.tsx +++ b/formulaire/pages/api/enfants/index.tsx @@ -54,10 +54,8 @@ const get: NextApiHandler = async (req, res) => { ], }, }); - await prisma?.$disconnect(); res.status(200).json(enfants); } catch (e: unknown) { - await prisma?.$disconnect(); console.log(e); } }; @@ -68,10 +66,8 @@ const post: NextApiHandler = async (req, res) => { data.userId = session?.dbUser.id; try { const enfant = await prisma.enfant.create({ data }); - await prisma?.$disconnect(); res.status(200).json(enfant); } catch (e: unknown) { - await prisma?.$disconnect(); console.log(e); } }; @@ -121,7 +117,6 @@ const update: NextApiHandler = async (req, res) => { data: parsed as Enfant, where: { id: parsed.id }, }); - await prisma?.$disconnect(); res.status(200).json(enfantUpdated); }; diff --git a/formulaire/pages/api/piece/dossier/index.tsx b/formulaire/pages/api/piece/dossier/index.tsx index 42684f433..2000acac5 100644 --- a/formulaire/pages/api/piece/dossier/index.tsx +++ b/formulaire/pages/api/piece/dossier/index.tsx @@ -5,7 +5,7 @@ import prisma from "../../../../src/lib/prismaClient"; import fs from "fs"; import { generateToken } from "src/lib/utils"; import { getServerSession } from "next-auth"; -import { authOptions } from '../../auth/[...nextauth]' +import { authOptions } from "../../auth/[...nextauth]"; const handler: NextApiHandler = async (req, res) => { const session = await getServerSession(req, res, authOptions); @@ -32,10 +32,8 @@ const post: NextApiHandler = async (req, res) => { piece.link, piece.statut ); - await prisma?.$disconnect() res.status(200).json({ pieceDossier: piece, tokenizedLink: tokenizedLink }); } catch (e: unknown) { - await prisma?.$disconnect() console.log(e); } }; diff --git a/formulaire/pages/api/piece/enfant/index.tsx b/formulaire/pages/api/piece/enfant/index.tsx index f13dd99e8..8fa8d7c23 100644 --- a/formulaire/pages/api/piece/enfant/index.tsx +++ b/formulaire/pages/api/piece/enfant/index.tsx @@ -4,35 +4,41 @@ import type { NextApiHandler } from "next"; import { generateToken } from "src/lib/utils"; import prisma from "../../../../src/lib/prismaClient"; import { getServerSession } from "next-auth"; -import { authOptions } from '../../auth/[...nextauth]' +import { authOptions } from "../../auth/[...nextauth]"; const handler: NextApiHandler = async (req, res) => { const session = await getServerSession(req, res, authOptions); - if (!session) { - res.status(401).end(); - return; - } - if (req.method == "POST") { - await post(req, res); - } else { - res.status(405).end(); - return; - } + if (!session) { + res.status(401).end(); + return; + } + if (req.method == "POST") { + await post(req, res); + } else { + res.status(405).end(); + return; + } }; const post: NextApiHandler = async (req, res) => { - const data = JSON.parse(req.body) as PieceDossierEnfant & {dossierId: number} - const dossierId = data.dossierId - delete data.dossierId - try { - const piece = await prisma.pieceDossierEnfant.create({ data }); - const tokenizedLink = generateToken(piece.id, dossierId, piece.type, piece.link, piece.statut) - await prisma?.$disconnect() - res.status(200).json({pieceDossier: piece, tokenizedLink: tokenizedLink}); - } catch (e: unknown) { - await prisma?.$disconnect() - console.log(e); - } + const data = JSON.parse(req.body) as PieceDossierEnfant & { + dossierId: number; + }; + const dossierId = data.dossierId; + delete data.dossierId; + try { + const piece = await prisma.pieceDossierEnfant.create({ data }); + const tokenizedLink = generateToken( + piece.id, + dossierId, + piece.type, + piece.link, + piece.statut + ); + res.status(200).json({ pieceDossier: piece, tokenizedLink: tokenizedLink }); + } catch (e: unknown) { + console.log(e); + } }; -export default withSentry(handler); \ No newline at end of file +export default withSentry(handler); diff --git a/formulaire/pages/api/societe/index.tsx b/formulaire/pages/api/societe/index.tsx index 0aa661fd6..83667b798 100644 --- a/formulaire/pages/api/societe/index.tsx +++ b/formulaire/pages/api/societe/index.tsx @@ -3,74 +3,70 @@ import type { NextApiHandler } from "next"; import { SocieteProductionModel } from "prisma/zod"; import prisma from "../../../src/lib/prismaClient"; import { getServerSession } from "next-auth"; -import { authOptions } from '../auth/[...nextauth]' +import { authOptions } from "../auth/[...nextauth]"; const handler: NextApiHandler = async (req, res) => { const session = await getServerSession(req, res, authOptions); - if (!session) { - res.status(401).end(); - return; - } - if (req.method == "POST") { - await post(req, res); - } else if (req.method == "GET") { - await get(req, res); - } else if (req.method == "PUT") { - await update(req, res); - } else { - res.status(405).end(); - return; - } + if (!session) { + res.status(401).end(); + return; + } + if (req.method == "POST") { + await post(req, res); + } else if (req.method == "GET") { + await get(req, res); + } else if (req.method == "PUT") { + await update(req, res); + } else { + res.status(405).end(); + return; + } }; const get: NextApiHandler = async (req, res) => { - const siret = req.query.siret as string; - try { - const societe = await prisma.societeProduction.findFirst({ - where: { - siret: siret - } - }) - await prisma?.$disconnect() - res.status(200).json(societe) - } catch (e: unknown) { - await prisma?.$disconnect() - console.log(e); - } + const siret = req.query.siret as string; + try { + const societe = await prisma.societeProduction.findFirst({ + where: { + siret: siret, + }, + }); + res.status(200).json(societe); + } catch (e: unknown) { + console.log(e); + } }; const update: NextApiHandler = async (req, res) => { - console.log('in societe update') - const data = JSON.parse(req.body) - const societeData = SocieteProductionModel.omit({id: true}) - try { - const societe = await prisma.societeProduction.update({ - data: {...societeData.parse(data)}, - where: { - id: data.id - } - }); - await prisma?.$disconnect() - res.status(200).json(societe); - } catch (e: unknown) { - await prisma?.$disconnect() - console.log(e); - } + console.log("in societe update"); + const data = JSON.parse(req.body); + const societeData = SocieteProductionModel.omit({ id: true }); + try { + const societe = await prisma.societeProduction.update({ + data: { ...societeData.parse(data) }, + where: { + id: data.id, + }, + }); + res.status(200).json(societe); + } catch (e: unknown) { + console.log(e); + } }; const post: NextApiHandler = async (req, res) => { - console.log('in societe create') - const data = JSON.parse(req.body) - const societeData = SocieteProductionModel.omit({id: true}) - try { - const societe = await prisma.societeProduction.create({ data: {...societeData.parse(data)} }); - console.log('societe created : ', societe) - await prisma?.$disconnect() - res.status(200).json(societe); - } catch (e: unknown) { - await prisma?.$disconnect() - console.log(e); - } + console.log("in societe create"); + const data = JSON.parse(req.body); + const societeData = SocieteProductionModel.omit({ id: true }); + try { + const societe = await prisma.societeProduction.create({ + data: { ...societeData.parse(data) }, + }); + console.log("societe created : ", societe); + res.status(200).json(societe); + } catch (e: unknown) { + console.log(e); + } }; -export default withSentry(handler); \ No newline at end of file +export default withSentry(handler); diff --git a/formulaire/pages/api/sync/inc/commentaires/index.tsx b/formulaire/pages/api/sync/inc/commentaires/index.tsx index 145eb6fe8..665784b14 100644 --- a/formulaire/pages/api/sync/inc/commentaires/index.tsx +++ b/formulaire/pages/api/sync/inc/commentaires/index.tsx @@ -45,7 +45,6 @@ const post: NextApiHandler = async (req, res) => { const comment = await prisma.comments.create({ data: data.comment, }); - await prisma?.$disconnect(); //console.log("comments created : ", comment); res.status(200).json(comment); } @@ -137,7 +136,6 @@ const get: NextApiHandler = async (req, res) => { }; } ); - await prisma?.$disconnect(); res.status(200).json(notificationsByDossier); } diff --git a/formulaire/pages/api/sync/inc/commentaires/notifications/index.tsx b/formulaire/pages/api/sync/inc/commentaires/notifications/index.tsx index 1769a8f0f..3e846fd07 100644 --- a/formulaire/pages/api/sync/inc/commentaires/notifications/index.tsx +++ b/formulaire/pages/api/sync/inc/commentaires/notifications/index.tsx @@ -2,7 +2,7 @@ import { Comments } from "@prisma/client"; import { withSentry } from "@sentry/nextjs"; import type { NextApiHandler } from "next"; import { CommentaireNotifications } from "src/lib/types"; -// import prisma from "../../../../../src/lib/prismaClient"; +import prisma from "../../../../../../src/lib/prismaClient"; const handler: NextApiHandler = async (req, res) => { if (req.method == "PUT") { @@ -48,7 +48,6 @@ const update: NextApiHandler = async (req, res) => { }, }, }); - await prisma?.$disconnect(); res.status(200).json(updateComments); } }; diff --git a/formulaire/pages/api/sync/inc/docs/index.tsx b/formulaire/pages/api/sync/inc/docs/index.tsx index 6c25ebafa..4e6c226e8 100644 --- a/formulaire/pages/api/sync/inc/docs/index.tsx +++ b/formulaire/pages/api/sync/inc/docs/index.tsx @@ -57,7 +57,6 @@ const get: NextApiHandler = async (req, res) => { }, }, }); - await prisma?.$disconnect(); res.status(200).json({ dossier: { id: dossier?.id, diff --git a/formulaire/pages/api/sync/inc/dossiers/index.tsx b/formulaire/pages/api/sync/inc/dossiers/index.tsx index 9ee91c81d..525289f84 100644 --- a/formulaire/pages/api/sync/inc/dossiers/index.tsx +++ b/formulaire/pages/api/sync/inc/dossiers/index.tsx @@ -27,11 +27,9 @@ const update: NextApiHandler = async (req, res) => { id: parseInt(data.dossier.externalId), }, }); - await prisma?.$disconnect() res.status(200).json({ message: "Dossier created successfully" }); } catch (e) { console.log("error : ", e); - await prisma?.$disconnect() res.status(500).json({ error: e }); } }; diff --git a/formulaire/pages/api/sync/inc/enfants/index.tsx b/formulaire/pages/api/sync/inc/enfants/index.tsx index 2d7d81f31..f1182ed7d 100644 --- a/formulaire/pages/api/sync/inc/enfants/index.tsx +++ b/formulaire/pages/api/sync/inc/enfants/index.tsx @@ -27,10 +27,8 @@ const update: NextApiHandler = async (req, res) => { }, }); // console.log('update : ', update) - await prisma?.$disconnect(); res.status(200).json(update); } catch (e) { - await prisma?.$disconnect(); res.status(500).json({ message: "Something went wrong" }); console.log(e); } diff --git a/formulaire/pages/api/sync/inc/pieces/index.tsx b/formulaire/pages/api/sync/inc/pieces/index.tsx index 89eb5f0b4..8792c7518 100644 --- a/formulaire/pages/api/sync/inc/pieces/index.tsx +++ b/formulaire/pages/api/sync/inc/pieces/index.tsx @@ -45,7 +45,6 @@ const update: NextApiHandler = async (req, res) => { }); // console.log("piece trouvee : ", piece); } - await prisma?.$disconnect(); res.status(200).json({ message: "OK" }); }; diff --git a/formulaire/pages/api/sync/inc/upload/index.tsx b/formulaire/pages/api/sync/inc/upload/index.tsx index 51c18a342..ea53f9fc4 100644 --- a/formulaire/pages/api/sync/inc/upload/index.tsx +++ b/formulaire/pages/api/sync/inc/upload/index.tsx @@ -12,12 +12,12 @@ export const config = { }; const handler: NextApiHandler = async (req, res) => { - if (req.method == "POST") { - await sendDoc(req, res); - } else { - res.status(405).end(); - return; - } + if (req.method == "POST") { + await sendDoc(req, res); + } else { + res.status(405).end(); + return; + } }; function getId(req: NextApiRequest): number { @@ -25,37 +25,30 @@ function getId(req: NextApiRequest): number { } const sendDoc: NextApiHandler = async (req, res) => { - - console.log('------ INC FROM SDP ------') - - + console.log("------ INC FROM SDP ------"); const dossierId = getId(req); try { - await fsp.readdir(`/mnt/docs-form/${dossierId}`); + await fsp.readdir(`/mnt/docs-form/${dossierId}`); } catch (error) { - await fsp.mkdir(`/mnt/docs-form/${dossierId}`); + await fsp.mkdir(`/mnt/docs-form/${dossierId}`); } const upload = await uploadFile(req, true); const data = { - nom: upload.files.justificatif.originalFilename, - enfantId: parseInt(req.query.enfantId as string), - type: req.query.typeJustif as JustificatifEnfant, - externalId: "", - link: upload.files.justificatif.filepath + ".encrypted", - statut: null - } - - const pieceEnfant = await prisma.pieceDossierEnfant.create({data}) + nom: upload.files.justificatif.originalFilename, + enfantId: parseInt(req.query.enfantId as string), + type: req.query.typeJustif as JustificatifEnfant, + externalId: "", + link: upload.files.justificatif.filepath + ".encrypted", + statut: null, + }; + + const pieceEnfant = await prisma.pieceDossierEnfant.create({ data }); //@ts-ignore - await prisma?.$disconnect() res - .status(200) - .json({ filePath: upload.files.justificatif.filepath + ".encrypted" }); - - - + .status(200) + .json({ filePath: upload.files.justificatif.filepath + ".encrypted" }); }; -export default withSentry(handler); \ No newline at end of file +export default withSentry(handler); diff --git a/formulaire/pages/api/users/index.tsx b/formulaire/pages/api/users/index.tsx index 5f9e62cd5..4e15de380 100644 --- a/formulaire/pages/api/users/index.tsx +++ b/formulaire/pages/api/users/index.tsx @@ -38,10 +38,8 @@ const getUserById: NextApiHandler = async (req, res) => { }, }, }); - await prisma?.$disconnect(); res.status(200).json(users); } catch (e: unknown) { - await prisma?.$disconnect(); console.log(e); } }; diff --git a/formulaire/src/lib/prismaClient.ts b/formulaire/src/lib/prismaClient.ts index 88f459d1e..25cd0eea9 100644 --- a/formulaire/src/lib/prismaClient.ts +++ b/formulaire/src/lib/prismaClient.ts @@ -2,17 +2,10 @@ import { PrismaClient } from "@prisma/client"; -declare global { - // eslint-disable-next-line no-var - var prisma: PrismaClient | null; - // function getPrismaClient(): PrismaClient; -} - const getClient = () => { return new PrismaClient(); }; const client = getClient(); -global.prisma = client; export default client;