import { Injectable } from '@nestjs/common' ; import { InjectConnection } from '@nestjs/typeorm' ; import { Connection } from 'typeorm' ; import { IPaginationOptions , paginate , Pagination } from '../../common/paginate' ; import { ID } from '../../common/shared-types' ; import { formatAllMeta , formatOneMeta } from '../../common/utils' ; import { Comment } from '../../entity' ; @ Injectable ( ) export class CommentService { constructor ( @ InjectConnection ( ) private connection ) { } param options async paginate ( options ) { const paginationObj = await paginate < Comment > ( this . connection . getRepository ( Comment ) , options , { relations : [ 'user' ] , loadRelationIds : { relations : [ 'post' ] , } , } ) ; formatAllMeta ( paginationObj . items , { filterKey : 'user' , cleanMeta : true , } ) ; return paginationObj ; } param id async findById ( id ) { const data = await this . connection . getRepository ( Comment ) . findOne ( { relations : [ 'user' ] , where : { id , } , } ) ; formatOneMeta ( data , { filterKey : 'user' , cleanMeta : true , } ) ; return data ; } param comment async create ( comment ) { const data = await this . connection . getRepository ( Comment ) . save ( comment ) ; formatOneMeta ( data ) ; return data ; } }