CRUD Modulo requisiciones LGP y actualización modulos de aprobaciones
This commit is contained in:
87
backend/src/modules/lpg/lpg.service.ts
Normal file
87
backend/src/modules/lpg/lpg.service.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user