feat(workflows): update product workflow (#4982)
**What** - added "update product" workflow Co-authored-by: Riqwan Thamir <5105988+riqwan@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||
|
||||
export class ScopeLevelUnique1697708391459 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`DROP INDEX "UQ_inventory_level_inventory_item_id_location_id"`
|
||||
)
|
||||
|
||||
await queryRunner.query(`
|
||||
CREATE UNIQUE INDEX "UQ_inventory_level_inventory_item_id_location_id" ON "inventory_level" ("inventory_item_id", "location_id") WHERE deleted_at IS NULL;
|
||||
`)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
CREATE UNIQUE INDEX "UQ_inventory_level_inventory_item_id_location_id" ON "inventory_level" ("inventory_item_id", "location_id");
|
||||
`)
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ export default class InventoryItemService {
|
||||
CREATED: "inventory-item.created",
|
||||
UPDATED: "inventory-item.updated",
|
||||
DELETED: "inventory-item.deleted",
|
||||
RESTORED: "inventory-item.restored",
|
||||
}
|
||||
|
||||
protected readonly manager_: EntityManager
|
||||
@@ -213,4 +214,27 @@ export default class InventoryItemService {
|
||||
ids: inventoryItemId,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @param inventoryItemId - The id of the inventory item to restore.
|
||||
* @param context
|
||||
*/
|
||||
@InjectEntityManager()
|
||||
async restore(
|
||||
inventoryItemId: string | string[],
|
||||
@MedusaContext() context: SharedContext = {}
|
||||
): Promise<void> {
|
||||
const manager = context.transactionManager!
|
||||
const itemRepository = manager.getRepository(InventoryItem)
|
||||
|
||||
const ids = Array.isArray(inventoryItemId)
|
||||
? inventoryItemId
|
||||
: [inventoryItemId]
|
||||
|
||||
await itemRepository.restore({ id: In(ids) })
|
||||
|
||||
await this.eventBusService_?.emit?.(InventoryItemService.Events.RESTORED, {
|
||||
ids: inventoryItemId,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ export default class InventoryLevelService {
|
||||
CREATED: "inventory-level.created",
|
||||
UPDATED: "inventory-level.updated",
|
||||
DELETED: "inventory-level.deleted",
|
||||
RESTORED: "inventory-level.restored",
|
||||
}
|
||||
|
||||
protected readonly manager_: EntityManager
|
||||
@@ -231,13 +232,37 @@ export default class InventoryLevelService {
|
||||
const manager = context.transactionManager!
|
||||
const levelRepository = manager.getRepository(InventoryLevel)
|
||||
|
||||
await levelRepository.delete({ inventory_item_id: In(ids) })
|
||||
await levelRepository.softDelete({ inventory_item_id: In(ids) })
|
||||
|
||||
await this.eventBusService_?.emit?.(InventoryLevelService.Events.DELETED, {
|
||||
inventory_item_id: inventoryItemId,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores inventory levels by inventory Item ID.
|
||||
* @param inventoryItemId - The ID or IDs of the inventory item to restore inventory levels for.
|
||||
* @param context
|
||||
*/
|
||||
@InjectEntityManager()
|
||||
async restoreByInventoryItemId(
|
||||
inventoryItemId: string | string[],
|
||||
@MedusaContext() context: SharedContext = {}
|
||||
): Promise<void> {
|
||||
const ids = Array.isArray(inventoryItemId)
|
||||
? inventoryItemId
|
||||
: [inventoryItemId]
|
||||
|
||||
const manager = context.transactionManager!
|
||||
const levelRepository = manager.getRepository(InventoryLevel)
|
||||
|
||||
await levelRepository.restore({ inventory_item_id: In(ids) })
|
||||
|
||||
await this.eventBusService_?.emit?.(InventoryLevelService.Events.RESTORED, {
|
||||
inventory_item_id: inventoryItemId,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an inventory level by ID.
|
||||
* @param inventoryLevelId - The ID or IDs of the inventory level to delete.
|
||||
@@ -255,7 +280,7 @@ export default class InventoryLevelService {
|
||||
const manager = context.transactionManager!
|
||||
const levelRepository = manager.getRepository(InventoryLevel)
|
||||
|
||||
await levelRepository.delete({ id: In(ids) })
|
||||
await levelRepository.softDelete({ id: In(ids) })
|
||||
|
||||
await this.eventBusService_?.emit?.(InventoryLevelService.Events.DELETED, {
|
||||
ids: inventoryLevelId,
|
||||
@@ -277,7 +302,7 @@ export default class InventoryLevelService {
|
||||
|
||||
const ids = Array.isArray(locationId) ? locationId : [locationId]
|
||||
|
||||
await levelRepository.delete({ location_id: In(ids) })
|
||||
await levelRepository.softDelete({ location_id: In(ids) })
|
||||
|
||||
await this.eventBusService_?.emit?.(InventoryLevelService.Events.DELETED, {
|
||||
location_ids: ids,
|
||||
|
||||
@@ -376,6 +376,27 @@ export default class InventoryService implements IInventoryService {
|
||||
return await this.inventoryItemService_.delete(inventoryItemId, context)
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore an inventory item and levels
|
||||
* @param inventoryItemId - the id of the inventory item to delete
|
||||
* @param context
|
||||
*/
|
||||
@InjectEntityManager(
|
||||
(target) =>
|
||||
target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED
|
||||
)
|
||||
async restoreInventoryItem(
|
||||
inventoryItemId: string | string[],
|
||||
@MedusaContext() context: SharedContext = {}
|
||||
): Promise<void> {
|
||||
await this.inventoryLevelService_.restoreByInventoryItemId(
|
||||
inventoryItemId,
|
||||
context
|
||||
)
|
||||
|
||||
return await this.inventoryItemService_.restore(inventoryItemId, context)
|
||||
}
|
||||
|
||||
@InjectEntityManager(
|
||||
(target) =>
|
||||
target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED
|
||||
|
||||
Reference in New Issue
Block a user