-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
661051c
commit de79137
Showing
14 changed files
with
266 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
apps/e-commerce/src/inventory-track-change/inventory-track-change.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { SequelizeModule } from '@nestjs/sequelize'; | ||
import { ECInventoryTrackChangeStatus } from '@rahino/database/models/ecommerce-eav/ec-inventory-track-change-status.entity'; | ||
import { ECInventory } from '@rahino/database/models/ecommerce-eav/ec-inventory.entity'; | ||
import { InventoryTrackChangeService } from './inventory-track-change.service'; | ||
|
||
@Module({ | ||
imports: [ | ||
SequelizeModule.forFeature([ECInventoryTrackChangeStatus, ECInventory]), | ||
], | ||
providers: [InventoryTrackChangeService], | ||
exports: [InventoryTrackChangeService], | ||
}) | ||
export class InventoryTrackChangeModule {} |
42 changes: 42 additions & 0 deletions
42
apps/e-commerce/src/inventory-track-change/inventory-track-change.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectModel } from '@nestjs/sequelize'; | ||
import { ECInventoryTrackChangeStatus } from '@rahino/database/models/ecommerce-eav/ec-inventory-track-change-status.entity'; | ||
import { InventoryTrackChangeStatusEnum } from '../util/enum'; | ||
import { Transaction } from 'sequelize'; | ||
import { ECInventory } from '@rahino/database/models/ecommerce-eav/ec-inventory.entity'; | ||
import { QueryOptionsBuilder } from '@rahino/query-filter/sequelize-query-builder'; | ||
|
||
@Injectable() | ||
export class InventoryTrackChangeService { | ||
constructor( | ||
@InjectModel(ECInventoryTrackChangeStatus) | ||
private readonly repository: typeof ECInventoryTrackChangeStatus, | ||
@InjectModel(ECInventory) | ||
private readonly inventoryRepository: typeof ECInventory, | ||
) {} | ||
|
||
async changeStatus( | ||
inventoryId: bigint, | ||
inventoryTrackChangeStatus: InventoryTrackChangeStatusEnum, | ||
qty: number, | ||
orderId?: bigint, | ||
transaction?: Transaction, | ||
) { | ||
const inventory = await this.inventoryRepository.findOne( | ||
new QueryOptionsBuilder().filter({ id: inventoryId }).build(), | ||
); | ||
|
||
await this.repository.create( | ||
{ | ||
inventoryId: inventory.id, | ||
productId: inventory.productId, | ||
qty: qty, | ||
inventoryTrackChangeStatusId: inventoryTrackChangeStatus, | ||
orderId: orderId, | ||
}, | ||
{ | ||
transaction: transaction, | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
apps/e-commerce/src/util/enum/inventory-track-change-status.enum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export enum InventoryTrackChangeStatusEnum { | ||
Create = 1, | ||
Update = 2, | ||
DecreaseQtyForOrderPurpose = 3, | ||
IncreaseQtyForOrderUnpaidOrder = 4, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.