From 710dcd367647741b62c55523ff60a9d35ce84c02 Mon Sep 17 00:00:00 2001 From: karol Date: Tue, 30 Jun 2026 14:48:28 +0000 Subject: [PATCH] =?UTF-8?q?Modificaci=C3=B3n=20modulo=20lecturas=20de=20bo?= =?UTF-8?q?mba?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/app.ts | 2 + .../pump-reading/pumpReading.controller.ts | 247 +++++++++++++++++- .../pump-reading/pumpReading.routes.ts | 28 ++ .../pump-reading/pumpReading.service.ts | 8 +- 4 files changed, 280 insertions(+), 5 deletions(-) create mode 100644 backend/src/modules/pump-reading/pumpReading.routes.ts diff --git a/backend/src/app.ts b/backend/src/app.ts index 045f8a7..2cb5765 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -14,6 +14,7 @@ import approvalrouter from "./modules/approvals/approval.routes"; import invoicerouter from "./modules/external-invoices/externalInvoice.routes"; import lpgRouter from "./modules/lpg/lpg.routes"; import anomalyRouter from "./modules/anomalies/anomaly.routes"; +import pumpReadingRouter from "./modules/pump-reading/pumpReading.routes"; @@ -36,6 +37,7 @@ app.use("/api/approvals", approvalrouter); app.use("/api/exterinvoice", invoicerouter); app.use("/api/lpg",lpgRouter); app.use("/api/anomaly", anomalyRouter); +app.use("/api/pumpReading", pumpReadingRouter); app.use(express.urlencoded({ diff --git a/backend/src/modules/pump-reading/pumpReading.controller.ts b/backend/src/modules/pump-reading/pumpReading.controller.ts index d171808..198e4aa 100644 --- a/backend/src/modules/pump-reading/pumpReading.controller.ts +++ b/backend/src/modules/pump-reading/pumpReading.controller.ts @@ -114,6 +114,251 @@ export class PumpReadingController { } } - + async calculateDispensedGallons( + req: Request, + + res: Response + + ) { + + try { + + const gallons = + + await service.calculateDispensedGallons( + + req.params.id as string + + ); + + res.json({ + + gallonsDispensed: gallons + + }); + + } catch (error) { + + res.status(500).json({ + + message: "Error al calcular galones despachados.", + + error + + }); + + } + + } + + // Calcular galones registrados por el sistema + + + async calculateSystemDispensed( + + req: Request, + res: Response + + ) { + + try { + + const gallons = await service.calculateSystemDispensed( + + req.params.id as string + + ); + + res.json({ + + systemDispensed: gallons + + }); + + } catch (error) { + + res.status(500).json({ + + message: "Error al calcular galones del sistema.", + error + + }); + + } + + } + + + // Calcular diferencia + + async calculateDifference( + + req: Request, + res: Response + + ) { + + try { + + const difference = await service.calculateDifference( + + req.params.id as string + + ); + + res.json({ + + difference + + }); + + } catch (error) { + + res.status(500).json({ + + message: "Error al calcular la diferencia.", + + error + + }); + + } + + } + + // Actualizar estado + + async updateStatus( + + req: Request, + res: Response + + ) { + + try { + + const status = await service.updateStatus( + + req.params.id as string + + ); + + res.json({ + + status + + }); + + } catch (error) { + + res.status(500).json({ + + message: "Error al actualizar el estado.", + error + + }); + + } + + } + + //Actualizar Fuel Request relacionadas + + + async updateFuelRequests( + + req: Request, + res: Response + + ) { + + try { + + const requests = await service.updateFuelRequests( + + req.params.id as string + + ); + + res.json(requests); + + } catch (error) { + + res.status(500).json({ + + message: "Error al actualizar las Fuel Request.", + error + + }); + + } + + } + + //Crear anomalía por diferencia + + async createDifferenceAnomaly( + + req: Request, + res: Response + + ) { + + try { + + const anomaly = await service.creataDifferenceAnomaly( + + req.params.id as string + + ); + + res.json(anomaly); + + } catch (error) { + + res.status(500).json({ + + message: "Error al crear la anomalía.", + + error + + }); + + } + + } + + //Cerrar lectura + + async closeReading( + + req: Request, + res: Response + + ) { + + try { + + const reading = await service.closeReading( + + req.params.id as string + + ); + + res.json(reading); + + } catch (error) { + + res.status(500).json({ + + message: "Error al cerrar la lectura.", + + error + + }); + + } + + } } \ No newline at end of file diff --git a/backend/src/modules/pump-reading/pumpReading.routes.ts b/backend/src/modules/pump-reading/pumpReading.routes.ts new file mode 100644 index 0000000..0b1753b --- /dev/null +++ b/backend/src/modules/pump-reading/pumpReading.routes.ts @@ -0,0 +1,28 @@ +import { Router } from "express"; +import { PumpReadingController } from "./pumpReading.controller"; +import { authMiddleware } from "../auth/auth.middleware"; + +const pumpReadingRouter = Router(); + +const controller = new PumpReadingController(); + + +// Obtener todas las lecturas +pumpReadingRouter.get("/", authMiddleware, controller.getAll); + +// Obtener una lectura por ID +pumpReadingRouter.get("/:id", authMiddleware, controller.getById); + +// Crear una nueva lectura +pumpReadingRouter.post("/", authMiddleware, controller.create); + +// Actualizar una lectura +pumpReadingRouter.put("/:id", authMiddleware, controller.update); + +// Eliminar una lectura +pumpReadingRouter.delete("/:id", authMiddleware, controller.delete); + +// Cerrar lectura y realizar el cuadre +pumpReadingRouter.post("/:id/close", authMiddleware, controller.closeReading); + +export default pumpReadingRouter; \ No newline at end of file diff --git a/backend/src/modules/pump-reading/pumpReading.service.ts b/backend/src/modules/pump-reading/pumpReading.service.ts index 28d709a..29e0296 100644 --- a/backend/src/modules/pump-reading/pumpReading.service.ts +++ b/backend/src/modules/pump-reading/pumpReading.service.ts @@ -151,7 +151,7 @@ export class PumpReadingService{ //Actualizar estado - async updateSatatus( + async updateStatus( id:string ){ const reading = await pumpReadingModel.findById(id); @@ -211,7 +211,7 @@ export class PumpReadingService{ //Crear anomalía por diferencencia - async creataDifferenfeAnomaly( + async creataDifferenceAnomaly( id:string ){ const reading = await pumpReadingModel.findById(id); @@ -263,14 +263,14 @@ export class PumpReadingService{ const difference = await this.calculateDifference(id); - await this.updateSatatus(id); + await this.updateStatus(id); await this.updateFuelRequests(id); //Crear anomalía if(difference !== 0){ - await this.creataDifferenfeAnomaly(id); + await this.creataDifferenceAnomaly(id); } return await pumpReadingModel