@labdigital/commercetools-mock 2.62.1 → 2.64.0
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/index.d.mts +10 -1
- package/dist/index.mjs +123 -39
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/orderSearch.ts +40 -0
- package/src/repositories/cart/actions.ts +39 -11
- package/src/repositories/cart/helpers.ts +39 -4
- package/src/repositories/cart/index.test.ts +32 -0
- package/src/repositories/cart/index.ts +29 -8
- package/src/repositories/helpers.test.ts +113 -2
- package/src/repositories/helpers.ts +107 -17
- package/src/repositories/order/index.ts +22 -12
- package/src/repositories/shipping-method/helpers.ts +3 -3
- package/src/services/cart.test.ts +162 -0
- package/src/services/order.ts +9 -0
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import express from "express";
|
|
|
2
2
|
import * as msw0 from "msw";
|
|
3
3
|
import { SetupServer, SetupServerApi } from "msw/node";
|
|
4
4
|
import * as _commercetools_platform_sdk0 from "@commercetools/platform-sdk";
|
|
5
|
-
import { Address, AssociateRole, AssociateRoleDraft, AttributeGroup, AttributeGroupDraft, BaseResource, BusinessUnit, BusinessUnitDraft, Cart, CartDiscount, CartDiscountDraft, CartDraft, CartReference, Category, CategoryDraft, Channel, ChannelDraft, ChannelReference, ChannelResourceIdentifier, CustomObject, CustomObjectDraft, Customer, CustomerCreatePasswordResetToken, CustomerDraft, CustomerGroup, CustomerGroupDraft, CustomerResetPassword, CustomerToken, DiscountCode, DiscountCodeDraft, DiscountGroup, DiscountGroupDraft, Extension, ExtensionDraft, FacetResults, FilteredFacetResult, InventoryEntry, InventoryEntryDraft, LineItem, LineItemDraft, MyCustomerChangePassword, MyCustomerEmailVerify, MyCustomerResetPassword, MyOrderFromCartDraft, MyQuoteRequestDraft, Order, OrderEdit, OrderEditDraft, OrderFromCartDraft, OrderImportDraft, Payment, PaymentDraft, Product, ProductDiscount, ProductDiscountDraft, ProductDraft, ProductPagedSearchResponse, ProductProjection, ProductProjectionPagedSearchResponse, ProductSearchRequest, ProductSelection, ProductSelectionDraft, ProductTailoring, ProductType, ProductTypeDraft, Project, QueryParam, Quote, QuoteDraft, QuoteRequest, QuoteRequestDraft, RangeFacetResult, RecurrencePolicy, RecurrencePolicyDraft, RecurringOrder, RecurringOrderDraft, ResourceIdentifier, Review, ReviewDraft, ReviewRatingStatistics, ShippingInfo, ShippingMethod, ShippingMethodDraft, ShippingMethodReference, ShoppingList, ShoppingListDraft, ShoppingListLineItem, StagedQuote, StagedQuoteDraft, StandalonePrice, StandalonePriceDraft, State, StateDraft, Store, StoreDraft, StoreKeyReference, Subscription, SubscriptionDraft, TaxCategory, TaxCategoryDraft, TermFacetResult, Type, TypeDraft, UpdateAction, Zone, ZoneDraft, ZoneReference } from "@commercetools/platform-sdk";
|
|
5
|
+
import { Address, AssociateRole, AssociateRoleDraft, AttributeGroup, AttributeGroupDraft, BaseResource, BusinessUnit, BusinessUnitDraft, Cart, CartDiscount, CartDiscountDraft, CartDraft, CartReference, Category, CategoryDraft, Channel, ChannelDraft, ChannelReference, ChannelResourceIdentifier, CustomObject, CustomObjectDraft, Customer, CustomerCreatePasswordResetToken, CustomerDraft, CustomerGroup, CustomerGroupDraft, CustomerResetPassword, CustomerToken, DiscountCode, DiscountCodeDraft, DiscountGroup, DiscountGroupDraft, Extension, ExtensionDraft, FacetResults, FilteredFacetResult, InventoryEntry, InventoryEntryDraft, LineItem, LineItemDraft, MyCustomerChangePassword, MyCustomerEmailVerify, MyCustomerResetPassword, MyOrderFromCartDraft, MyQuoteRequestDraft, Order, OrderEdit, OrderEditDraft, OrderFromCartDraft, OrderImportDraft, OrderPagedSearchResponse, OrderSearchRequest, Payment, PaymentDraft, Product, ProductDiscount, ProductDiscountDraft, ProductDraft, ProductPagedSearchResponse, ProductProjection, ProductProjectionPagedSearchResponse, ProductSearchRequest, ProductSelection, ProductSelectionDraft, ProductTailoring, ProductType, ProductTypeDraft, Project, QueryParam, Quote, QuoteDraft, QuoteRequest, QuoteRequestDraft, RangeFacetResult, RecurrencePolicy, RecurrencePolicyDraft, RecurringOrder, RecurringOrderDraft, ResourceIdentifier, Review, ReviewDraft, ReviewRatingStatistics, ShippingInfo, ShippingMethod, ShippingMethodDraft, ShippingMethodReference, ShoppingList, ShoppingListDraft, ShoppingListLineItem, StagedQuote, StagedQuoteDraft, StandalonePrice, StandalonePriceDraft, State, StateDraft, Store, StoreDraft, StoreKeyReference, Subscription, SubscriptionDraft, TaxCategory, TaxCategoryDraft, TermFacetResult, Type, TypeDraft, UpdateAction, Zone, ZoneDraft, ZoneReference } from "@commercetools/platform-sdk";
|
|
6
6
|
|
|
7
7
|
//#region src/oauth/store.d.ts
|
|
8
8
|
type Token = {
|
|
@@ -94,8 +94,16 @@ declare class CartRepository extends AbstractResourceRepository<"cart"> {
|
|
|
94
94
|
createShippingInfo(context: RepositoryContext, resource: Writable<Cart>, shippingMethodRef: NonNullable<CartDraft["shippingMethod"]>): NonNullable<Cart["shippingInfo"]>;
|
|
95
95
|
}
|
|
96
96
|
//#endregion
|
|
97
|
+
//#region src/orderSearch.d.ts
|
|
98
|
+
declare class OrderSearch {
|
|
99
|
+
protected _storage: AbstractStorage;
|
|
100
|
+
constructor(config: Config);
|
|
101
|
+
search(projectKey: string, params: OrderSearchRequest): OrderPagedSearchResponse;
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
97
104
|
//#region src/repositories/order/index.d.ts
|
|
98
105
|
declare class OrderRepository extends AbstractResourceRepository<"order"> {
|
|
106
|
+
protected _searchService: OrderSearch;
|
|
99
107
|
constructor(config: Config);
|
|
100
108
|
create(context: RepositoryContext, draft: OrderFromCartDraft): Order;
|
|
101
109
|
createFromCart(context: RepositoryContext, cartReference: CartReference, orderNumber?: string): Order;
|
|
@@ -104,6 +112,7 @@ declare class OrderRepository extends AbstractResourceRepository<"order"> {
|
|
|
104
112
|
private customLineItemFromImportDraft;
|
|
105
113
|
getWithOrderNumber(context: RepositoryContext, orderNumber: string, params?: QueryParams$1): Order | undefined;
|
|
106
114
|
createShippingInfo(context: RepositoryContext, resource: Writable<Order>, shippingMethodRef: ShippingMethodReference): ShippingInfo;
|
|
115
|
+
search(context: RepositoryContext, searchRequest: OrderSearchRequest): OrderPagedSearchResponse;
|
|
107
116
|
}
|
|
108
117
|
//#endregion
|
|
109
118
|
//#region src/repositories/quote-request/index.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -551,18 +551,15 @@ const roundDecimal = (decimal, roundingMode) => {
|
|
|
551
551
|
default: throw new Error(`Unknown rounding mode: ${roundingMode}`);
|
|
552
552
|
}
|
|
553
553
|
};
|
|
554
|
-
const
|
|
555
|
-
|
|
556
|
-
switch (value.currencyCode.toUpperCase()) {
|
|
554
|
+
const getCurrencyFractionDigits = (currencyCode) => {
|
|
555
|
+
switch (currencyCode.toUpperCase()) {
|
|
557
556
|
case "BHD":
|
|
558
557
|
case "IQD":
|
|
559
558
|
case "JOD":
|
|
560
559
|
case "KWD":
|
|
561
560
|
case "LYD":
|
|
562
561
|
case "OMR":
|
|
563
|
-
case "TND":
|
|
564
|
-
fractionDigits = 3;
|
|
565
|
-
break;
|
|
562
|
+
case "TND": return 3;
|
|
566
563
|
case "CVE":
|
|
567
564
|
case "DJF":
|
|
568
565
|
case "GNF":
|
|
@@ -577,22 +574,49 @@ const createCentPrecisionMoney = (value) => {
|
|
|
577
574
|
case "VUV":
|
|
578
575
|
case "XAF":
|
|
579
576
|
case "XOF":
|
|
580
|
-
case "XPF":
|
|
581
|
-
|
|
582
|
-
break;
|
|
583
|
-
default: fractionDigits = 2;
|
|
577
|
+
case "XPF": return 0;
|
|
578
|
+
default: return 2;
|
|
584
579
|
}
|
|
585
|
-
|
|
580
|
+
};
|
|
581
|
+
const calculateCentAmountFromPreciseAmount = (preciseAmount, fractionDigits, currencyCode, roundingMode = "HalfEven") => {
|
|
582
|
+
const diff = fractionDigits - getCurrencyFractionDigits(currencyCode);
|
|
583
|
+
const scale = new Decimal(10).pow(Math.abs(diff));
|
|
584
|
+
return roundDecimal(diff >= 0 ? new Decimal(preciseAmount).div(scale) : new Decimal(preciseAmount).mul(scale), roundingMode).toNumber();
|
|
585
|
+
};
|
|
586
|
+
const createCentPrecisionMoney = (value) => {
|
|
587
|
+
const fractionDigits = getCurrencyFractionDigits(value.currencyCode);
|
|
588
|
+
const preciseValue = value;
|
|
589
|
+
let centAmount;
|
|
590
|
+
centAmount = value.centAmount ?? 0;
|
|
591
|
+
if (preciseValue.preciseAmount !== void 0 && preciseValue.fractionDigits !== void 0) centAmount = calculateCentAmountFromPreciseAmount(preciseValue.preciseAmount, preciseValue.fractionDigits, value.currencyCode, "HalfEven");
|
|
586
592
|
return {
|
|
587
593
|
type: "centPrecision",
|
|
588
|
-
centAmount
|
|
594
|
+
centAmount,
|
|
589
595
|
currencyCode: value.currencyCode,
|
|
590
596
|
fractionDigits
|
|
591
597
|
};
|
|
592
598
|
};
|
|
599
|
+
const createHighPrecisionMoney = (value) => {
|
|
600
|
+
if (value.preciseAmount === void 0) throw new Error("HighPrecisionMoney requires preciseAmount");
|
|
601
|
+
if (value.fractionDigits === void 0) throw new Error("HighPrecisionMoney requires fractionDigits");
|
|
602
|
+
return {
|
|
603
|
+
type: "highPrecision",
|
|
604
|
+
centAmount: value.centAmount ?? calculateCentAmountFromPreciseAmount(value.preciseAmount, value.fractionDigits, value.currencyCode, "HalfEven"),
|
|
605
|
+
currencyCode: value.currencyCode,
|
|
606
|
+
fractionDigits: value.fractionDigits,
|
|
607
|
+
preciseAmount: value.preciseAmount
|
|
608
|
+
};
|
|
609
|
+
};
|
|
593
610
|
const createTypedMoney = (value) => {
|
|
611
|
+
const preciseValue = value;
|
|
612
|
+
if ("type" in value && value.type === "highPrecision" || preciseValue.preciseAmount !== void 0) return createHighPrecisionMoney(value);
|
|
594
613
|
return createCentPrecisionMoney(value);
|
|
595
614
|
};
|
|
615
|
+
const calculateMoneyTotalCentAmount = (money, quantity, roundingMode = "HalfEven") => {
|
|
616
|
+
const preciseValue = money;
|
|
617
|
+
if (preciseValue.preciseAmount === void 0 || preciseValue.fractionDigits === void 0) return (money.centAmount ?? 0) * quantity;
|
|
618
|
+
return calculateCentAmountFromPreciseAmount(new Decimal(preciseValue.preciseAmount).mul(quantity).toNumber(), preciseValue.fractionDigits, money.currencyCode, roundingMode);
|
|
619
|
+
};
|
|
596
620
|
const resolveStoreReference = (ref, projectKey, storage) => {
|
|
597
621
|
if (!ref) return void 0;
|
|
598
622
|
const resource = storage.getByResourceIdentifier(projectKey, ref);
|
|
@@ -911,7 +935,10 @@ const selectPrice = ({ prices, currency, country }) => {
|
|
|
911
935
|
return countryMatch && currencyMatch;
|
|
912
936
|
});
|
|
913
937
|
};
|
|
914
|
-
const calculateLineItemTotalPrice = (lineItem) =>
|
|
938
|
+
const calculateLineItemTotalPrice = (lineItem) => {
|
|
939
|
+
if (!lineItem.price?.value) return 0;
|
|
940
|
+
return calculateMoneyTotalCentAmount(lineItem.price.value, lineItem.quantity);
|
|
941
|
+
};
|
|
915
942
|
const calculateCartTotalPrice = (cart) => {
|
|
916
943
|
return cart.lineItems.reduce((cur, item) => cur + item.totalPrice.centAmount, 0) + cart.customLineItems.reduce((cur, item) => cur + item.totalPrice.centAmount, 0);
|
|
917
944
|
};
|
|
@@ -923,8 +950,8 @@ const createCustomLineItemFromDraft = (projectKey, draft, storage, country) => {
|
|
|
923
950
|
taxCategory = storage.get(projectKey, "tax-category", taxCategoryRef.id, {}) || void 0;
|
|
924
951
|
} catch (_error) {}
|
|
925
952
|
const totalPrice = createCentPrecisionMoney({
|
|
926
|
-
|
|
927
|
-
centAmount: (draft.money
|
|
953
|
+
currencyCode: draft.money.currencyCode,
|
|
954
|
+
centAmount: calculateMoneyTotalCentAmount(draft.money, quantity)
|
|
928
955
|
});
|
|
929
956
|
const taxedPrice = taxCategory ? calculateTaxedPrice(totalPrice.centAmount, taxCategory, totalPrice.currencyCode, country) : void 0;
|
|
930
957
|
const taxRate = taxCategory ? taxCategory.rates.find((rate) => !rate.country || rate.country === country) : void 0;
|
|
@@ -947,6 +974,22 @@ const createCustomLineItemFromDraft = (projectKey, draft, storage, country) => {
|
|
|
947
974
|
taxedPricePortions: []
|
|
948
975
|
};
|
|
949
976
|
};
|
|
977
|
+
const createDiscountCodeInfoFromCode = (projectKey, storage, code) => {
|
|
978
|
+
const discountCodes = storage.query(projectKey, "discount-code", { where: `code="${code}"` });
|
|
979
|
+
if (discountCodes.count === 0) throw new CommercetoolsError({
|
|
980
|
+
code: "DiscountCodeNonApplicable",
|
|
981
|
+
message: `The discount code '${code}' was not found.`,
|
|
982
|
+
reason: "DoesNotExist",
|
|
983
|
+
discountCode: "nonexistent"
|
|
984
|
+
});
|
|
985
|
+
return {
|
|
986
|
+
discountCode: {
|
|
987
|
+
typeId: "discount-code",
|
|
988
|
+
id: discountCodes.results[0].id
|
|
989
|
+
},
|
|
990
|
+
state: "MatchesCart"
|
|
991
|
+
};
|
|
992
|
+
};
|
|
950
993
|
|
|
951
994
|
//#endregion
|
|
952
995
|
//#region src/repositories/cart/actions.ts
|
|
@@ -998,6 +1041,10 @@ var CartUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
998
1041
|
country: resource.country
|
|
999
1042
|
});
|
|
1000
1043
|
if (!price) throw new Error(`No valid price found for ${productId} for country ${resource.country} and currency ${currency}`);
|
|
1044
|
+
const totalPrice = createCentPrecisionMoney({
|
|
1045
|
+
currencyCode: price.value.currencyCode,
|
|
1046
|
+
centAmount: calculateMoneyTotalCentAmount(price.value, quantity)
|
|
1047
|
+
});
|
|
1001
1048
|
resource.lineItems.push({
|
|
1002
1049
|
id: v4(),
|
|
1003
1050
|
key,
|
|
@@ -1011,11 +1058,7 @@ var CartUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
1011
1058
|
price,
|
|
1012
1059
|
taxedPricePortions: [],
|
|
1013
1060
|
perMethodTaxRate: [],
|
|
1014
|
-
totalPrice
|
|
1015
|
-
...price.value,
|
|
1016
|
-
type: "centPrecision",
|
|
1017
|
-
centAmount: price.value.centAmount * quantity
|
|
1018
|
-
},
|
|
1061
|
+
totalPrice,
|
|
1019
1062
|
quantity,
|
|
1020
1063
|
discountedPricePerQuantity: [],
|
|
1021
1064
|
lineItemMode: "Standard",
|
|
@@ -1057,6 +1100,10 @@ var CartUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
1057
1100
|
resource.taxRoundingMode = taxRoundingMode;
|
|
1058
1101
|
}
|
|
1059
1102
|
recalculate() {}
|
|
1103
|
+
addDiscountCode(context, resource, { code }) {
|
|
1104
|
+
const info = createDiscountCodeInfoFromCode(context.projectKey, this._storage, code);
|
|
1105
|
+
if (!resource.discountCodes.map((dc) => dc.discountCode.id).includes(info.discountCode.id)) resource.discountCodes.push(info);
|
|
1106
|
+
}
|
|
1060
1107
|
removeDiscountCode(context, resource, { discountCode }) {
|
|
1061
1108
|
resource.discountCodes = resource.discountCodes.filter((code) => code.discountCode.id !== discountCode.id);
|
|
1062
1109
|
}
|
|
@@ -1126,8 +1173,8 @@ var CartUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
1126
1173
|
});
|
|
1127
1174
|
customLineItem$1.quantity = quantity;
|
|
1128
1175
|
customLineItem$1.totalPrice = createCentPrecisionMoney({
|
|
1129
|
-
|
|
1130
|
-
centAmount: (customLineItem$1.money
|
|
1176
|
+
currencyCode: customLineItem$1.money.currencyCode,
|
|
1177
|
+
centAmount: calculateMoneyTotalCentAmount(customLineItem$1.money, quantity)
|
|
1131
1178
|
});
|
|
1132
1179
|
};
|
|
1133
1180
|
if (customLineItemId) {
|
|
@@ -1149,8 +1196,8 @@ var CartUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
1149
1196
|
});
|
|
1150
1197
|
customLineItem$1.money = createTypedMoney(money);
|
|
1151
1198
|
customLineItem$1.totalPrice = createCentPrecisionMoney({
|
|
1152
|
-
|
|
1153
|
-
centAmount: (money
|
|
1199
|
+
currencyCode: money.currencyCode,
|
|
1200
|
+
centAmount: calculateMoneyTotalCentAmount(money, customLineItem$1.quantity)
|
|
1154
1201
|
});
|
|
1155
1202
|
};
|
|
1156
1203
|
if (customLineItemId) {
|
|
@@ -1207,7 +1254,7 @@ var CartUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
1207
1254
|
shippingMethodName,
|
|
1208
1255
|
price: createCentPrecisionMoney(shippingRate.price),
|
|
1209
1256
|
shippingRate: {
|
|
1210
|
-
price:
|
|
1257
|
+
price: createCentPrecisionMoney(shippingRate.price),
|
|
1211
1258
|
tiers: []
|
|
1212
1259
|
},
|
|
1213
1260
|
taxCategory: tax ? {
|
|
@@ -1293,7 +1340,7 @@ var CartUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
1293
1340
|
}
|
|
1294
1341
|
const lineItemTotal = calculateLineItemTotalPrice(lineItem);
|
|
1295
1342
|
lineItem.totalPrice = createCentPrecisionMoney({
|
|
1296
|
-
|
|
1343
|
+
currencyCode: lineItem.price.value.currencyCode,
|
|
1297
1344
|
centAmount: lineItemTotal
|
|
1298
1345
|
});
|
|
1299
1346
|
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
@@ -1384,6 +1431,10 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1384
1431
|
});
|
|
1385
1432
|
const lineItems = draft.lineItems?.map((draftLineItem) => this.draftLineItemtoLineItem(context.projectKey, draftLineItem, draft.currency, draft.country)) ?? [];
|
|
1386
1433
|
const customLineItems = draft.customLineItems?.map((draftCustomLineItem) => createCustomLineItemFromDraft(context.projectKey, draftCustomLineItem, this._storage, draft.shippingAddress?.country ?? draft.country)) ?? [];
|
|
1434
|
+
const discountCodeInfo = [];
|
|
1435
|
+
if (draft.discountCodes?.length) draft.discountCodes.forEach((code) => {
|
|
1436
|
+
discountCodeInfo.push(createDiscountCodeInfoFromCode(context.projectKey, this._storage, code));
|
|
1437
|
+
});
|
|
1387
1438
|
const resource = {
|
|
1388
1439
|
...getBaseResourceProperties(),
|
|
1389
1440
|
anonymousId: draft.anonymousId,
|
|
@@ -1398,7 +1449,7 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1398
1449
|
customerEmail: draft.customerEmail,
|
|
1399
1450
|
customLineItems,
|
|
1400
1451
|
directDiscounts: [],
|
|
1401
|
-
discountCodes:
|
|
1452
|
+
discountCodes: discountCodeInfo,
|
|
1402
1453
|
inventoryMode: "None",
|
|
1403
1454
|
itemShippingAddresses: [],
|
|
1404
1455
|
lineItems,
|
|
@@ -1464,6 +1515,10 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1464
1515
|
country
|
|
1465
1516
|
});
|
|
1466
1517
|
if (!price) throw new Error(`No valid price found for ${productId} for country ${country} and currency ${currency}`);
|
|
1518
|
+
const totalPrice = createCentPrecisionMoney({
|
|
1519
|
+
currencyCode: price.value.currencyCode,
|
|
1520
|
+
centAmount: calculateMoneyTotalCentAmount(price.value, quant)
|
|
1521
|
+
});
|
|
1467
1522
|
return {
|
|
1468
1523
|
id: v4(),
|
|
1469
1524
|
productId: product.id,
|
|
@@ -1473,12 +1528,7 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1473
1528
|
name: product.masterData.current.name,
|
|
1474
1529
|
variant,
|
|
1475
1530
|
price,
|
|
1476
|
-
totalPrice
|
|
1477
|
-
type: "centPrecision",
|
|
1478
|
-
currencyCode: price.value.currencyCode,
|
|
1479
|
-
fractionDigits: price.value.fractionDigits,
|
|
1480
|
-
centAmount: price.value.centAmount * quant
|
|
1481
|
-
},
|
|
1531
|
+
totalPrice,
|
|
1482
1532
|
taxedPricePortions: [],
|
|
1483
1533
|
perMethodTaxRate: [],
|
|
1484
1534
|
quantity: quant,
|
|
@@ -1501,6 +1551,30 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1501
1551
|
}
|
|
1502
1552
|
};
|
|
1503
1553
|
|
|
1554
|
+
//#endregion
|
|
1555
|
+
//#region src/orderSearch.ts
|
|
1556
|
+
var OrderSearch = class {
|
|
1557
|
+
_storage;
|
|
1558
|
+
constructor(config) {
|
|
1559
|
+
this._storage = config.storage;
|
|
1560
|
+
}
|
|
1561
|
+
search(projectKey, params) {
|
|
1562
|
+
const orderResources = this._storage.all(projectKey, "order");
|
|
1563
|
+
const offset = params.offset || 0;
|
|
1564
|
+
const limit = params.limit || 20;
|
|
1565
|
+
const results = orderResources.slice(offset, offset + limit).map((order) => ({
|
|
1566
|
+
id: order.id,
|
|
1567
|
+
version: order.version
|
|
1568
|
+
}));
|
|
1569
|
+
return {
|
|
1570
|
+
total: orderResources.length,
|
|
1571
|
+
offset,
|
|
1572
|
+
limit,
|
|
1573
|
+
hits: results
|
|
1574
|
+
};
|
|
1575
|
+
}
|
|
1576
|
+
};
|
|
1577
|
+
|
|
1504
1578
|
//#endregion
|
|
1505
1579
|
//#region src/repositories/order/actions.ts
|
|
1506
1580
|
var OrderUpdateHandler = class extends AbstractUpdateHandler {
|
|
@@ -1667,9 +1741,11 @@ var OrderUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
1667
1741
|
//#endregion
|
|
1668
1742
|
//#region src/repositories/order/index.ts
|
|
1669
1743
|
var OrderRepository = class extends AbstractResourceRepository {
|
|
1744
|
+
_searchService;
|
|
1670
1745
|
constructor(config) {
|
|
1671
1746
|
super("order", config);
|
|
1672
1747
|
this.actions = new OrderUpdateHandler(config.storage);
|
|
1748
|
+
this._searchService = new OrderSearch(config);
|
|
1673
1749
|
}
|
|
1674
1750
|
create(context, draft) {
|
|
1675
1751
|
assert(draft.cart, "draft.cart is missing");
|
|
@@ -1799,8 +1875,8 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
1799
1875
|
} else throw new Error("No product found");
|
|
1800
1876
|
const quantity = draft.quantity ?? 1;
|
|
1801
1877
|
const totalPrice = createCentPrecisionMoney({
|
|
1802
|
-
|
|
1803
|
-
centAmount: (draft.price.value
|
|
1878
|
+
currencyCode: draft.price.value.currencyCode,
|
|
1879
|
+
centAmount: calculateMoneyTotalCentAmount(draft.price.value, quantity)
|
|
1804
1880
|
});
|
|
1805
1881
|
return {
|
|
1806
1882
|
...getBaseResourceProperties(),
|
|
@@ -1830,8 +1906,8 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
1830
1906
|
customLineItemFromImportDraft(context, draft) {
|
|
1831
1907
|
const quantity = draft.quantity ?? 1;
|
|
1832
1908
|
const totalPrice = createCentPrecisionMoney({
|
|
1833
|
-
|
|
1834
|
-
centAmount: (draft.money
|
|
1909
|
+
currencyCode: draft.money.currencyCode,
|
|
1910
|
+
centAmount: calculateMoneyTotalCentAmount(draft.money, quantity)
|
|
1835
1911
|
});
|
|
1836
1912
|
return {
|
|
1837
1913
|
...getBaseResourceProperties(),
|
|
@@ -1881,6 +1957,9 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
1881
1957
|
deliveries: []
|
|
1882
1958
|
};
|
|
1883
1959
|
}
|
|
1960
|
+
search(context, searchRequest) {
|
|
1961
|
+
return this._searchService.search(context.projectKey, searchRequest);
|
|
1962
|
+
}
|
|
1884
1963
|
};
|
|
1885
1964
|
|
|
1886
1965
|
//#endregion
|
|
@@ -6308,8 +6387,8 @@ var ReviewUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
6308
6387
|
//#endregion
|
|
6309
6388
|
//#region src/repositories/shipping-method/helpers.ts
|
|
6310
6389
|
const transformShippingRate = (rate) => ({
|
|
6311
|
-
price:
|
|
6312
|
-
freeAbove: rate.freeAbove &&
|
|
6390
|
+
price: createCentPrecisionMoney(rate.price),
|
|
6391
|
+
freeAbove: rate.freeAbove && createCentPrecisionMoney(rate.freeAbove),
|
|
6313
6392
|
tiers: rate.tiers || []
|
|
6314
6393
|
});
|
|
6315
6394
|
|
|
@@ -7578,6 +7657,7 @@ var OrderService = class extends AbstractService {
|
|
|
7578
7657
|
}
|
|
7579
7658
|
extraRoutes(router) {
|
|
7580
7659
|
router.post("/import", this.import.bind(this));
|
|
7660
|
+
router.post("/search", this.search.bind(this));
|
|
7581
7661
|
router.get("/order-number=:orderNumber", this.getWithOrderNumber.bind(this));
|
|
7582
7662
|
}
|
|
7583
7663
|
import(request, response) {
|
|
@@ -7601,6 +7681,10 @@ var OrderService = class extends AbstractService {
|
|
|
7601
7681
|
}]
|
|
7602
7682
|
});
|
|
7603
7683
|
}
|
|
7684
|
+
search(request, response) {
|
|
7685
|
+
const resource = this.repository.search(getRepositoryContext(request), request.body);
|
|
7686
|
+
response.status(200).send(resource);
|
|
7687
|
+
}
|
|
7604
7688
|
};
|
|
7605
7689
|
|
|
7606
7690
|
//#endregion
|