import { Injectable } from '@nestjs/common' ; import { ModelType , DocumentType } from '@typegoose/typegoose/lib/types' ; import { Types } from 'mongoose' ; import { InjectModel } from 'nestjs-typegoose' ; import { CreateReviewDto } from './dto/create-review.dto' ; import { ReviewModel } from './review.model' ; @ Injectable ( ) export class ReviewService { constructor ( @ InjectModel ( ReviewModel ) private readonly reviewModel ) { } async create ( dto ) { return this . reviewModel . create ( dto ) ; } async delete ( id ) { return this . reviewModel . findByIdAndDelete ( id ) . exec ( ) ; } async findByProductId ( productId ) { return this . reviewModel . find ( { productId : Types . ObjectId ( productId ) } ) . exec ( ) ; } async deleteByProductId ( productId ) { return this . reviewModel . deleteMany ( { productId : Types . ObjectId ( productId ) } ) . exec ( ) ; } }