forked from Yara724/api
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { Injectable } from "@nestjs/common";
|
|
import { InjectModel } from "@nestjs/mongoose";
|
|
import { FilterQuery, Model, UpdateQuery } 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();
|
|
}
|
|
|
|
async findByIdAndUpdate(
|
|
id: string,
|
|
update: UpdateQuery<ClientModel>,
|
|
): Promise<ClientModel | null> {
|
|
return this.clientModel
|
|
.findByIdAndUpdate(id, update, { new: true })
|
|
.lean()
|
|
.exec();
|
|
}
|
|
}
|