import { Injectable } from "@nestjs/common" ; import { InjectModel } from "@nestjs/mongoose" ; import { FilterQuery , Model } from "mongoose" ; import { User , UserDocument } from "./schemas/user.schema" ; @ Injectable ( ) export class UsersRepository { constructor ( @ InjectModel ( User . name ) private userModel ) { } async findOne ( userFilterQuery ) { return this . userModel . findOne ( userFilterQuery ) ; } async find ( usersFilterQuery ) { return this . userModel . find ( usersFilterQuery ) ; } async create ( user ) { const newUser = new this . userModel ( user ) ; return newUser . save ( ) ; } async findOneAndUpdate ( userFilterQuery , user ) { return this . userModel . findOneAndUpdate ( userFilterQuery , user , { new : true } ) ; } }