Modificación modulo lecturas de bomba
This commit is contained in:
@ -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({
|
||||
|
||||
@ -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
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
28
backend/src/modules/pump-reading/pumpReading.routes.ts
Normal file
28
backend/src/modules/pump-reading/pumpReading.routes.ts
Normal file
@ -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;
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user