Skip to content

Commit

Permalink
feature[Contract]: Adiciona endpoint de relatórios por contrato.
Browse files Browse the repository at this point in the history
Refs: #28
  • Loading branch information
DanielViniciusAlves committed Aug 5, 2024
1 parent 93240c5 commit 2da3340
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/controllers/Report.controller.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Request, Response } from 'express';
import { listImpressorasRelatorio, findImpressoraWithReport } from '../repository/Impressora.repository'
import { listImpressorasContract, findImpressoraWithReport } from '../repository/Impressora.repository'
import { generateReport, generateMonthReport, createPdf } from '../usecases/report/generate.report'
import { Impressora } from '../types/Impressora.type'
import fs from 'fs';
import { updateReport } from '../usecases/report/update.report';

export default {

async listImpressorasReports(request: Request, response: Response) {
async listImpressorasContractReports(request: Request, response: Response) {
try {
let result = await listImpressorasRelatorio();
const contractId: string = request.params.contractId as string;
const result: Impressora[] | false = await listImpressorasContract(contractId);
if (!result) {
return response.status(500).json({
message: 'Erro: Não foi possível listar impressoras.',
Expand Down
14 changes: 14 additions & 0 deletions src/repository/Impressora.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ export const listImpressorasRelatorio = async (): Promise<Impressora[] | false>
}
}

export const listImpressorasContract = async (contractId: string): Promise<Impressora[] | false> => {
try {
const impressoras = await impressoraClient.findMany({
where: {
numContrato: contractId,
},
});
return impressoras;
} catch (error) {
console.error("Erro ao procurar impressoras: ", error);
return false;
}
}

export const findImpressora = async (id: number): Promise<Impressora | false> => {
try {
const impressora = await impressoraClient.findUnique({ where: { id } });
Expand Down
2 changes: 1 addition & 1 deletion src/routes/report.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { requestHandler } from '../middlewares/requestWrapper.adapter';

const reportRoutes = Router();

reportRoutes.get('/', requestHandler(ReportController.listImpressorasReports));
reportRoutes.get('/contract/:contractId', requestHandler(ReportController.listImpressorasContractReports));
reportRoutes.get('/:id', requestHandler(ReportController.retrieveReport));
reportRoutes.get('/month/:id', requestHandler(ReportController.retrieveMonthReport));

Expand Down

0 comments on commit 2da3340

Please sign in to comment.