-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from mdsreq-fga-unb/54-adicionar-drill
Integração das USs 50, 54, 61, 58 e 57 ao sistema
- Loading branch information
Showing
30 changed files
with
2,757 additions
and
16,073 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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
{ | ||
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint", | ||
"editor.formatOnPaste": false, // required | ||
"editor.formatOnType": false, // required | ||
"editor.formatOnSave": true, // optional | ||
"editor.formatOnSaveMode": "file", // required to format on save | ||
"files.autoSave": "onFocusChange", // optional but recommended | ||
"vs-code-prettier-eslint.prettierLast": true, | ||
"[typescript]": { | ||
"editor.defaultFormatter": "vscode.typescript-language-features" | ||
} // set as "true" to run 'prettier' last not first | ||
} | ||
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint", | ||
"editor.formatOnPaste": false, // required | ||
"editor.formatOnType": false, // required | ||
"editor.formatOnSave": true, // optional | ||
"editor.formatOnSaveMode": "file", // required to format on save | ||
"files.autoSave": "onFocusChange", // optional but recommended | ||
"vs-code-prettier-eslint.prettierLast": true, | ||
"[typescript]": { | ||
"editor.defaultFormatter": "vscode.typescript-language-features" | ||
} // set as "true" to run 'prettier' last not first | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- CreateTable | ||
CREATE TABLE "Drill" ( | ||
"id" TEXT NOT NULL, | ||
"title" TEXT NOT NULL, | ||
"description" TEXT NOT NULL, | ||
"observations" TEXT NOT NULL, | ||
"classPlanId" TEXT NOT NULL, | ||
|
||
CONSTRAINT "Drill_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Drill" ADD CONSTRAINT "Drill_classPlanId_fkey" FOREIGN KEY ("classPlanId") REFERENCES "ClassPlan"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
8 changes: 8 additions & 0 deletions
8
backend/prisma/migrations/20231205200843_remove_campo_level/migration.sql
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,8 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `level` on the `User` table. All the data in the column will be lost. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "User" DROP COLUMN "level"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { Request, Response } from "express" | ||
import { prisma } from "@/prisma" | ||
import { ZodError } from "zod" | ||
import { drillSchema } from "@/zodSchemas/drill.zod" | ||
import { fromZodError } from "zod-validation-error" | ||
import { Prisma } from "@prisma/client" | ||
|
||
export default class drillController { | ||
create = async (req: Request, res: Response) => { | ||
try { | ||
const data = drillSchema.parse(req.body) | ||
const drill = (await prisma.drill.create({ | ||
data: { | ||
...data, | ||
}, | ||
include: { | ||
classPlan: { | ||
select: { | ||
id: true, | ||
}, | ||
}, | ||
}, | ||
})) as Prisma.DrillCreateInput | ||
res.status(201).json(drill) | ||
} catch (err) { | ||
if (err instanceof ZodError) { | ||
res.status(400).json(fromZodError(err)) | ||
} else { | ||
res.status(500).json({ error: "Internal Server Error" }) | ||
} | ||
} | ||
} | ||
|
||
getManyByClassPlanId = async (req: Request, res: Response) => { | ||
try { | ||
const { classPlanId } = req.params | ||
const drills = await prisma.drill.findMany({ | ||
where: { | ||
classPlanId, | ||
}, | ||
select: { | ||
id: true, | ||
title: true, | ||
}, | ||
}) | ||
res.status(200).json(drills) | ||
} catch (err) { | ||
res.status(500).json({ error: "Internal Server Error" }) | ||
} | ||
} | ||
|
||
updateById = async (req: Request, res: Response) => { | ||
try { | ||
const id = req.params.id | ||
const data = drillSchema.parse(req.body) | ||
const updatedDrill = await prisma.drill.update({ | ||
where: { | ||
id, | ||
}, | ||
data: { | ||
...data, | ||
}, | ||
}) | ||
res.status(204).json(updatedDrill) | ||
} catch (err) { | ||
if (err instanceof ZodError) { | ||
res.status(400).json(fromZodError(err)) | ||
} else { | ||
res.status(500).json({ error: "Internal Server Error" }) | ||
} | ||
} | ||
} | ||
|
||
deleteById = async (req: Request, res: Response) => { | ||
try { | ||
const id = req.params.id | ||
const deletedDrill = await prisma.drill.delete({ | ||
where: { | ||
id, | ||
}, | ||
}) | ||
res.status(204).json(deletedDrill) | ||
} catch (err) { | ||
res.status(500).json({ error: "Internal Server Error" }) | ||
} | ||
} | ||
|
||
show = async (req: Request, res: Response) => { | ||
try { | ||
const { id } = req.params | ||
const drill = await prisma.drill.findUnique({ | ||
where: { | ||
id: id, | ||
}, | ||
include: { | ||
classPlan: { | ||
select: { | ||
id: true, | ||
}, | ||
}, | ||
}, | ||
}) | ||
res.status(200).json(drill) | ||
} catch (err) { | ||
res.status(500).json({ error: "Internal Server Error" }) | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Router } from "express" | ||
import drillController from "../controllers/drillController" | ||
|
||
const drillRouters = Router() | ||
const drill = new drillController() | ||
|
||
drillRouters.post("/", drill.create) | ||
drillRouters.get("/:classPlanId", drill.getManyByClassPlanId) | ||
drillRouters.get("/drill/:id", drill.show) | ||
drillRouters.put("/:id", drill.updateById) | ||
drillRouters.delete("/:id", drill.deleteById) | ||
|
||
export default drillRouters |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { z } from "zod" | ||
|
||
const drillSchema = z.object({ | ||
title: z.string().min(5, "Título deve ter no mínimo 5 caracteres"), | ||
description: z | ||
.string() | ||
.max(500, "Descrição deve ter no máximo 500 caracteres"), | ||
observations: z | ||
.string() | ||
.max(500, "Observações deve ter no máximo 500 caracteres"), | ||
classPlanId: z.string().uuid("Id do plano de aula inválido"), | ||
}) | ||
|
||
export { drillSchema } |
Oops, something went wrong.