import { Injectable } from '@nestjs/common' import { UpdateUserDto } from './dto/update-user.dto' import { InjectModel } from '@nestjs/mongoose' import { User } from 'src/schemas/user.schema' import { Model } from 'mongoose' @Injectable() export class UsersService { constructor(@InjectModel(User.name) private userModel: Model) {} async checkEmailExists(email: string) { const user = await this.userModel.findOne({ email }) if (user) return true return false } async findAll() { return await this.userModel.find({}) } async findOne(_id: string) { return await this.userModel.findById({ _id }) } async update(_id: string, updateUserDto: UpdateUserDto) { return await this.userModel.findOneAndUpdate({ _id }, updateUserDto) } async remove(_id: string) { return await this.userModel.deleteOne({ _id }) } }