CRUD Modulo requisiciones LGP y actualización modulos de aprobaciones

This commit is contained in:
2026-06-25 14:45:39 +00:00
parent 0d8ef99e81
commit eeb563825a
11 changed files with 451 additions and 168 deletions

View File

@ -0,0 +1,87 @@
import lpgModel from "./lpg.model";
import { ILpg } from "./lpg.interface";
import { idText } from "typescript";
export class LPGService{
//Crear solicitud gas LPG
async create (
data:ILpg
){
data.totalAmount = data.gallons *
data.pricePerGallon;
const lpg = new lpgModel(data);
return await lpg.save();
}
//Obtener todas las requisiciones
async getAll() {
return await lpgModel
.find()
.populate("requestedBy")
.populate("approveBy")
}
//Obtener requisición por Id
async getById(
id:string
){
return await lpgModel
.findById(id)
.populate("requestedBy")
.populate("approveBy")
}
async update(
id:string,
data:Partial<ILpg>
){
if (data.gallons &&
data.pricePerGallon
){
data.totalAmount =
data.gallons *
data.pricePerGallon
}
return await lpgModel
.findByIdAndUpdate(
id,
data,
{
new:true
}
);
}
async getByStatus(
status:string
){
return await lpgModel
.find({
status
} as any)
}
async getByPlant(
plant:string
){
return await lpgModel
.find({
plant
}as any)
}
async delete(
id:string
){
return await lpgModel
.findByIdAndDelete(id);
}
}