From 6199b3a1e6022ec46e1b58ff182d74aa2f0e7498 Mon Sep 17 00:00:00 2001 From: bahram rajabi Date: Wed, 19 Jun 2024 00:59:17 +0330 Subject: [PATCH] add possible factor method --- .../product-comment.controller.ts | 8 ++++ .../product-comment.service.ts | 47 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/apps/e-commerce/src/product-comment/product-comment.controller.ts b/apps/e-commerce/src/product-comment/product-comment.controller.ts index 34fdd706..c94f9f92 100644 --- a/apps/e-commerce/src/product-comment/product-comment.controller.ts +++ b/apps/e-commerce/src/product-comment/product-comment.controller.ts @@ -38,6 +38,14 @@ export class ProductCommentController { // public url + @ApiOperation({ description: 'show all possible factors' }) + @Get('/possibleFactor/:productId') + @HttpCode(HttpStatus.OK) + async possibleFactors(@Param('id') productId: bigint) { + return await this.service.possibleFactors(productId); + } + + // public url @ApiOperation({ description: 'show all product comments' }) @Get('/product/:id') @ApiQuery({ diff --git a/apps/e-commerce/src/product-comment/product-comment.service.ts b/apps/e-commerce/src/product-comment/product-comment.service.ts index 8c4c80bd..1dbf439a 100644 --- a/apps/e-commerce/src/product-comment/product-comment.service.ts +++ b/apps/e-commerce/src/product-comment/product-comment.service.ts @@ -40,6 +40,53 @@ export class ProductCommentService { private readonly i18n: I18nService, ) {} + async possibleFactors(productId: bigint) { + const product = await this.productRepository.findOne( + new QueryOptionsBuilder() + .filter({ id: productId }) + .filter( + Sequelize.where( + Sequelize.fn('isnull', Sequelize.col('ECProduct.isDeleted'), 0), + { + [Op.eq]: 0, + }, + ), + ) + .filter({ publishStatusId: PublishStatusEnum.publish }) + .build(), + ); + if (!product) { + throw new NotFoundException( + this.i18n.t('core.not_found_id', { + lang: I18nContext.current().lang, + }), + ); + } + + let queryOptions = new QueryOptionsBuilder() + .filter({ entityTypeId: product.entityTypeId }) + .filter( + Sequelize.where( + Sequelize.fn( + 'isnull', + Sequelize.col('ECEntityTypeFactor.isDeleted'), + 0, + ), + { + [Op.eq]: 0, + }, + ), + ) + .build(); + + const count = await this.entityTypeFactorRepository.count(queryOptions); + const result = await this.entityTypeFactorRepository.findAll(queryOptions); + return { + result: result, + total: count, + }; + } + async findAll(productId: bigint, filter: ListFilter) { let queryBuilder = new QueryOptionsBuilder() .filter(