-
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 #49 from Daniel-Alvarenga/main
New tables and routes
- Loading branch information
Showing
11 changed files
with
306 additions
and
13 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
43 changes: 43 additions & 0 deletions
43
server/prisma/migrations/20240804231659_add_notas_and_materias_tables/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,43 @@ | ||
-- CreateTable | ||
CREATE TABLE `materias` ( | ||
`id` VARCHAR(191) NOT NULL, | ||
`name` VARCHAR(191) NOT NULL, | ||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), | ||
`updatedAt` DATETIME(3) NOT NULL, | ||
|
||
PRIMARY KEY (`id`) | ||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | ||
|
||
-- CreateTable | ||
CREATE TABLE `cursos_materias` ( | ||
`cursoId` VARCHAR(191) NOT NULL, | ||
`materiaId` VARCHAR(191) NOT NULL, | ||
|
||
PRIMARY KEY (`cursoId`, `materiaId`) | ||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | ||
|
||
-- CreateTable | ||
CREATE TABLE `notas` ( | ||
`id` VARCHAR(191) NOT NULL, | ||
`alunoId` VARCHAR(191) NOT NULL, | ||
`materiaId` VARCHAR(191) NOT NULL, | ||
`bimestre` INTEGER NOT NULL, | ||
`ano` INTEGER NOT NULL, | ||
`mencao` ENUM('I', 'R', 'B', 'MB') NOT NULL, | ||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), | ||
`updatedAt` DATETIME(3) NOT NULL, | ||
|
||
PRIMARY KEY (`id`) | ||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE `cursos_materias` ADD CONSTRAINT `cursos_materias_cursoId_fkey` FOREIGN KEY (`cursoId`) REFERENCES `cursos`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE `cursos_materias` ADD CONSTRAINT `cursos_materias_materiaId_fkey` FOREIGN KEY (`materiaId`) REFERENCES `materias`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE `notas` ADD CONSTRAINT `notas_alunoId_fkey` FOREIGN KEY (`alunoId`) REFERENCES `alunos`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE `notas` ADD CONSTRAINT `notas_materiaId_fkey` FOREIGN KEY (`materiaId`) REFERENCES `materias`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; |
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
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
47 changes: 47 additions & 0 deletions
47
server/src/modules/services/funcionario/CompareBoletinsUseCase.ts
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,47 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { prisma } from "../../../prisma/client"; | ||
import { AppError } from "../../../errors/error"; | ||
import { CompareBoletimDTO } from '../../interfaces/funcionarioDTOs'; | ||
import { downloadFromMinio } from "../../../minioService"; | ||
import { clearUploads } from '../shared/helpers/helpers'; | ||
|
||
export class CompareBoletimUseCase { | ||
async execute({ boletimId, file }: CompareBoletimDTO) { | ||
if (!boletimId) { | ||
throw new AppError('ID do boletim não fornecido.'); | ||
} | ||
|
||
if (!file || !file.path) { | ||
throw new AppError('Arquivo do boletim não fornecido.'); | ||
} | ||
|
||
const boletim = await prisma.boletim.findUnique({ | ||
where: { | ||
id: boletimId, | ||
}, | ||
}); | ||
|
||
if (!boletim) { | ||
throw new AppError('Boletim não encontrado.'); | ||
} | ||
|
||
const filePath = path.resolve(file.path); | ||
const fileBuffer = fs.readFileSync(filePath); | ||
|
||
const storedBoletimBuffer = await downloadFromMinio('boot', boletim.caminho); | ||
|
||
const isEqual = fileBuffer.equals(storedBoletimBuffer); | ||
|
||
const novoStatus = isEqual ? 'APROVADO' : 'RECUSADO'; | ||
|
||
await prisma.boletim.update({ | ||
where: { id: boletimId }, | ||
data: { status: novoStatus } | ||
}); | ||
|
||
await clearUploads(); | ||
|
||
return { message: `Boletim ${novoStatus}.` }; | ||
} | ||
} |
Oops, something went wrong.