-
Notifications
You must be signed in to change notification settings - Fork 14
/
Task04a_states.ts
38 lines (30 loc) · 1.1 KB
/
Task04a_states.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { StateDraft } from "@commercetools/platform-sdk";
import * as states from "./handson/states";
import { log } from "./utils/logger";
const orderPackedStateDraft: StateDraft = {
key: "tt-order-packed",
type: "OrderState",
name: {
de: "TT Order Packed ",
en: "TT Order Packed ",
},
initial: true,
};
const orderCompletedStateDraft: StateDraft = {
key: "tt-order-completed",
type: "OrderState",
name: {
de: "TT Order Completed ",
en: "TT Order Completed ",
},
initial: false,
};
const createStatesWithTransitions = async () => {
let orderPackedState = await states.createNewState(orderPackedStateDraft)
let orderCompletedState = await states.createNewState(orderCompletedStateDraft)
orderPackedState = await states.addTransition(orderPackedState.body.key, [orderCompletedState.body.key])
orderCompletedState = await states.addTransition(orderCompletedState.body.key, [])
return orderPackedState;
};
createStatesWithTransitions().then(log).catch(log)
// states.getStateByKey(orderPackedStateDraft.key).then(log).catch(log)