forked from Yara724/api
blame and claim refactored
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectModel } from "@nestjs/mongoose";
|
||||
import { FilterQuery, Model, Types } from "mongoose";
|
||||
import { ClaimCase, ClaimCaseDocument } from "../schema/claim-cases.schema";
|
||||
|
||||
@Injectable()
|
||||
export class ClaimCaseDbService {
|
||||
constructor(
|
||||
@InjectModel(ClaimCase.name)
|
||||
private readonly claimCaseModel: Model<ClaimCaseDocument>,
|
||||
) {}
|
||||
|
||||
async create(payload: Partial<ClaimCase>): Promise<ClaimCaseDocument> {
|
||||
return this.claimCaseModel.create(payload);
|
||||
}
|
||||
|
||||
async findById(id: string | Types.ObjectId): Promise<ClaimCaseDocument | null> {
|
||||
return this.claimCaseModel.findById(id);
|
||||
}
|
||||
|
||||
async findOne(filter: FilterQuery<ClaimCase>): Promise<ClaimCaseDocument | null> {
|
||||
return this.claimCaseModel.findOne(filter);
|
||||
}
|
||||
|
||||
async findByIdAndUpdate(
|
||||
id: string | Types.ObjectId,
|
||||
update: any,
|
||||
): Promise<ClaimCaseDocument | null> {
|
||||
return this.claimCaseModel.findByIdAndUpdate(id, update, { new: true });
|
||||
}
|
||||
|
||||
async find(
|
||||
filter: FilterQuery<ClaimCase>,
|
||||
options?: { lean?: boolean; select?: string },
|
||||
): Promise<ClaimCaseDocument[] | Record<string, unknown>[]> {
|
||||
if (options?.lean) {
|
||||
const query = options?.select
|
||||
? this.claimCaseModel.find(filter).select(options.select).lean()
|
||||
: this.claimCaseModel.find(filter).lean();
|
||||
return query.exec() as Promise<Record<string, unknown>[]>;
|
||||
}
|
||||
const query = options?.select
|
||||
? this.claimCaseModel.find(filter).select(options.select)
|
||||
: this.claimCaseModel.find(filter);
|
||||
return query.exec() as Promise<ClaimCaseDocument[]>;
|
||||
}
|
||||
|
||||
async countByFilter(filter: FilterQuery<ClaimCase>): Promise<number> {
|
||||
return this.claimCaseModel.countDocuments(filter);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,6 @@ export class VideoCaptureDbService {
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<VideoCaptureModel | null> {
|
||||
return this.videoCapture.findById(id).lean();
|
||||
return this.videoCapture.findById(id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user