import { Injectable } from '@nestjs/common'; import { Comment, CommentDocument } from '../schemas/post-comment.schema'; import { Model } from 'mongoose'; import { InjectModel } from '@nestjs/mongoose'; @Injectable() export class PostCommentsService { constructor( @InjectModel(Comment.name) private readonly commentModel: Model, ) {} async create(comment: CommentDocument): Promise { return this.commentModel.create(comment); } async findAll(): Promise { return this.commentModel.find().setOptions({ sanitizeFilter: true }).exec(); } async findOne(id: string): Promise { return this.commentModel.findOne({ _id: id }).exec(); } async findOneByDNI(dni: string): Promise { return this.commentModel.findOne({ dni: dni }).exec(); } async update(id: string, comment: CommentDocument) { return this.commentModel.findOneAndUpdate({ _id: id }, comment, { new: true, }); } async remove(id: string) { return this.commentModel.findOneAndUpdate({ _id: id }, {status: '-1'}, { new: true, }); } async findPostCommunity(id: string): Promise { console.log(id); return this.commentModel.find({community_id:id}).setOptions({ sanitizeFilter: true }).exec(); } }