Skip to content

Commit

Permalink
Concluindo US52 - Front e Back
Browse files Browse the repository at this point in the history
Co-authored-by: Artur <[email protected]>
  • Loading branch information
JoaoBarreto03 and ArturRSA19 committed Dec 9, 2023
1 parent 64d384b commit 31fc067
Show file tree
Hide file tree
Showing 6 changed files with 332 additions and 229 deletions.
21 changes: 21 additions & 0 deletions backend/src/controllers/classPlanController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,25 @@ export default class classPlanController {
res.status(500).json({ errors: { server: "Server error" } })
}
}
updateById = async (req: Request, res: Response) => {
try {
const id = req.params.id
const data = classPlanSchema.parse(req.body)
const updatedPlan = await prisma.classPlan.update({
where: {
id,
},
data: {
...data,
},
})
res.status(204).json(updatedPlan)
} catch (err) {
if (err instanceof ZodError) {
res.status(400).json(fromZodError(err))
} else {
res.status(500).json({ error: "Internal Server Error" })
}
}
}
}
1 change: 1 addition & 0 deletions backend/src/routes/classPlanRouters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const classPlan = new classPlanController()
classPlanRouters.post("/", classPlan.create)
classPlanRouters.get("/:id", classPlan.show)
classPlanRouters.get("/planos-usuario/:userId", classPlan.list)
classPlanRouters.put("/:id", classPlan.updateById)
classPlanRouters.delete("/:id", classPlan.delete)

export default classPlanRouters
5 changes: 4 additions & 1 deletion frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 31fc067

Please sign in to comment.