2022-07-01 20:53:38 +00:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2022-07-01 22:27:19 +00:00
|
|
|
import { Comment, CommentDocument } from '../schemas/post-comment.schema';
|
|
|
|
import { Model } from 'mongoose';
|
|
|
|
import { InjectModel } from '@nestjs/mongoose';
|
|
|
|
|
2022-07-01 20:53:38 +00:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class PostCommentsService {
|
2022-07-01 22:27:19 +00:00
|
|
|
constructor(
|
|
|
|
@InjectModel(Comment.name) private readonly commentModel: Model<CommentDocument>,
|
|
|
|
) {}
|
|
|
|
|
|
|
|
async create(comment: CommentDocument): Promise<Comment> {
|
|
|
|
return this.commentModel.create(comment);
|
2022-07-01 20:53:38 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 22:27:19 +00:00
|
|
|
async findAll(): Promise<Comment[]> {
|
|
|
|
return this.commentModel
|
|
|
|
.find()
|
|
|
|
.setOptions({ sanitizeFilter: true })
|
|
|
|
.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
async findOne(id: string): Promise<Comment> {
|
|
|
|
return this.commentModel.findOne({ _id: id }).exec();
|
2022-07-01 20:53:38 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 22:27:19 +00:00
|
|
|
async findOneByDNI(dni: string): Promise<Comment> {
|
|
|
|
return this.commentModel.findOne({ dni: dni }).exec();
|
2022-07-01 20:53:38 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 22:27:19 +00:00
|
|
|
async update(id: string, comment: CommentDocument) {
|
|
|
|
return this.commentModel.findOneAndUpdate({ _id: id }, comment, {
|
|
|
|
new: true,
|
|
|
|
});
|
2022-07-01 20:53:38 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 22:27:19 +00:00
|
|
|
async remove(id: string) {
|
|
|
|
return this.commentModel.findByIdAndRemove({ _id: id }).exec();
|
2022-07-01 20:53:38 +00:00
|
|
|
}
|
|
|
|
}
|