forked from Yara724/api
Initial commit after migration to gitea
This commit is contained in:
56
src/client/client.service.ts
Normal file
56
src/client/client.service.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { BadGatewayException, GoneException, Injectable } from "@nestjs/common";
|
||||
import { Types } from "mongoose";
|
||||
import {
|
||||
ClientDto,
|
||||
ClientDtoRs,
|
||||
ClientLists,
|
||||
} from "src/client/dto/create-client.dto";
|
||||
import { ClientDbService } from "./entities/db-service/client.db.service";
|
||||
|
||||
@Injectable()
|
||||
export class ClientService {
|
||||
constructor(private readonly clientDbService: ClientDbService) {}
|
||||
async addClient(client: ClientDto): Promise<ClientDtoRs> {
|
||||
try {
|
||||
const newClient = await this.clientDbService.create({
|
||||
clientCode: client.clientCode,
|
||||
clientName: {
|
||||
persian: client.clientName.persian,
|
||||
english: client.clientName.english || null,
|
||||
},
|
||||
property: {
|
||||
smsApiKey: client.property.smsApiKey || null,
|
||||
},
|
||||
useExpertMode: client.useExpertMode || null,
|
||||
});
|
||||
if (newClient) return new ClientDtoRs(newClient);
|
||||
else throw new GoneException("database not connected");
|
||||
} catch (er) {
|
||||
throw new BadGatewayException(er.errors);
|
||||
}
|
||||
}
|
||||
|
||||
findOne(filter) {
|
||||
return this.clientDbService.findOne(filter);
|
||||
}
|
||||
|
||||
async findClientWithPersianName(filter: string) {
|
||||
return await this.clientDbService.find({ "clientName.persian": filter });
|
||||
}
|
||||
|
||||
async findClientWithCompanyCode(companyCode: number) {
|
||||
return await this.clientDbService.find({ clientCode: companyCode });
|
||||
}
|
||||
|
||||
async getClients(): Promise<ClientDtoRs[]> {
|
||||
const clients = await this.clientDbService.findAll();
|
||||
const show = clients.map((c) => new ClientDtoRs(c));
|
||||
return show;
|
||||
}
|
||||
|
||||
async getClientList(): Promise<ClientLists[]> {
|
||||
const client = await this.clientDbService.findAll();
|
||||
const list = client.map((element) => new ClientLists(element));
|
||||
return list;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user