diff --git a/formulaire/pages/api/comments/index.tsx b/formulaire/pages/api/comments/index.tsx index 880ffb2dd..1359e7b1e 100644 --- a/formulaire/pages/api/comments/index.tsx +++ b/formulaire/pages/api/comments/index.tsx @@ -4,7 +4,7 @@ import type { NextApiHandler } from "next"; import { getSession } from "next-auth/react"; 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); @@ -32,10 +32,10 @@ const get: NextApiHandler = async (req, res) => { dossierId: parseInt(dossierId), }, }); - await prisma?.$disconnect() + await prisma?.$disconnect(); res.status(200).json(comments); } catch (e: unknown) { - await prisma?.$disconnect() + await prisma?.$disconnect(); console.log(e); } }; @@ -52,13 +52,13 @@ const updateCommentairesNotifications: NextApiHandler = async (req, res) => { } } - console.log("data received : ", data.commentIds); + //console.log("data received : ", data.commentIds); const commentIds = data.commentIds.map((id: string) => parseInt(id) ) as number[]; - console.log("commentIds : ", commentIds); + //console.log("commentIds : ", commentIds); const updateComments = await prisma?.comments.updateMany({ data: { seen: true, @@ -69,7 +69,7 @@ const updateCommentairesNotifications: NextApiHandler = async (req, res) => { }, }, }); - await prisma?.$disconnect() + await prisma?.$disconnect(); res.status(200).json(updateComments); }; @@ -81,10 +81,10 @@ const post: NextApiHandler = async (req, res) => { console.log("comment to create : ", data); try { const comment = await prisma.comments.create({ data }); - await prisma?.$disconnect() + await prisma?.$disconnect(); res.status(200).json(comment); } catch (e: unknown) { - await prisma?.$disconnect() + await prisma?.$disconnect(); console.log(e); } }; diff --git a/formulaire/pages/api/enfants/index.tsx b/formulaire/pages/api/enfants/index.tsx index de4d92128..3bc5a7abf 100644 --- a/formulaire/pages/api/enfants/index.tsx +++ b/formulaire/pages/api/enfants/index.tsx @@ -4,7 +4,7 @@ import type { NextApiHandler } from "next"; import { EnfantData } from "src/fetching/dossiers"; 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); @@ -54,10 +54,10 @@ const get: NextApiHandler = async (req, res) => { ], }, }); - await prisma?.$disconnect() + await prisma?.$disconnect(); res.status(200).json(enfants); } catch (e: unknown) { - await prisma?.$disconnect() + await prisma?.$disconnect(); console.log(e); } }; @@ -68,10 +68,10 @@ const post: NextApiHandler = async (req, res) => { data.userId = session?.dbUser.id; try { const enfant = await prisma.enfant.create({ data }); - await prisma?.$disconnect() + await prisma?.$disconnect(); res.status(200).json(enfant); } catch (e: unknown) { - await prisma?.$disconnect() + await prisma?.$disconnect(); console.log(e); } }; @@ -88,7 +88,7 @@ const update: NextApiHandler = async (req, res) => { return; } - console.log("ENFANT UPDATED: ", parsed); + console.log("ENFANT UPDATED: ", parsed.id); parsed.nombreJours = parseInt(parsed.nombreJours?.toString() || "0"); parsed.montantCachet = parseFloat(parsed.montantCachet?.toString() || "0"); @@ -101,10 +101,15 @@ const update: NextApiHandler = async (req, res) => { if (parsed.remuneration) { parsed.remuneration.forEach(async (rem) => { - await prisma.remuneration.update({ - data: rem, - where: { id: rem.id }, - }); + try { + await prisma.remuneration.update({ + data: rem, + where: { id: rem.id }, + }); + } catch (e) { + console.log("error, cannot update remuneration", rem.id); + throw e; + } }); } @@ -116,7 +121,7 @@ const update: NextApiHandler = async (req, res) => { data: parsed as Enfant, where: { id: parsed.id }, }); - await prisma?.$disconnect() + await prisma?.$disconnect(); res.status(200).json(enfantUpdated); }; diff --git a/formulaire/pages/api/sync/inc/commentaires/index.tsx b/formulaire/pages/api/sync/inc/commentaires/index.tsx index ed1a471ae..145eb6fe8 100644 --- a/formulaire/pages/api/sync/inc/commentaires/index.tsx +++ b/formulaire/pages/api/sync/inc/commentaires/index.tsx @@ -21,7 +21,7 @@ const handler: NextApiHandler = async (req, res) => { const update: NextApiHandler = async (req, res) => { const data = JSON.parse(req.body) as { id: string; api_key: string }; - console.log("data received : ", data); + //console.log("data received : ", data); if (data.api_key !== process.env.API_KEY_SDP) { res.status(401).json({ error: `Unauthorized` }); } else { @@ -30,7 +30,7 @@ const update: NextApiHandler = async (req, res) => { dossierId: parseInt(data.id as string), }, }); - console.log("comments found : ", comments); + // console.log("comments found : ", comments); res.status(200).json(comments); } }; @@ -38,15 +38,15 @@ const update: NextApiHandler = async (req, res) => { const post: NextApiHandler = async (req, res) => { const data = JSON.parse(req.body) as { comment: Comments; api_key: string }; - console.log("data received : ", data); + //console.log("data received : ", data); if (data.api_key !== process.env.API_KEY_SDP) { res.status(401).json({ error: `Unauthorized` }); } else { const comment = await prisma.comments.create({ data: data.comment, }); - await prisma?.$disconnect() - console.log("comments created : ", comment); + await prisma?.$disconnect(); + //console.log("comments created : ", comment); res.status(200).json(comment); } }; @@ -55,7 +55,7 @@ const get: NextApiHandler = async (req, res) => { const data = req.query; let ids = data.externalId as string[]; const externalIds = ids.map((id: string) => parseInt(id)) as number[]; - console.log("data externalIds received : ", data); + //console.log("data externalIds received : ", data); if (data.token !== process.env.API_KEY_SDP) { res.status(401).json({ error: `Unauthorized` }); @@ -137,7 +137,7 @@ const get: NextApiHandler = async (req, res) => { }; } ); - await prisma?.$disconnect() + 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 6fe187f07..1769a8f0f 100644 --- a/formulaire/pages/api/sync/inc/commentaires/notifications/index.tsx +++ b/formulaire/pages/api/sync/inc/commentaires/notifications/index.tsx @@ -27,13 +27,13 @@ const update: NextApiHandler = async (req, res) => { } } - console.log("data received : ", data.commentIds); + //console.log("data received : ", data.commentIds); const commentIds = data.commentIds.map((id: string) => parseInt(id) ) as number[]; - console.log("commentIds : ", commentIds); + // console.log("commentIds : ", commentIds); if (data.token !== process.env.API_KEY_SDP) { res.status(401).json({ error: `Unauthorized` }); @@ -48,7 +48,7 @@ const update: NextApiHandler = async (req, res) => { }, }, }); - await prisma?.$disconnect() + await prisma?.$disconnect(); res.status(200).json(updateComments); } }; diff --git a/formulaire/pages/api/sync/inc/enfants/index.tsx b/formulaire/pages/api/sync/inc/enfants/index.tsx index f8c7ae769..2d7d81f31 100644 --- a/formulaire/pages/api/sync/inc/enfants/index.tsx +++ b/formulaire/pages/api/sync/inc/enfants/index.tsx @@ -13,29 +13,27 @@ const handler: NextApiHandler = async (req, res) => { }; const update: NextApiHandler = async (req, res) => { + const data = JSON.parse(req.body) as Enfant & { externalId: string }; - const data = JSON.parse(req.body) as Enfant & {externalId: string}; - - console.log('data received : ', data) + //console.log("data received : ", data); try { const update = await prisma.enfant.update({ - data: { - dateConsultation: data.dateConsultation - }, - where: { - id: parseInt(data.externalId) - } - }) - console.log('update : ', update) - await prisma?.$disconnect() + data: { + dateConsultation: data.dateConsultation, + }, + where: { + id: parseInt(data.externalId), + }, + }); + // 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) + await prisma?.$disconnect(); + res.status(500).json({ message: "Something went wrong" }); + console.log(e); } - }; export default withSentry(handler); diff --git a/formulaire/pages/api/sync/inc/pieces/index.tsx b/formulaire/pages/api/sync/inc/pieces/index.tsx index cdc709e2d..89eb5f0b4 100644 --- a/formulaire/pages/api/sync/inc/pieces/index.tsx +++ b/formulaire/pages/api/sync/inc/pieces/index.tsx @@ -20,7 +20,7 @@ const update: NextApiHandler = async (req, res) => { api_key: string; }; - console.log("data received : ", data); + //console.log("data received : ", data); if (data.api_key !== process.env.API_KEY_SDP) { res.status(401).json({ error: `Unauthorized` }); @@ -43,9 +43,9 @@ const update: NextApiHandler = async (req, res) => { id: parseInt(data.id), }, }); - console.log("piece trouvee : ", piece); + // console.log("piece trouvee : ", piece); } - await prisma?.$disconnect() + await prisma?.$disconnect(); res.status(200).json({ message: "OK" }); }; diff --git a/src/components/index.tsx b/src/components/index.tsx index b1ac5d4d2..d656a2d59 100644 --- a/src/components/index.tsx +++ b/src/components/index.tsx @@ -3,30 +3,29 @@ import type { NextApiHandler } from "next"; import prisma from "../../../../../src/lib/prismaClient"; const handler: NextApiHandler = async (req, res) => { - if (req.method == "PUT") { - await update(req, res); - } else { - res.status(405).end(); - return; - } + if (req.method == "PUT") { + await update(req, res); + } else { + res.status(405).end(); + return; + } }; const update: NextApiHandler = async (req, res) => { - const data = JSON.parse(req.body) as {id: string, api_key: string} - - console.log('data received : ', data) - if(data.api_key !== process.env.API_KEY_SDP) { - res.status(401).json({ error: `Unauthorized` }) - } else { - const comments = await prisma.comments.findMany({ - where: { - dossierId: parseInt(data.id as string) - } - }) - console.log('comments found : ', comments) - res.status(200).json(comments) - } + const data = JSON.parse(req.body) as { id: string; api_key: string }; + //console.log('data received : ', data) + if (data.api_key !== process.env.API_KEY_SDP) { + res.status(401).json({ error: `Unauthorized` }); + } else { + const comments = await prisma.comments.findMany({ + where: { + dossierId: parseInt(data.id as string), + }, + }); + console.log("comments found : ", comments); + res.status(200).json(comments); + } }; -export default withSentry(handler); \ No newline at end of file +export default withSentry(handler); diff --git a/src/pages/api/sync/out/enfants/index.tsx b/src/pages/api/sync/out/enfants/index.tsx index 20cbb8d89..e229c0e12 100644 --- a/src/pages/api/sync/out/enfants/index.tsx +++ b/src/pages/api/sync/out/enfants/index.tsx @@ -4,37 +4,35 @@ import type { NextApiHandler } from "next"; import { getSession } from "next-auth/react"; const handler: NextApiHandler = async (req, res) => { - const session = await getSession({ req }); - if (!session) { - res.status(401).end(); - return; - } - if (req.method == "PUT") { - await passEnfant(req, res); - } else { - res.status(405).end(); - return; - } + const session = await getSession({ req }); + if (!session) { + res.status(401).end(); + return; + } + if (req.method == "PUT") { + await passEnfant(req, res); + } else { + res.status(405).end(); + return; + } }; const passEnfant: NextApiHandler = async (req, res) => { + const data = JSON.parse(req.body) as Enfant; - const data = JSON.parse(req.body) as Enfant - - console.log('data received : ', data) - - const url = `${process.env.API_URL_SDP}/inc/enfants`; - const fetching = await fetch(url, { - method: "PUT", - body: JSON.stringify({...data, api_key: process.env.API_KEY_SDP}) - }).then(async (r) => { - if (!r.ok) { - throw Error(`got status ${r.status}`); - } - return r.json(); - }); - res.status(200).json(fetching); + //console.log('data received : ', data) + const url = `${process.env.API_URL_SDP}/inc/enfants`; + const fetching = await fetch(url, { + method: "PUT", + body: JSON.stringify({ ...data, api_key: process.env.API_KEY_SDP }), + }).then(async (r) => { + if (!r.ok) { + throw Error(`got status ${r.status}`); + } + return r.json(); + }); + res.status(200).json(fetching); }; -export default withSentry(handler); \ No newline at end of file +export default withSentry(handler); diff --git a/src/pages/api/sync/out/pieces/index.tsx b/src/pages/api/sync/out/pieces/index.tsx index 7d77ba727..76ff883b6 100644 --- a/src/pages/api/sync/out/pieces/index.tsx +++ b/src/pages/api/sync/out/pieces/index.tsx @@ -4,38 +4,40 @@ import type { NextApiHandler } from "next"; import { getSession } from "next-auth/react"; const handler: NextApiHandler = async (req, res) => { - const session = await getSession({ req }); - if (!session) { - res.status(401).end(); - return; - } - if (req.method == "PUT") { - await updatePiece(req, res); - } else { - res.status(405).end(); - return; - } + const session = await getSession({ req }); + if (!session) { + res.status(401).end(); + return; + } + if (req.method == "PUT") { + await updatePiece(req, res); + } else { + res.status(405).end(); + return; + } }; const updatePiece: NextApiHandler = async (req, res) => { + const data = JSON.parse(req.body) as { + type: "Enfant" | "Dossier"; + id: string; + statut: STATUT_PIECE; + }; - const data = JSON.parse(req.body) as {type: 'Enfant' | 'Dossier', id: string, statut: STATUT_PIECE} - - console.log('data received : ', data) - - const url = `${process.env.API_URL_SDP}/inc/pieces`; - const fetching = await fetch(url, { - body: JSON.stringify({...data, api_key: process.env.API_KEY_SDP}), - method: "PUT", - }).then(async (r) => { - if (!r.ok) { - console.log('r : ', r.status) - res.status(500).json({ error: `Something went wrong : ${r.status}` }) - } - return r.json(); - }); - res.status(200).json({message: fetching}) + //console.log('data received : ', data) + const url = `${process.env.API_URL_SDP}/inc/pieces`; + const fetching = await fetch(url, { + body: JSON.stringify({ ...data, api_key: process.env.API_KEY_SDP }), + method: "PUT", + }).then(async (r) => { + if (!r.ok) { + console.log("r : ", r.status); + res.status(500).json({ error: `Something went wrong : ${r.status}` }); + } + return r.json(); + }); + res.status(200).json({ message: fetching }); }; -export default withSentry(handler); \ No newline at end of file +export default withSentry(handler); diff --git a/yarn.lock b/yarn.lock index 36b79c090..167b5d4cd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4324,7 +4324,6 @@ __metadata: swr: ^1.1.0 ts-node: ^10.4.0 typescript: 4.5.2 - typescript-eslint: ^0.0.1-alpha.0 use-debounce: ^7.0.1 zod: ^3.20.2 languageName: unknown @@ -11659,13 +11658,6 @@ __metadata: languageName: node linkType: hard -"typescript-eslint@npm:^0.0.1-alpha.0": - version: 0.0.1-alpha.0 - resolution: "typescript-eslint@npm:0.0.1-alpha.0" - checksum: 2896a13f2c77f5193736016abfdb78139c4f781d10c1fa9d4a1b4dbaa6f8696db9e0060bb148d5e9c74eb76e797530b048dcf135b7d4ff303609b2f47a62b206 - languageName: node - linkType: hard - "typescript@npm:4.5.2": version: 4.5.2 resolution: "typescript@npm:4.5.2"