|
1
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"; |
|
2
|
import { PluginModule } from "../../../types"; |
|
3
|
|
|
4
|
/** |
|
5
|
* Input to delete gift cards by their IDs. |
|
6
|
*/ |
|
7
|
export interface DeleteGiftCardsStepInput { |
|
8
|
/** |
|
9
|
* The IDs of the gift cards to delete. |
|
10
|
*/ |
|
11
|
id: string[] |
|
12
|
} |
|
13
|
|
|
14
|
/** |
|
15
|
* This step deletes gift cards by their IDs. The step supports rollback by |
|
16
|
* restoring the deleted gift cards. |
|
17
|
* |
|
18
|
* @example |
|
19
|
* const data = deleteGiftCardsStep({ id: ["gc_123"] }) |
|
20
|
*/ |
|
21
|
export const deleteGiftCardsStep = createStep( |
|
22
|
"delete-gift-cards", |
|
23
|
async function ({ id }: DeleteGiftCardsStepInput, { container }) { |
|
24
|
const module = container.resolve<any>(PluginModule.STORE_CREDIT); |
|
25
|
|
|
26
|
await module.deleteGiftCards({ id }); |
|
27
|
|
|
28
|
return new StepResponse(id, id); |
|
29
|
}, |
|
30
|
async (id, { container }) => { |
|
31
|
if (!id?.length) { |
|
32
|
return; |
|
33
|
} |
|
34
|
|
|
35
|
const module = container.resolve<any>(PluginModule.STORE_CREDIT); |
|
36
|
|
|
37
|
await module.restoreGiftCards({ id }); |
|
38
|
} |
|
39
|
); |