Skip to content

Commit

Permalink
fix discount
Browse files Browse the repository at this point in the history
  • Loading branch information
bahram1249 committed May 21, 2024
1 parent caf9501 commit 5986b23
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,28 @@ export class ProductDiscountSetterService {
) {
return await this.discountRepository.findAll(
new QueryOptionsBuilder()
.attributes([
'id',
'name',
'description',
'discountTypeId',
'discountActionTypeId',
'discountValue',
'maxValue',
'discountActionRuleId',
'userId',
'priority',
'limit',
'used',
'isActive',
'isDeleted',
'startDate',
'endDate',
'couponCode',
'freeShipment',
'createdAt',
'updatedAt',
])
.include([
{
model: ECDiscountCondition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export class ProductDiscountService {
_.merge(filter, { inventoryStatusId: InventoryStatusEnum.available }),
);
let results = await this.repository.findAll(resultQuery);
await this.productDiscountSetterService.applyProducts(results);
const total = await this.repository.count(countQuery);
await this.productDiscountSetterService.applyProducts(results);
if (filter.limit + filter.offset >= total) {
more = false;
}
Expand Down
52 changes: 49 additions & 3 deletions apps/e-commerce/src/product/service/apply-discount.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,47 @@ export class ApplyDiscountService {
) {
return await this.repository.findAll(
new QueryOptionsBuilder()
.attributes([
'id',
'name',
'description',
'discountTypeId',
'discountActionTypeId',
'discountValue',
'maxValue',
'discountActionRuleId',
'userId',
'priority',
'limit',
'used',
'isActive',
'isDeleted',
[
Sequelize.fn(
'isnull',
Sequelize.col('ECDiscount.startDate'),
Sequelize.fn('getdate'),
),
'startDate',
],
[
Sequelize.fn(
'isnull',
Sequelize.col('ECDiscount.endDate'),
Sequelize.fn(
'dateadd',
Sequelize.literal('day'),
Sequelize.literal('1'),
Sequelize.fn('getdate'),
),
),
'endDate',
],
'couponCode',
'freeShipment',
'createdAt',
'updatedAt',
])
.include([
{
model: ECDiscountCondition,
Expand All @@ -442,9 +483,14 @@ export class ApplyDiscountService {
Sequelize.where(Sequelize.fn('getdate'), {
[Op.between]: [
Sequelize.fn(
'isnull',
Sequelize.col('ECDiscount.startDate'),
Sequelize.fn('getdate'),
'dateadd',
Sequelize.literal('minute'),
Sequelize.literal('-16'),
Sequelize.fn(
'isnull',
Sequelize.col('ECDiscount.startDate'),
Sequelize.fn('getdate'),
),
),
Sequelize.fn(
'isnull',
Expand Down

0 comments on commit 5986b23

Please sign in to comment.