forked from Yara724/api
Initial commit after migration to gitea
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { InjectModel } from "@nestjs/mongoose";
|
||||
import { FilterQuery, Model } from "mongoose";
|
||||
import { CarGreenCardModel } from "src/claim-request-management/entites/schema/car-green-card.schema";
|
||||
|
||||
export class CarGreenCardDbService {
|
||||
constructor(
|
||||
@InjectModel(CarGreenCardModel.name)
|
||||
private readonly model: Model<CarGreenCardModel>,
|
||||
) {}
|
||||
async create(greenCard): Promise<CarGreenCardModel> {
|
||||
return await this.model.create(greenCard);
|
||||
}
|
||||
|
||||
async findOne(
|
||||
filter: FilterQuery<CarGreenCardModel>,
|
||||
): Promise<CarGreenCardModel> {
|
||||
return await this.model.findOne({ filter });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
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 create(
|
||||
claimRequest: ClaimRequestManagementModel,
|
||||
): Promise<ClaimRequestManagementModel> {
|
||||
const uniqueRequestNumber = await this.generateUniqueNumbers();
|
||||
return this.model.create({
|
||||
...claimRequest,
|
||||
requestNumber: uniqueRequestNumber,
|
||||
});
|
||||
}
|
||||
|
||||
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 findAllByStatus(filter: FilterQuery<ClaimRequestManagementModel>) {
|
||||
return await this.model.find(filter);
|
||||
}
|
||||
|
||||
async findAndDelete(
|
||||
filter: FilterQuery<ClaimRequestManagementModel>,
|
||||
option,
|
||||
) {
|
||||
return await this.model.deleteMany(filter, option);
|
||||
}
|
||||
|
||||
async findAllAndPagination(
|
||||
filter: FilterQuery<ClaimRequestManagementModel>,
|
||||
currentPage: number,
|
||||
countPerPage: number,
|
||||
) {
|
||||
const responsePerPage = countPerPage | 1;
|
||||
const skipPge = responsePerPage * (Number(currentPage) - 1);
|
||||
return await this.model.find(filter).limit(responsePerPage).skip(skipPge);
|
||||
}
|
||||
|
||||
async aggregate(filter?) {
|
||||
return await this.model.aggregate(filter);
|
||||
}
|
||||
|
||||
async findAndUpdate(
|
||||
id: string,
|
||||
update: UpdateQuery<ClaimRequestManagementModel>,
|
||||
option?: FilterQuery<ClaimRequestManagementModel>,
|
||||
) {
|
||||
return await this.model.findByIdAndUpdate(
|
||||
{ _id: new Types.ObjectId(id) },
|
||||
update,
|
||||
option,
|
||||
);
|
||||
}
|
||||
|
||||
async findAllByAnyFilter(
|
||||
filter: FilterQuery<ClaimRequestManagementModel>,
|
||||
): Promise<ClaimRequestManagementModel[]> {
|
||||
return await this.model.find(filter);
|
||||
}
|
||||
|
||||
async countByFilter(
|
||||
filter: FilterQuery<ClaimRequestManagementModel>,
|
||||
): Promise<number> {
|
||||
return await this.model.countDocuments(filter);
|
||||
}
|
||||
async findAll(): Promise<ClaimRequestManagementModel[]> {
|
||||
return await this.model.find();
|
||||
}
|
||||
async generateUniqueNumbers(digits = 5) {
|
||||
try {
|
||||
const max = Math.pow(10, digits);
|
||||
const randomBytes = crypto.randomBytes(Math.ceil(digits / 2));
|
||||
const randomNumber = parseInt(randomBytes.toString("hex"), 16) % max;
|
||||
return randomNumber.toString().padStart(digits, "0");
|
||||
} catch (error) {
|
||||
console.error("Error generating unique numbers:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async findAllWithFilter(filter?: FilterQuery<ClaimRequestManagementModel>) {
|
||||
return await this.model.find(filter);
|
||||
}
|
||||
|
||||
async findByIdAndUpdate(
|
||||
id: string,
|
||||
updateDto: UpdateQuery<ClaimRequestManagementModel>,
|
||||
): Promise<ClaimRequestManagementModel | null> {
|
||||
return this.model.findByIdAndUpdate(id, updateDto, { new: true }).lean();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectModel } from "@nestjs/mongoose";
|
||||
import { FilterQuery, Model, Types } from "mongoose";
|
||||
import { ClaimRequiredDocument } from "src/claim-request-management/entites/schema/claim-required-document.schema";
|
||||
|
||||
@Injectable()
|
||||
export class ClaimRequiredDocumentDbService {
|
||||
constructor(
|
||||
@InjectModel(ClaimRequiredDocument.name)
|
||||
private readonly model: Model<ClaimRequiredDocument>,
|
||||
) {}
|
||||
|
||||
async create(document: Partial<ClaimRequiredDocument>): Promise<ClaimRequiredDocument> {
|
||||
return await this.model.create(document);
|
||||
}
|
||||
|
||||
async findOne(
|
||||
filter: FilterQuery<ClaimRequiredDocument>,
|
||||
): Promise<ClaimRequiredDocument | null> {
|
||||
return await this.model.findOne(filter);
|
||||
}
|
||||
|
||||
async findAll(
|
||||
filter: FilterQuery<ClaimRequiredDocument>,
|
||||
): Promise<ClaimRequiredDocument[]> {
|
||||
return await this.model.find(filter);
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<ClaimRequiredDocument | null> {
|
||||
return this.model.findById(id).lean();
|
||||
}
|
||||
|
||||
async findByClaimId(claimId: string): Promise<ClaimRequiredDocument[]> {
|
||||
return this.model.find({ claimId: new Types.ObjectId(claimId) });
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<void> {
|
||||
await this.model.findByIdAndDelete(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectModel } from "@nestjs/mongoose";
|
||||
import { FilterQuery, Model } from "mongoose";
|
||||
import { ClaimSignModel } from "src/claim-request-management/entites/schema/claim-sign";
|
||||
|
||||
@Injectable()
|
||||
export class ClaimSignDbService {
|
||||
constructor(
|
||||
@InjectModel(ClaimSignModel.name)
|
||||
private readonly claimSignService: Model<ClaimSignModel>,
|
||||
) {}
|
||||
|
||||
async create(claimSign: ClaimSignModel): Promise<ClaimSignModel> {
|
||||
return await this.claimSignService.create(claimSign);
|
||||
}
|
||||
|
||||
async findOne(filter: FilterQuery<ClaimSignModel>): Promise<ClaimSignModel> {
|
||||
return await this.claimSignService.findOne(filter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { InjectModel } from "@nestjs/mongoose";
|
||||
import { Model, Types } from "mongoose";
|
||||
import { DamagePartImageModel } from "src/claim-request-management/entites/schema/damage-image-part.schema";
|
||||
|
||||
export class DamageImageDbService {
|
||||
constructor(
|
||||
@InjectModel(DamagePartImageModel.name)
|
||||
private readonly model: Model<DamagePartImageModel>,
|
||||
) {}
|
||||
|
||||
async create(image): Promise<DamagePartImageModel> {
|
||||
return await this.model.create(image);
|
||||
}
|
||||
|
||||
async findOne(id: string): Promise<DamagePartImageModel> {
|
||||
return await this.model.findById(new Types.ObjectId(id));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectModel } from "@nestjs/mongoose";
|
||||
import { FilterQuery, Model } from "mongoose";
|
||||
import { ClaimFactorsImage } from "src/claim-request-management/entites/schema/factor-image.schema";
|
||||
|
||||
@Injectable()
|
||||
export class ClaimFactorsImageDbService {
|
||||
constructor(
|
||||
@InjectModel(ClaimFactorsImage.name)
|
||||
private readonly model: Model<ClaimFactorsImage>,
|
||||
) {}
|
||||
async create(image): Promise<ClaimFactorsImage> {
|
||||
return await this.model.create(image);
|
||||
}
|
||||
|
||||
async findOne(
|
||||
filter: FilterQuery<ClaimFactorsImage>,
|
||||
): Promise<ClaimFactorsImage> {
|
||||
return await this.model.findOne({ filter });
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<ClaimFactorsImage | null> {
|
||||
return this.model.findById(id).lean();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectModel } from "@nestjs/mongoose";
|
||||
import { FilterQuery, Model } from "mongoose";
|
||||
import { VideoCaptureModel } from "src/claim-request-management/entites/schema/video-capture.schema";
|
||||
|
||||
@Injectable()
|
||||
export class VideoCaptureDbService {
|
||||
constructor(
|
||||
@InjectModel(VideoCaptureModel.name)
|
||||
private readonly videoCapture: Model<VideoCaptureModel>,
|
||||
) {}
|
||||
async create(video): Promise<VideoCaptureModel> {
|
||||
return await this.videoCapture.create(video);
|
||||
}
|
||||
|
||||
async findOne(
|
||||
filter: FilterQuery<VideoCaptureModel>,
|
||||
): Promise<VideoCaptureModel> {
|
||||
return await this.videoCapture.findOne(filter);
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<VideoCaptureModel | null> {
|
||||
return this.videoCapture.findById(id).lean();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user