-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: rework of table and formulaire enfant (demandeurs) * fix: fix desynchro enfants form * fix: finish nex implementation form enfants
- Loading branch information
1 parent
9601557
commit 5ed6796
Showing
13 changed files
with
1,981 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import type { NextApiHandler, NextApiRequest } from "next"; | ||
import { Enfant, PrismaClient } from "@prisma/client"; | ||
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 == "GET") { | ||
await get(req, res); | ||
} else { | ||
res.status(405).end(); | ||
return; | ||
} | ||
}; | ||
|
||
function getId(req: NextApiRequest): number { | ||
return Number(req.query.id as string); | ||
} | ||
|
||
const get: NextApiHandler = async (req, res) => { | ||
const session = await getSession({ req }); | ||
const prisma = new PrismaClient(); | ||
console.log('order : ', req.query.order) | ||
try { | ||
const dossierId = getId(req); | ||
const dossierConcerned = await prisma.dossier.findUnique({ | ||
where: { | ||
id: dossierId | ||
} | ||
}) | ||
|
||
if ( | ||
dossierConcerned?.userId === session?.dbUser.id || | ||
dossierConcerned?.collaboratorIds.includes(session?.dbUser.id) | ||
) { | ||
const enfantsByDossier = await prisma.enfant.findMany({ | ||
take: req.query.numberByPage ? Number(req.query.numberByPage) : 25, | ||
skip: 25 * Number(req.query.page), | ||
include: { | ||
piecesDossier: true, | ||
remuneration: true, | ||
Comments: true | ||
}, | ||
where: { | ||
dossierId: dossierId | ||
}, | ||
orderBy: { | ||
[req.query.termToOrder as string]: req.query.order as string | ||
} | ||
}) | ||
const countEnfants = await prisma.enfant.count({ | ||
where: { | ||
dossierId: dossierId | ||
} | ||
} | ||
) | ||
res.status(200).json({enfants: enfantsByDossier, count: countEnfants}); | ||
} else { | ||
res.status(401).json({ message: "Unauthorized" }); | ||
} | ||
} catch(e) { | ||
console.log(e); | ||
} | ||
}; | ||
|
||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.