import { GraphQLPaths , TAuthRole , TPagedList , TProductReview } from '@cromwell/core' ; import { DeleteManyInput , PagedParamsInput , PagedProductReview , ProductReview , ProductReviewFilter , ProductReviewInput , ProductReviewRepository , } from '@cromwell/core-backend' ; import { Arg , Authorized , Int , Mutation , Query , Resolver } from 'type-graphql' ; import { getCustomRepository } from 'typeorm' ; import { resetAllPagesCache } from '../helpers/reset-page' ; import { serverFireAction } from '../helpers/server-fire-action' ; const getOneByIdPath = GraphQLPaths . ProductReview . getOneById ; const getManyPath = GraphQLPaths . ProductReview . getMany ; const createPath = GraphQLPaths . ProductReview . create ; const updatePath = GraphQLPaths . ProductReview . update ; const deletePath = GraphQLPaths . ProductReview . delete ; const deleteManyPath = GraphQLPaths . ProductReview . deleteMany ; const deleteManyFilteredPath = GraphQLPaths . ProductReview . deleteManyFiltered ; const getFilteredPath = GraphQLPaths . ProductReview . getFiltered ; @ Resolver ( ProductReview ) export class ProductReviewResolver { private repository = getCustomRepository ( ProductReviewRepository ) ; @ Query ( ( ) => PagedProductReview ) async [ getManyPath ] ( @ Arg ( "pagedParams" ) pagedParams ) { return await this . repository . getProductReviews ( pagedParams ) ; } @ Query ( ( ) => ProductReview ) async [ getOneByIdPath ] ( @ Arg ( "id" , ( ) => Int ) id ) { return await this . repository . getProductReview ( id ) ; } @ Authorized < TAuthRole > ( "administrator" ) @ Mutation ( ( ) => ProductReview ) async [ createPath ] ( @ Arg ( "data" ) data ) { const review = await this . repository . createProductReview ( data ) ; serverFireAction ( 'create_product_review' , review ) ; return review ; } @ Authorized < TAuthRole > ( "administrator" ) @ Mutation ( ( ) => ProductReview ) async [ updatePath ] ( @ Arg ( "id" , ( ) => Int ) id , @ Arg ( "data" ) data ) { const review = await this . repository . updateProductReview ( id , data ) ; serverFireAction ( 'update_product_review' , review ) ; resetAllPagesCache ( ) ; return review ; } @ Authorized < TAuthRole > ( "administrator" ) @ Mutation ( ( ) => Boolean ) async [ deletePath ] ( @ Arg ( "id" , ( ) => Int ) id ) { const review = await this . repository . deleteProductReview ( id ) ; serverFireAction ( 'delete_product_review' , { id } ) ; resetAllPagesCache ( ) ; return review ; } @ Authorized < TAuthRole > ( "administrator" ) @ Mutation ( ( ) => Boolean ) async [ deleteManyPath ] ( @ Arg ( "data" ) data ) { const res = await this . repository . deleteMany ( data ) ; resetAllPagesCache ( ) ; return res ; } @ Authorized < TAuthRole > ( "administrator" ) @ Mutation ( ( ) => Boolean ) async [ deleteManyFilteredPath ] ( @ Arg ( "input" ) input , @ Arg ( "filterParams" , { nullable : true } ) filterParams ? ) { const res = await this . repository . deleteManyFilteredProductReviews ( input , filterParams ) ; resetAllPagesCache ( ) ; return res ; } @ Query ( ( ) => PagedProductReview ) async [ getFilteredPath ] ( @ Arg ( "pagedParams" , { nullable : true } ) pagedParams ? , @ Arg ( "filterParams" , { nullable : true } ) filterParams ? ) { return this . repository . getFilteredProductReviews ( pagedParams , filterParams ) ; } }