YARA-1136

This commit is contained in:
SepehrYahyaee
2026-07-26 11:35:21 +03:30
parent 778544c321
commit 9828aee8af
13 changed files with 707 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
import { Injectable } from "@nestjs/common";
import { InjectModel } from "@nestjs/mongoose";
import { FilterQuery, Model, Types } from "mongoose";
import { CallCenterAgentModel } from "../schema/call-center-agent.schema";
@Injectable()
export class CallCenterAgentDbService {
constructor(
@InjectModel(CallCenterAgentModel.name)
private readonly model: Model<CallCenterAgentModel>,
) {}
async create(
data: Partial<CallCenterAgentModel> & { password: string },
): Promise<CallCenterAgentModel> {
return this.model.create(data);
}
async findOne(
filter: FilterQuery<CallCenterAgentModel>,
): Promise<CallCenterAgentModel | null> {
return this.model.findOne(filter);
}
async findById(id: string): Promise<CallCenterAgentModel | null> {
return this.model.findOne({ _id: new Types.ObjectId(id) });
}
async findByLoginIdentifier(
identifier: string,
): Promise<CallCenterAgentModel | null> {
const id = identifier.trim();
const or: FilterQuery<CallCenterAgentModel>[] = [
{ email: id },
{ username: id },
];
if (/^\d{10}$/.test(id)) {
or.push({ nationalCode: id });
}
return this.model.findOne({ $or: or });
}
async findAll(
filter: FilterQuery<CallCenterAgentModel>,
): Promise<(CallCenterAgentModel & { _id: Types.ObjectId })[]> {
return this.model.find(filter).lean() as Promise<
(CallCenterAgentModel & { _id: Types.ObjectId })[]
>;
}
}