Skip to content

Commit

Permalink
fix: lower consoles (#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Bouquillon authored Dec 12, 2023
1 parent 1de2199 commit aa51d0d
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 132 deletions.
16 changes: 8 additions & 8 deletions formulaire/pages/api/comments/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
};
Expand All @@ -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,
Expand All @@ -69,7 +69,7 @@ const updateCommentairesNotifications: NextApiHandler = async (req, res) => {
},
},
});
await prisma?.$disconnect()
await prisma?.$disconnect();
res.status(200).json(updateComments);
};

Expand All @@ -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);
}
};
Expand Down
27 changes: 16 additions & 11 deletions formulaire/pages/api/enfants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
};
Expand All @@ -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);
}
};
Expand All @@ -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");
Expand All @@ -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;
}
});
}

Expand All @@ -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);
};
Expand Down
14 changes: 7 additions & 7 deletions formulaire/pages/api/sync/inc/commentaires/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -30,23 +30,23 @@ 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);
}
};

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);
}
};
Expand All @@ -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` });
Expand Down Expand Up @@ -137,7 +137,7 @@ const get: NextApiHandler = async (req, res) => {
};
}
);
await prisma?.$disconnect()
await prisma?.$disconnect();

res.status(200).json(notificationsByDossier);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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` });
Expand All @@ -48,7 +48,7 @@ const update: NextApiHandler = async (req, res) => {
},
},
});
await prisma?.$disconnect()
await prisma?.$disconnect();
res.status(200).json(updateComments);
}
};
Expand Down
30 changes: 14 additions & 16 deletions formulaire/pages/api/sync/inc/enfants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
6 changes: 3 additions & 3 deletions formulaire/pages/api/sync/inc/pieces/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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` });
Expand All @@ -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" });
};
Expand Down
41 changes: 20 additions & 21 deletions src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
export default withSentry(handler);
52 changes: 25 additions & 27 deletions src/pages/api/sync/out/enfants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
export default withSentry(handler);
Loading

0 comments on commit aa51d0d

Please sign in to comment.