| Current Path : /home/deltalab/PMS/logistic-backend/src/models/kpi/ |
| Current File : //home/deltalab/PMS/logistic-backend/src/models/kpi/kpi.service.ts |
import { Model } from 'mongoose';
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Kpi, KpiDocument } from './kpi.schema';
@Injectable()
export class KpiService {
constructor(
@InjectModel(Kpi.name)
private kpiModel: Model<KpiDocument>,
) {}
async create(kpi: Kpi): Promise<Kpi> {
const createdCat = new this.kpiModel(kpi);
return createdCat.save();
}
async delete(id: string): Promise<Kpi> {
return await this.kpiModel.findByIdAndRemove(id);
}
async update(id: string, kpi: Kpi): Promise<Kpi> {
return await this.kpiModel.findByIdAndUpdate(id, kpi, {
new: true,
});
}
async readAll(): Promise<Kpi[]> {
return this.kpiModel.find().exec();
}
async readById(id: string): Promise<Kpi> {
return await this.kpiModel.findById(id).exec();
}
}