@lookiero/checkout 0.2.42 → 0.2.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/domain/checkoutItem/command/replaceCheckoutItem.d.ts +14 -0
- package/dist/domain/checkoutItem/command/replaceCheckoutItem.js +7 -0
- package/dist/domain/checkoutItem/model/checkoutItem.d.ts +4 -1
- package/dist/domain/checkoutItem/model/checkoutItem.js +11 -1
- package/dist/domain/checkoutItem/model/checkoutItemReplaced.d.ts +13 -0
- package/dist/domain/checkoutItem/model/checkoutItemReplaced.js +4 -0
- package/dist/infrastructure/delivery/baseBootstrap.js +3 -1
- package/dist/infrastructure/domain/checkoutItem/model/httpCheckoutItems.js +3 -0
- package/dist/infrastructure/domain/checkoutItem/model/httpCheckoutItemsReplace.d.ts +5 -0
- package/dist/infrastructure/domain/checkoutItem/model/httpCheckoutItemsReplace.js +13 -0
- package/dist/infrastructure/domain/checkoutItem/react/useReplaceCheckoutItem.d.ts +16 -0
- package/dist/infrastructure/domain/checkoutItem/react/useReplaceCheckoutItem.js +13 -0
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Command } from "@lookiero/messaging";
|
|
2
|
+
declare const REPLACE_CHECKOUT_ITEM = "replace_checkout_item";
|
|
3
|
+
interface ReplaceCheckoutItemPayload {
|
|
4
|
+
readonly aggregateId: string;
|
|
5
|
+
readonly replacedFor: string;
|
|
6
|
+
}
|
|
7
|
+
interface ReplaceCheckoutItem extends Command<typeof REPLACE_CHECKOUT_ITEM>, ReplaceCheckoutItemPayload {
|
|
8
|
+
}
|
|
9
|
+
interface ReplaceCheckoutItemFunction {
|
|
10
|
+
(payload: ReplaceCheckoutItemPayload): ReplaceCheckoutItem;
|
|
11
|
+
}
|
|
12
|
+
declare const replaceCheckoutItem: ReplaceCheckoutItemFunction;
|
|
13
|
+
export type { ReplaceCheckoutItem };
|
|
14
|
+
export { REPLACE_CHECKOUT_ITEM, replaceCheckoutItem };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { command } from "@lookiero/messaging";
|
|
2
|
+
const REPLACE_CHECKOUT_ITEM = "replace_checkout_item";
|
|
3
|
+
const replaceCheckoutItem = ({ aggregateId, ...payload }) => ({
|
|
4
|
+
...command({ aggregateId, name: REPLACE_CHECKOUT_ITEM }),
|
|
5
|
+
...payload,
|
|
6
|
+
});
|
|
7
|
+
export { REPLACE_CHECKOUT_ITEM, replaceCheckoutItem };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AggregateRoot, CommandHandlerFunction } from "@lookiero/messaging";
|
|
2
2
|
import { KeepCheckoutItem } from "../command/keepCheckoutItem";
|
|
3
|
+
import { ReplaceCheckoutItem } from "../command/replaceCheckoutItem";
|
|
3
4
|
import { ReturnCheckoutItem } from "../command/returnCheckoutItem";
|
|
4
5
|
import { Feedbacks } from "./feedbacks";
|
|
5
6
|
import { Price } from "./price";
|
|
@@ -14,8 +15,10 @@ interface CheckoutItem extends AggregateRoot {
|
|
|
14
15
|
readonly status: CheckoutItemStatus;
|
|
15
16
|
readonly price: Price;
|
|
16
17
|
readonly feedbacks: Feedbacks;
|
|
18
|
+
readonly replacedFor?: string;
|
|
17
19
|
}
|
|
18
20
|
declare const keepCheckoutItemHandler: CommandHandlerFunction<KeepCheckoutItem, CheckoutItem>;
|
|
19
21
|
declare const returnCheckoutItemHandler: CommandHandlerFunction<ReturnCheckoutItem, CheckoutItem>;
|
|
22
|
+
declare const replaceCheckoutItemHandler: CommandHandlerFunction<ReplaceCheckoutItem, CheckoutItem>;
|
|
20
23
|
export type { CheckoutItem };
|
|
21
|
-
export { CheckoutItemStatus, keepCheckoutItemHandler, returnCheckoutItemHandler };
|
|
24
|
+
export { CheckoutItemStatus, keepCheckoutItemHandler, returnCheckoutItemHandler, replaceCheckoutItemHandler };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import invariant from "tiny-invariant";
|
|
2
2
|
import { checkoutItemKept } from "./checkoutItemKept";
|
|
3
|
+
import { checkoutItemReplaced } from "./checkoutItemReplaced";
|
|
3
4
|
import { checkoutItemReturned } from "./checkoutItemReturned";
|
|
4
5
|
var CheckoutItemStatus;
|
|
5
6
|
(function (CheckoutItemStatus) {
|
|
@@ -27,4 +28,13 @@ const returnCheckoutItemHandler = () => async ({ aggregateRoot, command }) => {
|
|
|
27
28
|
domainEvents: [checkoutItemReturned({ aggregateId })],
|
|
28
29
|
};
|
|
29
30
|
};
|
|
30
|
-
|
|
31
|
+
const replaceCheckoutItemHandler = () => async ({ aggregateRoot, command }) => {
|
|
32
|
+
const { aggregateId } = command;
|
|
33
|
+
invariant(aggregateRoot.status !== CheckoutItemStatus.REPLACED, "CheckoutItem is already replaced");
|
|
34
|
+
return {
|
|
35
|
+
...aggregateRoot,
|
|
36
|
+
status: CheckoutItemStatus.REPLACED,
|
|
37
|
+
domainEvents: [checkoutItemReplaced({ aggregateId })],
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export { CheckoutItemStatus, keepCheckoutItemHandler, returnCheckoutItemHandler, replaceCheckoutItemHandler };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DomainEvent } from "@lookiero/messaging";
|
|
2
|
+
declare const CHECKOUT_ITEM_REPLACED = "checkout_item_replaced";
|
|
3
|
+
interface CheckoutItemReplacedPayload {
|
|
4
|
+
readonly aggregateId: string;
|
|
5
|
+
}
|
|
6
|
+
interface CheckoutItemReplaced extends DomainEvent<typeof CHECKOUT_ITEM_REPLACED>, CheckoutItemReplacedPayload {
|
|
7
|
+
}
|
|
8
|
+
interface CheckoutItemReplacedFunction {
|
|
9
|
+
(payload: CheckoutItemReplacedPayload): CheckoutItemReplaced;
|
|
10
|
+
}
|
|
11
|
+
declare const checkoutItemReplaced: CheckoutItemReplacedFunction;
|
|
12
|
+
export type { CheckoutItemReplaced };
|
|
13
|
+
export { CHECKOUT_ITEM_REPLACED, checkoutItemReplaced };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { domainEvent } from "@lookiero/messaging";
|
|
2
|
+
const CHECKOUT_ITEM_REPLACED = "checkout_item_replaced";
|
|
3
|
+
const checkoutItemReplaced = ({ aggregateId }) => domainEvent({ aggregateId, name: CHECKOUT_ITEM_REPLACED });
|
|
4
|
+
export { CHECKOUT_ITEM_REPLACED, checkoutItemReplaced };
|
|
@@ -4,8 +4,9 @@ import { startCheckoutHandler } from "../../domain/checkout/model/checkout";
|
|
|
4
4
|
import { BOOK_CHECKOUT_BOOKING_FOR_CHECKOUT_ITEM } from "../../domain/checkoutBooking/command/bookCheckoutBookingForCheckoutItem";
|
|
5
5
|
import { bookCheckoutBookingForCheckoutItemHandler, } from "../../domain/checkoutBooking/model/checkoutBooking";
|
|
6
6
|
import { KEEP_CHECKOUT_ITEM } from "../../domain/checkoutItem/command/keepCheckoutItem";
|
|
7
|
+
import { REPLACE_CHECKOUT_ITEM } from "../../domain/checkoutItem/command/replaceCheckoutItem";
|
|
7
8
|
import { RETURN_CHECKOUT_ITEM } from "../../domain/checkoutItem/command/returnCheckoutItem";
|
|
8
|
-
import { keepCheckoutItemHandler, returnCheckoutItemHandler, } from "../../domain/checkoutItem/model/checkoutItem";
|
|
9
|
+
import { keepCheckoutItemHandler, replaceCheckoutItemHandler, returnCheckoutItemHandler, } from "../../domain/checkoutItem/model/checkoutItem";
|
|
9
10
|
import { UPDATE_UI_SETTING } from "../../domain/uiSetting/command/updateUiSetting";
|
|
10
11
|
import { updateUiSettingHandler } from "../../domain/uiSetting/model/uiSetting";
|
|
11
12
|
import { viewBookedSizeChangeProductsVariantsForCheckoutItemHandler, VIEW_BOOKED_SIZE_CHANGE_PRODUCT_VARIANTS_FOR_CHECKOUT_ITEM, } from "../../projection/bookedSizeChangeProductsVariants/viewBookedSizeChangeProductVariantsForCheckoutItem";
|
|
@@ -41,6 +42,7 @@ const baseBootstrap = ({ checkoutByIdView, firstAvailableCheckoutByCustomerIdVie
|
|
|
41
42
|
})
|
|
42
43
|
.command(KEEP_CHECKOUT_ITEM, keepCheckoutItemHandler)(getCheckoutItem, saveCheckoutItem, ...checkoutItemsDependencies)
|
|
43
44
|
.command(RETURN_CHECKOUT_ITEM, returnCheckoutItemHandler)(getCheckoutItem, saveCheckoutItem, ...checkoutItemsDependencies)
|
|
45
|
+
.command(REPLACE_CHECKOUT_ITEM, replaceCheckoutItemHandler)(getCheckoutItem, saveCheckoutItem, ...checkoutItemsDependencies)
|
|
44
46
|
.query(VIEW_BOOKED_SIZE_CHANGE_PRODUCT_VARIANTS_FOR_CHECKOUT_ITEM, viewBookedSizeChangeProductsVariantsForCheckoutItemHandler, {
|
|
45
47
|
view: bookedSizeChangeProductsVariantsForCheckoutItemView,
|
|
46
48
|
})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import invariant from "tiny-invariant";
|
|
2
2
|
import { viewCheckoutItemById, } from "../../../../projection/checkoutItem/viewCheckoutItemById";
|
|
3
3
|
import { httpCheckoutItemsKeep } from "./httpCheckoutItemsKeep";
|
|
4
|
+
import { httpCheckoutItemsReplace } from "./httpCheckoutItemsReplace";
|
|
4
5
|
import { httpCheckoutItemsReturn } from "./httpCheckoutItemsReturn";
|
|
5
6
|
const toDomain = (checkoutItem) => {
|
|
6
7
|
invariant(checkoutItem, "No checkoutItem found!");
|
|
@@ -9,6 +10,7 @@ const toDomain = (checkoutItem) => {
|
|
|
9
10
|
status: checkoutItem.status,
|
|
10
11
|
price: checkoutItem.price,
|
|
11
12
|
feedbacks: checkoutItem.feedback,
|
|
13
|
+
replacedFor: checkoutItem.replacedFor,
|
|
12
14
|
aggregateId: checkoutItem.id,
|
|
13
15
|
domainEvents: [],
|
|
14
16
|
};
|
|
@@ -18,6 +20,7 @@ const saveCheckoutItem = ({ httpPost }) => async (aggregateRoot) => {
|
|
|
18
20
|
await Promise.all([
|
|
19
21
|
httpCheckoutItemsKeep({ httpPost })(aggregateRoot),
|
|
20
22
|
httpCheckoutItemsReturn({ httpPost })(aggregateRoot),
|
|
23
|
+
httpCheckoutItemsReplace({ httpPost })(aggregateRoot),
|
|
21
24
|
]);
|
|
22
25
|
};
|
|
23
26
|
export { getCheckoutItem, saveCheckoutItem };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { HttpCheckoutItemsSaveFunction } from "./httpCheckoutItems";
|
|
2
|
+
interface HttpCheckoutItemsReplaceFunction extends HttpCheckoutItemsSaveFunction {
|
|
3
|
+
}
|
|
4
|
+
declare const httpCheckoutItemsReplace: HttpCheckoutItemsReplaceFunction;
|
|
5
|
+
export { httpCheckoutItemsReplace };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CHECKOUT_ITEM_REPLACED, } from "../../../../domain/checkoutItem/model/checkoutItemReplaced";
|
|
2
|
+
const isCheckoutItemReplaced = (event) => event.name === CHECKOUT_ITEM_REPLACED;
|
|
3
|
+
const httpCheckoutItemsReplace = ({ httpPost }) => async ({ aggregateId, replacedFor, domainEvents }) => {
|
|
4
|
+
const checkoutItemReplaced = domainEvents.find(isCheckoutItemReplaced);
|
|
5
|
+
if (!checkoutItemReplaced) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
await httpPost({
|
|
9
|
+
endpoint: "/replace-checkout-item",
|
|
10
|
+
body: { checkoutItemId: aggregateId, replacedFor },
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
export { httpCheckoutItemsReplace };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CommandStatus } from "@lookiero/messaging-react";
|
|
2
|
+
interface ReplaceCheckoutItemFunctionArgs {
|
|
3
|
+
readonly replacedFor: string;
|
|
4
|
+
}
|
|
5
|
+
interface ReplaceCheckoutItemFunction {
|
|
6
|
+
(args: ReplaceCheckoutItemFunctionArgs): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
interface UseReplaceCheckoutItemFunctionArgs {
|
|
9
|
+
readonly checkoutItemId: string;
|
|
10
|
+
}
|
|
11
|
+
declare type UseReplaceCheckoutItemResult = [replace: ReplaceCheckoutItemFunction, status: CommandStatus];
|
|
12
|
+
interface UseReplaceCheckoutItemFunction {
|
|
13
|
+
(args: UseReplaceCheckoutItemFunctionArgs): UseReplaceCheckoutItemResult;
|
|
14
|
+
}
|
|
15
|
+
declare const useReplaceCheckoutItem: UseReplaceCheckoutItemFunction;
|
|
16
|
+
export { useReplaceCheckoutItem };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useCommand } from "@lookiero/messaging-react";
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { replaceCheckoutItem } from "../../../../domain/checkoutItem/command/replaceCheckoutItem";
|
|
4
|
+
import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
|
|
5
|
+
const useReplaceCheckoutItem = ({ checkoutItemId }) => {
|
|
6
|
+
const [commandBus, status] = useCommand({ contextId: MESSAGING_CONTEXT_ID });
|
|
7
|
+
const replace = useCallback(({ replacedFor }) => commandBus(replaceCheckoutItem({
|
|
8
|
+
aggregateId: checkoutItemId,
|
|
9
|
+
replacedFor,
|
|
10
|
+
})), [checkoutItemId, commandBus]);
|
|
11
|
+
return [replace, status];
|
|
12
|
+
};
|
|
13
|
+
export { useReplaceCheckoutItem };
|