Skip to content

Commit

Permalink
add possible factor method
Browse files Browse the repository at this point in the history
  • Loading branch information
bahram1249 committed Jun 18, 2024
1 parent 4d496ab commit 6199b3a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
47 changes: 47 additions & 0 deletions apps/e-commerce/src/product-comment/product-comment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,53 @@ export class ProductCommentService {
private readonly i18n: I18nService<I18nTranslations>,
) {}

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(
Expand Down

0 comments on commit 6199b3a

Please sign in to comment.