forked from Yara724/api
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { Injectable } from "@nestjs/common";
|
|
import { InjectModel } from "@nestjs/mongoose";
|
|
import { FilterQuery, Model, Types, UpdateQuery } from "mongoose";
|
|
import { ClaimRequestManagementModel } from "src/claim-request-management/entites/schema/claim-request-management.schema";
|
|
const crypto = require("node:crypto");
|
|
|
|
@Injectable()
|
|
export class ClaimRequestManagementDbService {
|
|
constructor(
|
|
@InjectModel(ClaimRequestManagementModel.name)
|
|
private readonly model: Model<ClaimRequestManagementModel>,
|
|
) {}
|
|
|
|
async findOne(
|
|
id?: string,
|
|
filter?: FilterQuery<ClaimRequestManagementModel>,
|
|
) {
|
|
if (filter) return await this.model.findOne(filter);
|
|
return await this.model.findOne({ _id: new Types.ObjectId(id) });
|
|
}
|
|
|
|
async findOneDocument(
|
|
id: string,
|
|
filter?: FilterQuery<ClaimRequestManagementModel>,
|
|
) {
|
|
if (filter) return await this.model.findOne(filter);
|
|
return await this.model.findOne({ _id: new Types.ObjectId(id) }).lean();
|
|
}
|
|
|
|
async findOneAndUpdate(
|
|
filter: FilterQuery<ClaimRequestManagementModel>,
|
|
update: UpdateQuery<ClaimRequestManagementModel>,
|
|
option?,
|
|
) {
|
|
return await this.model.findOneAndUpdate(filter, update, option);
|
|
}
|
|
|
|
async findAndUpdate(
|
|
id: string,
|
|
update: UpdateQuery<ClaimRequestManagementModel>,
|
|
option?: FilterQuery<ClaimRequestManagementModel>,
|
|
) {
|
|
return await this.model.findByIdAndUpdate(
|
|
{ _id: new Types.ObjectId(id) },
|
|
update,
|
|
option,
|
|
);
|
|
}
|
|
}
|