forked from Yara724/api
Initial commit after migration to gitea
This commit is contained in:
34
src/client/entities/db-service/branch.db.service.ts
Normal file
34
src/client/entities/db-service/branch.db.service.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectModel } from "@nestjs/mongoose";
|
||||
import { FilterQuery, Model, Types } from "mongoose";
|
||||
import { BranchModel, BranchDocument } from "../schema/branch.schema";
|
||||
|
||||
@Injectable()
|
||||
export class BranchDbService {
|
||||
constructor(
|
||||
@InjectModel(BranchModel.name)
|
||||
private readonly branchModel: Model<BranchModel>,
|
||||
) {}
|
||||
|
||||
async create(branch: BranchModel): Promise<BranchModel> {
|
||||
return await this.branchModel.create(branch);
|
||||
}
|
||||
|
||||
async find(branch: FilterQuery<BranchModel>): Promise<BranchDocument> {
|
||||
return await this.branchModel.findOne(branch);
|
||||
}
|
||||
|
||||
async findOne(branch: FilterQuery<BranchModel>) {
|
||||
return this.branchModel.findOne(branch);
|
||||
}
|
||||
|
||||
async findAll(insuranceId: string): Promise<BranchModel[]> {
|
||||
return await this.branchModel.find({
|
||||
clientKey: new Types.ObjectId(insuranceId),
|
||||
});
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<BranchModel | null> {
|
||||
return this.branchModel.findById(id).lean();
|
||||
}
|
||||
}
|
||||
28
src/client/entities/db-service/client.db.service.ts
Normal file
28
src/client/entities/db-service/client.db.service.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectModel } from "@nestjs/mongoose";
|
||||
import { FilterQuery, Model } from "mongoose";
|
||||
import { ClientModel, ClientDocument } from "../schema/client.schema";
|
||||
|
||||
@Injectable()
|
||||
export class ClientDbService {
|
||||
constructor(
|
||||
@InjectModel(ClientModel.name)
|
||||
private readonly clientModel: Model<ClientModel>,
|
||||
) {}
|
||||
|
||||
async create(client: ClientModel): Promise<ClientModel> {
|
||||
return await this.clientModel.create(client);
|
||||
}
|
||||
|
||||
async find(client: FilterQuery<ClientModel>): Promise<ClientDocument> {
|
||||
return await this.clientModel.findOne(client);
|
||||
}
|
||||
|
||||
async findOne(client: FilterQuery<ClientModel>) {
|
||||
return this.clientModel.findOne(client);
|
||||
}
|
||||
|
||||
async findAll(): Promise<ClientModel[]> {
|
||||
return await this.clientModel.find();
|
||||
}
|
||||
}
|
||||
32
src/client/entities/schema/branch.schema.ts
Normal file
32
src/client/entities/schema/branch.schema.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
|
||||
import { Types } from "mongoose";
|
||||
|
||||
export type BranchDocument = BranchModel & Document;
|
||||
|
||||
@Schema({ collection: "branches", versionKey: false, timestamps: true })
|
||||
export class BranchModel {
|
||||
@Prop({ required: true, type: Types.ObjectId, ref: "ClientModel" })
|
||||
clientKey: Types.ObjectId;
|
||||
|
||||
@Prop({ required: true })
|
||||
name: string;
|
||||
|
||||
@Prop({ required: true })
|
||||
code: string;
|
||||
|
||||
@Prop({ required: true })
|
||||
city: string;
|
||||
|
||||
@Prop({ required: true })
|
||||
state: string;
|
||||
|
||||
@Prop({ required: true })
|
||||
address: string;
|
||||
|
||||
@Prop()
|
||||
phoneNumber?: string;
|
||||
}
|
||||
|
||||
export const BranchSchema = SchemaFactory.createForClass(BranchModel);
|
||||
|
||||
BranchSchema.index({ clientKey: 1, code: 1 }, { unique: true });
|
||||
25
src/client/entities/schema/client.schema.ts
Normal file
25
src/client/entities/schema/client.schema.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
|
||||
|
||||
export type ClientDocument = ClientModel & Document;
|
||||
|
||||
@Schema({ collection: "clients", versionKey: false })
|
||||
export class ClientModel {
|
||||
@Prop({ required: true, unique: true, type: Object })
|
||||
clientName: {
|
||||
persian: string;
|
||||
english: string;
|
||||
};
|
||||
|
||||
@Prop({ required: false, unique: true, type: Object })
|
||||
property: {
|
||||
smsApiKey: string;
|
||||
};
|
||||
|
||||
@Prop({ required: true, unique: false })
|
||||
useExpertMode: "legal" | "genuine";
|
||||
|
||||
@Prop({ required: true, unique: false })
|
||||
clientCode: number;
|
||||
}
|
||||
|
||||
export const ClientDbSchema = SchemaFactory.createForClass(ClientModel);
|
||||
Reference in New Issue
Block a user