forked from Yara724/api
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { Injectable } from "@nestjs/common";
|
|
import { InjectModel } from "@nestjs/mongoose";
|
|
import { FilterQuery, Model, Types } from "mongoose";
|
|
import { RegistrarModel } from "../schema/registrar.schema";
|
|
|
|
@Injectable()
|
|
export class RegistrarDbService {
|
|
constructor(
|
|
@InjectModel(RegistrarModel.name)
|
|
private readonly registrarModel: Model<RegistrarModel>,
|
|
) {}
|
|
|
|
async create(
|
|
user: Partial<RegistrarModel> & { password: string },
|
|
): Promise<RegistrarModel> {
|
|
return this.registrarModel.create(user);
|
|
}
|
|
|
|
async findOne(
|
|
filter: FilterQuery<RegistrarModel>,
|
|
): Promise<RegistrarModel | null> {
|
|
return this.registrarModel.findOne(filter);
|
|
}
|
|
|
|
async findOneAndUpdate(
|
|
filter: FilterQuery<RegistrarModel>,
|
|
update: any,
|
|
): Promise<RegistrarModel | null> {
|
|
return this.registrarModel.findOneAndUpdate(filter, update, { new: true });
|
|
}
|
|
|
|
async updateOne(filter: FilterQuery<RegistrarModel>, update: any) {
|
|
return this.registrarModel.updateOne(filter, update);
|
|
}
|
|
|
|
async findById(userId: string): Promise<RegistrarModel | null> {
|
|
return this.registrarModel.findOne({ _id: new Types.ObjectId(userId) });
|
|
}
|
|
}
|
|
|