blame and claim refactored

This commit is contained in:
2026-02-24 12:19:25 +03:30
parent 0d8858f458
commit 35732dd70a
81 changed files with 11603 additions and 77 deletions

View File

@@ -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);
}
}