@unchainedshop/api 3.0.0-rc6 → 3.0.0-rc7
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/lib/api-index.d.ts +1 -1
- package/lib/api-index.d.ts.map +1 -1
- package/lib/api-index.js +1 -1
- package/lib/api-index.js.map +1 -1
- package/lib/context.d.ts +0 -1
- package/lib/context.d.ts.map +1 -1
- package/lib/context.js +4 -19
- package/lib/context.js.map +1 -1
- package/lib/express/createBulkImportMiddleware.d.ts +1 -2
- package/lib/express/createBulkImportMiddleware.d.ts.map +1 -1
- package/lib/express/createBulkImportMiddleware.js.map +1 -1
- package/lib/express/createERCMetadataMiddleware.js +1 -1
- package/lib/express/createERCMetadataMiddleware.js.map +1 -1
- package/lib/express/index.d.ts.map +1 -1
- package/lib/express/index.js.map +1 -1
- package/lib/fastify/index.d.ts.map +1 -1
- package/lib/fastify/index.js.map +1 -1
- package/lib/resolvers/mutations/orders/addCartDiscount.d.ts.map +1 -1
- package/lib/resolvers/mutations/orders/addCartDiscount.js +8 -3
- package/lib/resolvers/mutations/orders/addCartDiscount.js.map +1 -1
- package/lib/resolvers/mutations/orders/addCartProduct.d.ts.map +1 -1
- package/lib/resolvers/mutations/orders/addCartProduct.js +8 -3
- package/lib/resolvers/mutations/orders/addCartProduct.js.map +1 -1
- package/lib/resolvers/mutations/orders/addCartQuotation.d.ts.map +1 -1
- package/lib/resolvers/mutations/orders/addCartQuotation.js +8 -3
- package/lib/resolvers/mutations/orders/addCartQuotation.js.map +1 -1
- package/lib/resolvers/mutations/orders/addMultipleCartProducts.d.ts.map +1 -1
- package/lib/resolvers/mutations/orders/addMultipleCartProducts.js +8 -3
- package/lib/resolvers/mutations/orders/addMultipleCartProducts.js.map +1 -1
- package/lib/resolvers/mutations/orders/checkoutCart.d.ts.map +1 -1
- package/lib/resolvers/mutations/orders/checkoutCart.js +10 -5
- package/lib/resolvers/mutations/orders/checkoutCart.js.map +1 -1
- package/lib/resolvers/mutations/orders/emptyCart.d.ts.map +1 -1
- package/lib/resolvers/mutations/orders/emptyCart.js +8 -3
- package/lib/resolvers/mutations/orders/emptyCart.js.map +1 -1
- package/lib/resolvers/mutations/orders/signPaymentProviderForCheckout.js +1 -1
- package/lib/resolvers/mutations/orders/signPaymentProviderForCheckout.js.map +1 -1
- package/lib/resolvers/mutations/orders/updateCart.d.ts.map +1 -1
- package/lib/resolvers/mutations/orders/updateCart.js +8 -3
- package/lib/resolvers/mutations/orders/updateCart.js.map +1 -1
- package/lib/resolvers/type/filter/loaded-filter-types.d.ts.map +1 -1
- package/lib/resolvers/type/filter/loaded-filter-types.js +1 -2
- package/lib/resolvers/type/filter/loaded-filter-types.js.map +1 -1
- package/lib/resolvers/type/index.d.ts +0 -3
- package/lib/resolvers/type/index.d.ts.map +1 -1
- package/lib/resolvers/type/product/product-configurable-types.d.ts.map +1 -1
- package/lib/resolvers/type/product/product-configurable-types.js +3 -5
- package/lib/resolvers/type/product/product-configurable-types.js.map +1 -1
- package/lib/resolvers/type/product/product-plan-types.d.ts.map +1 -1
- package/lib/resolvers/type/product/product-plan-types.js +3 -5
- package/lib/resolvers/type/product/product-plan-types.js.map +1 -1
- package/lib/resolvers/type/product/product-simple-types.d.ts +0 -2
- package/lib/resolvers/type/product/product-simple-types.d.ts.map +1 -1
- package/lib/resolvers/type/product/product-simple-types.js +13 -50
- package/lib/resolvers/type/product/product-simple-types.js.map +1 -1
- package/lib/resolvers/type/product/product-tokenized-types.d.ts +0 -1
- package/lib/resolvers/type/product/product-tokenized-types.d.ts.map +1 -1
- package/lib/resolvers/type/product/product-tokenized-types.js +5 -23
- package/lib/resolvers/type/product/product-tokenized-types.js.map +1 -1
- package/lib/resolvers/type/user-types.d.ts.map +1 -1
- package/lib/resolvers/type/user-types.js +2 -2
- package/lib/resolvers/type/user-types.js.map +1 -1
- package/package.json +10 -7
- package/src/api-index.ts +1 -1
- package/src/context.ts +4 -20
- package/src/express/createBulkImportMiddleware.ts +1 -2
- package/src/express/createERCMetadataMiddleware.ts +1 -1
- package/src/express/index.ts +1 -2
- package/src/fastify/index.ts +2 -3
- package/src/resolvers/mutations/orders/addCartDiscount.ts +7 -2
- package/src/resolvers/mutations/orders/addCartProduct.ts +8 -2
- package/src/resolvers/mutations/orders/addCartQuotation.ts +7 -2
- package/src/resolvers/mutations/orders/addMultipleCartProducts.ts +7 -2
- package/src/resolvers/mutations/orders/checkoutCart.ts +9 -5
- package/src/resolvers/mutations/orders/emptyCart.ts +7 -3
- package/src/resolvers/mutations/orders/signPaymentProviderForCheckout.ts +1 -1
- package/src/resolvers/mutations/orders/updateCart.ts +7 -3
- package/src/resolvers/type/filter/loaded-filter-types.ts +1 -2
- package/src/resolvers/type/product/product-configurable-types.ts +3 -10
- package/src/resolvers/type/product/product-plan-types.ts +3 -7
- package/src/resolvers/type/product/product-simple-types.ts +14 -74
- package/src/resolvers/type/product/product-tokenized-types.ts +5 -35
- package/src/resolvers/type/user-types.ts +4 -2
- package/tests/api-index.test.ts +4 -4
- package/lib/resolvers/mutations/utils/getOrderCart.d.ts +0 -7
- package/lib/resolvers/mutations/utils/getOrderCart.d.ts.map +0 -1
- package/lib/resolvers/mutations/utils/getOrderCart.js +0 -17
- package/lib/resolvers/mutations/utils/getOrderCart.js.map +0 -1
- package/src/resolvers/mutations/utils/getOrderCart.ts +0 -20
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
ProductNotFoundError,
|
|
5
5
|
OrderQuantityTooLowError,
|
|
6
6
|
OrderWrongStatusError,
|
|
7
|
+
OrderNotFoundError,
|
|
7
8
|
} from '../../../errors.js';
|
|
8
|
-
import { getOrderCart } from '../utils/getOrderCart.js';
|
|
9
9
|
import { ordersSettings } from '@unchainedshop/core-orders';
|
|
10
10
|
|
|
11
11
|
export default async function addMultipleCartProducts(
|
|
@@ -41,7 +41,12 @@ export default async function addMultipleCartProducts(
|
|
|
41
41
|
}),
|
|
42
42
|
);
|
|
43
43
|
|
|
44
|
-
const order = await
|
|
44
|
+
const order = await services.orders.findOrInitCart({
|
|
45
|
+
orderId,
|
|
46
|
+
user,
|
|
47
|
+
countryCode: context.countryContext,
|
|
48
|
+
});
|
|
49
|
+
if (!order) throw new OrderNotFoundError({ orderId });
|
|
45
50
|
if (!modules.orders.isCart(order)) throw new OrderWrongStatusError({ status: order.status });
|
|
46
51
|
|
|
47
52
|
// Reduce is used to wait for each product to be added before processing the next (sequential processing)
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Context } from '../../../context.js';
|
|
2
|
-
import { OrderCheckoutError } from '../../../errors.js';
|
|
3
|
-
import { getOrderCart } from '../utils/getOrderCart.js';
|
|
2
|
+
import { OrderCheckoutError, OrderNotFoundError } from '../../../errors.js';
|
|
4
3
|
import { createLogger, log } from '@unchainedshop/logger';
|
|
5
4
|
|
|
6
5
|
const logger = createLogger('unchained:api');
|
|
@@ -20,11 +19,16 @@ export default async function checkoutCart(
|
|
|
20
19
|
log('mutation checkoutCart', { orderId: forceOrderId, userId });
|
|
21
20
|
|
|
22
21
|
// Do not check for order status here! The checkout method will act accordingly
|
|
23
|
-
|
|
22
|
+
const order = await services.orders.findOrInitCart({
|
|
23
|
+
orderId: forceOrderId,
|
|
24
|
+
user,
|
|
25
|
+
countryCode: context.countryContext,
|
|
26
|
+
});
|
|
27
|
+
if (!order) throw new OrderNotFoundError({ orderId: forceOrderId });
|
|
24
28
|
|
|
25
29
|
try {
|
|
26
|
-
|
|
27
|
-
return
|
|
30
|
+
const checkedOutOrder = await services.orders.checkoutOrder(order._id, transactionContext);
|
|
31
|
+
return checkedOutOrder;
|
|
28
32
|
} catch (error) {
|
|
29
33
|
logger.error(error.message, { userId, orderId: order._id });
|
|
30
34
|
throw new OrderCheckoutError({
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { log } from '@unchainedshop/logger';
|
|
2
2
|
import { Context } from '../../../context.js';
|
|
3
|
-
import {
|
|
4
|
-
import { OrderWrongStatusError } from '../../../errors.js';
|
|
3
|
+
import { OrderNotFoundError, OrderWrongStatusError } from '../../../errors.js';
|
|
5
4
|
|
|
6
5
|
export default async function emptyCart(
|
|
7
6
|
root: never,
|
|
@@ -12,7 +11,12 @@ export default async function emptyCart(
|
|
|
12
11
|
|
|
13
12
|
log('mutation emptyCart', { userId, orderId });
|
|
14
13
|
|
|
15
|
-
const order = await
|
|
14
|
+
const order = await services.orders.findOrInitCart({
|
|
15
|
+
orderId,
|
|
16
|
+
user,
|
|
17
|
+
countryCode: context.countryContext,
|
|
18
|
+
});
|
|
19
|
+
if (!order) throw new OrderNotFoundError({ orderId });
|
|
16
20
|
if (!modules.orders.isCart(order)) throw new OrderWrongStatusError({ status: order.status });
|
|
17
21
|
|
|
18
22
|
if (!order) return null;
|
|
@@ -32,7 +32,7 @@ export default async function signPaymentProviderForCheckout(
|
|
|
32
32
|
if (!orderPayment) throw new OrderPaymentNotFoundError({ orderPaymentId });
|
|
33
33
|
} else {
|
|
34
34
|
const order = await modules.orders.cart({
|
|
35
|
-
|
|
35
|
+
countryCode: context.countryContext,
|
|
36
36
|
userId,
|
|
37
37
|
});
|
|
38
38
|
if (!order) throw new UserNoCartError({ userId });
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { log } from '@unchainedshop/logger';
|
|
2
2
|
import { Context } from '../../../context.js';
|
|
3
|
-
import {
|
|
4
|
-
import { OrderWrongStatusError } from '../../../errors.js';
|
|
3
|
+
import { OrderNotFoundError, OrderWrongStatusError } from '../../../errors.js';
|
|
5
4
|
import { Address, Contact } from '@unchainedshop/mongodb';
|
|
6
5
|
|
|
7
6
|
interface UpdateCartParams {
|
|
@@ -20,7 +19,12 @@ export default async function updateCart(root: never, params: UpdateCartParams,
|
|
|
20
19
|
|
|
21
20
|
log('mutation updateCart', { userId });
|
|
22
21
|
|
|
23
|
-
let order = await
|
|
22
|
+
let order = await services.orders.findOrInitCart({
|
|
23
|
+
orderId,
|
|
24
|
+
user,
|
|
25
|
+
countryCode: context.countryContext,
|
|
26
|
+
});
|
|
27
|
+
if (!order) throw new OrderNotFoundError({ orderId });
|
|
24
28
|
if (!modules.orders.isCart(order)) throw new OrderWrongStatusError({ status: order.status });
|
|
25
29
|
|
|
26
30
|
if (meta) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Context } from '../../../context.js';
|
|
2
2
|
import { Filter, SearchQuery } from '@unchainedshop/core-filters';
|
|
3
3
|
import { FilterDirector } from '@unchainedshop/core';
|
|
4
|
-
import { intersectSet } from '@unchainedshop/utils';
|
|
5
4
|
|
|
6
5
|
type LoadedFilterData = {
|
|
7
6
|
forceLiveCollection: boolean;
|
|
@@ -26,7 +25,7 @@ export const LoadedFilter = {
|
|
|
26
25
|
) => {
|
|
27
26
|
const filterActions = await FilterDirector.actions({ searchQuery }, context);
|
|
28
27
|
return filterActions.aggregateProductIds({
|
|
29
|
-
productIds: Array.from(
|
|
28
|
+
productIds: Array.from(filteredByOtherFiltersSet.intersection(filteredByThisFilterSet)),
|
|
30
29
|
}).length;
|
|
31
30
|
},
|
|
32
31
|
productsCount: async (
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
import { Context } from '../../../context.js';
|
|
9
9
|
import { Product } from './product-types.js';
|
|
10
10
|
import { sha256 } from '@unchainedshop/utils';
|
|
11
|
-
import { ProductPricingDirector } from '@unchainedshop/core';
|
|
12
11
|
|
|
13
12
|
export const ConfigurableProduct = {
|
|
14
13
|
...Product,
|
|
@@ -105,7 +104,7 @@ export const ConfigurableProduct = {
|
|
|
105
104
|
},
|
|
106
105
|
requestContext: Context,
|
|
107
106
|
): Promise<ProductPriceRange> {
|
|
108
|
-
const { countryContext, modules } = requestContext;
|
|
107
|
+
const { countryContext, modules, services } = requestContext;
|
|
109
108
|
const currency = forcedCurrencyCode || requestContext.currencyContext;
|
|
110
109
|
|
|
111
110
|
const products = await modules.products.proxyProducts(product, vectors, {
|
|
@@ -123,14 +122,8 @@ export const ConfigurableProduct = {
|
|
|
123
122
|
quantity,
|
|
124
123
|
};
|
|
125
124
|
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
requestContext,
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
if (!calculated || !calculated.length) return null;
|
|
132
|
-
|
|
133
|
-
const pricing = ProductPricingDirector.calculationSheet(pricingContext, calculated);
|
|
125
|
+
const pricing = await services.products.simulateProductPricing(pricingContext);
|
|
126
|
+
if (!pricing) return null;
|
|
134
127
|
const unitPrice = pricing.unitPrice({ useNetPrice });
|
|
135
128
|
|
|
136
129
|
return {
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
} from '@unchainedshop/core-products';
|
|
6
6
|
import { Context } from '../../../context.js';
|
|
7
7
|
import { Product } from './product-types.js';
|
|
8
|
-
import { ProductPricingDirector } from '@unchainedshop/core';
|
|
9
8
|
import { sha256 } from '@unchainedshop/utils';
|
|
10
9
|
|
|
11
10
|
export const PlanProduct = {
|
|
@@ -40,7 +39,7 @@ export const PlanProduct = {
|
|
|
40
39
|
},
|
|
41
40
|
requestContext: Context,
|
|
42
41
|
): Promise<ProductPrice> {
|
|
43
|
-
const { countryContext, user } = requestContext;
|
|
42
|
+
const { countryContext, user, services } = requestContext;
|
|
44
43
|
const currency = forcedCurrencyCode || requestContext.currencyContext;
|
|
45
44
|
|
|
46
45
|
const pricingContext = {
|
|
@@ -52,11 +51,8 @@ export const PlanProduct = {
|
|
|
52
51
|
configuration,
|
|
53
52
|
};
|
|
54
53
|
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
if (!calculated || !calculated.length) return null;
|
|
58
|
-
|
|
59
|
-
const pricing = ProductPricingDirector.calculationSheet(pricingContext, calculated);
|
|
54
|
+
const pricing = await services.products.simulateProductPricing(pricingContext);
|
|
55
|
+
if (!pricing) return null;
|
|
60
56
|
const unitPrice = pricing.unitPrice({ useNetPrice });
|
|
61
57
|
|
|
62
58
|
return {
|
|
@@ -15,54 +15,23 @@ export const SimpleProduct = {
|
|
|
15
15
|
requestContext: Context,
|
|
16
16
|
): Promise<
|
|
17
17
|
Array<{
|
|
18
|
-
_id: string;
|
|
19
18
|
deliveryProvider?: DeliveryProvider;
|
|
20
19
|
warehousingProvider?: WarehousingProvider;
|
|
21
20
|
shipping?: Date;
|
|
22
21
|
earliestDelivery?: Date;
|
|
23
22
|
}>
|
|
24
23
|
> {
|
|
25
|
-
const {
|
|
26
|
-
const {
|
|
27
|
-
|
|
28
|
-
const deliveryProviders = await modules.delivery.findProviders({
|
|
29
|
-
type: deliveryProviderType,
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
return deliveryProviders.reduce(async (oldResult, deliveryProvider) => {
|
|
33
|
-
const result = await oldResult;
|
|
34
|
-
|
|
35
|
-
const warehousingProviders = await services.orders.supportedWarehousingProviders({
|
|
36
|
-
product: obj,
|
|
37
|
-
deliveryProvider,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const mappedWarehousingProviders = await Promise.all(
|
|
41
|
-
warehousingProviders.map(async (warehousingProvider) => {
|
|
42
|
-
const warehousingContext: WarehousingContext = {
|
|
43
|
-
deliveryProvider,
|
|
44
|
-
product: obj,
|
|
45
|
-
quantity,
|
|
46
|
-
referenceDate,
|
|
47
|
-
};
|
|
24
|
+
const { referenceDate, quantity } = params;
|
|
25
|
+
const { services, modules } = requestContext;
|
|
48
26
|
|
|
49
|
-
|
|
50
|
-
warehousingProvider,
|
|
51
|
-
warehousingContext,
|
|
52
|
-
requestContext,
|
|
53
|
-
);
|
|
54
|
-
const dispatch = await director.estimatedDispatch();
|
|
27
|
+
const deliveryProviders = await modules.delivery.findProviders({});
|
|
55
28
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
return result.concat(result, mappedWarehousingProviders);
|
|
65
|
-
}, Promise.resolve([]));
|
|
29
|
+
return services.products.simulateProductDispatching({
|
|
30
|
+
deliveryProviders,
|
|
31
|
+
product: obj,
|
|
32
|
+
quantity,
|
|
33
|
+
referenceDate,
|
|
34
|
+
});
|
|
66
35
|
},
|
|
67
36
|
|
|
68
37
|
async simulatedStocks(
|
|
@@ -74,7 +43,6 @@ export const SimpleProduct = {
|
|
|
74
43
|
requestContext: Context,
|
|
75
44
|
): Promise<
|
|
76
45
|
Array<{
|
|
77
|
-
_id: string;
|
|
78
46
|
deliveryProvider?: DeliveryProvider;
|
|
79
47
|
warehousingProvider?: WarehousingProvider;
|
|
80
48
|
quantity?: number;
|
|
@@ -87,39 +55,11 @@ export const SimpleProduct = {
|
|
|
87
55
|
type: deliveryProviderType,
|
|
88
56
|
});
|
|
89
57
|
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
deliveryProvider,
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
const mappedWarehousingProviders = await Promise.all(
|
|
99
|
-
warehousingProviders.map(async (warehousingProvider) => {
|
|
100
|
-
const warehousingContext: WarehousingContext = {
|
|
101
|
-
deliveryProvider,
|
|
102
|
-
product: obj,
|
|
103
|
-
referenceDate,
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const director = await WarehousingDirector.actions(
|
|
107
|
-
warehousingProvider,
|
|
108
|
-
warehousingContext,
|
|
109
|
-
requestContext,
|
|
110
|
-
);
|
|
111
|
-
const stock = await director.estimatedStock();
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
warehousingProvider,
|
|
115
|
-
...warehousingContext,
|
|
116
|
-
...stock,
|
|
117
|
-
};
|
|
118
|
-
}),
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
return result.concat(result, mappedWarehousingProviders);
|
|
122
|
-
}, Promise.resolve([]));
|
|
58
|
+
return services.products.simulateProductInventory({
|
|
59
|
+
deliveryProviders,
|
|
60
|
+
product: obj,
|
|
61
|
+
referenceDate,
|
|
62
|
+
});
|
|
123
63
|
},
|
|
124
64
|
|
|
125
65
|
baseUnit({ warehousing }): string {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { WarehousingContext, WarehousingDirector } from '@unchainedshop/core';
|
|
2
1
|
import {
|
|
3
2
|
Product,
|
|
4
3
|
ProductContractConfiguration,
|
|
@@ -40,7 +39,6 @@ export const TokenizedProduct = {
|
|
|
40
39
|
requestContext: Context,
|
|
41
40
|
): Promise<
|
|
42
41
|
Array<{
|
|
43
|
-
_id: string;
|
|
44
42
|
deliveryProvider?: DeliveryProvider;
|
|
45
43
|
warehousingProvider?: WarehousingProvider;
|
|
46
44
|
quantity?: number;
|
|
@@ -51,39 +49,11 @@ export const TokenizedProduct = {
|
|
|
51
49
|
|
|
52
50
|
const deliveryProviders = await modules.delivery.findProviders({});
|
|
53
51
|
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
deliveryProvider,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const mappedWarehousingProviders = await Promise.all(
|
|
63
|
-
warehousingProviders.map(async (warehousingProvider) => {
|
|
64
|
-
const warehousingContext: WarehousingContext = {
|
|
65
|
-
deliveryProvider,
|
|
66
|
-
product: obj,
|
|
67
|
-
referenceDate,
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const director = await WarehousingDirector.actions(
|
|
71
|
-
warehousingProvider,
|
|
72
|
-
warehousingContext,
|
|
73
|
-
requestContext,
|
|
74
|
-
);
|
|
75
|
-
const stock = await director.estimatedStock();
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
warehousingProvider,
|
|
79
|
-
...warehousingContext,
|
|
80
|
-
...stock,
|
|
81
|
-
};
|
|
82
|
-
}),
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
return result.concat(result, mappedWarehousingProviders);
|
|
86
|
-
}, Promise.resolve([]));
|
|
52
|
+
return services.products.simulateProductInventory({
|
|
53
|
+
deliveryProviders,
|
|
54
|
+
product: obj,
|
|
55
|
+
referenceDate,
|
|
56
|
+
});
|
|
87
57
|
},
|
|
88
58
|
|
|
89
59
|
async tokens(product: Product, params: never, requestContext: Context) {
|
|
@@ -114,7 +114,9 @@ const {
|
|
|
114
114
|
} = actions as Record<string, string>;
|
|
115
115
|
|
|
116
116
|
const getPrimaryEmail = (user: UserType) => {
|
|
117
|
-
return (user.emails || []).
|
|
117
|
+
return (user.emails || []).toSorted(
|
|
118
|
+
(left, right) => Number(right.verified) - Number(left.verified),
|
|
119
|
+
)?.[0];
|
|
118
120
|
};
|
|
119
121
|
|
|
120
122
|
export const User: UserHelperTypes = {
|
|
@@ -174,7 +176,7 @@ export const User: UserHelperTypes = {
|
|
|
174
176
|
const { modules, countryContext } = context;
|
|
175
177
|
await checkAction(context, viewUserOrders, [user, params]);
|
|
176
178
|
return modules.orders.cart({
|
|
177
|
-
|
|
179
|
+
countryCode: countryContext,
|
|
178
180
|
orderNumber: params.orderNumber,
|
|
179
181
|
userId: user._id,
|
|
180
182
|
});
|
package/tests/api-index.test.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Import the function to be tested.
|
|
2
|
-
import { admin } from '../
|
|
3
|
-
import { actions } from '../
|
|
4
|
-
import { checkAction, ensureActionExists, ensureIsFunction } from '../
|
|
5
|
-
import { NoPermissionError, PermissionSystemError } from '../
|
|
2
|
+
import { admin } from '../src/roles/admin.js';
|
|
3
|
+
import { actions } from '../src/roles/index.js';
|
|
4
|
+
import { checkAction, ensureActionExists, ensureIsFunction } from '../src/acl.js';
|
|
5
|
+
import { NoPermissionError, PermissionSystemError } from '../src/errors.js';
|
|
6
6
|
import { Roles } from '@unchainedshop/roles';
|
|
7
7
|
|
|
8
8
|
describe('API', () => {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getOrderCart.d.ts","sourceRoot":"","sources":["../../../../src/resolvers/mutations/utils/getOrderCart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AAGjD,eAAO,MAAM,YAAY,WAAkB;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,WAAW,OAAO,iBAe5F,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { OrderNotFoundError } from '../../../errors.js';
|
|
2
|
-
export const getOrderCart = async (params, context) => {
|
|
3
|
-
const { modules, services } = context;
|
|
4
|
-
const { orderId, user } = params;
|
|
5
|
-
if (orderId) {
|
|
6
|
-
const order = await modules.orders.findOrder({ orderId });
|
|
7
|
-
if (!order)
|
|
8
|
-
throw new OrderNotFoundError({ orderId });
|
|
9
|
-
return order;
|
|
10
|
-
}
|
|
11
|
-
return services.orders.nextUserCart({
|
|
12
|
-
user,
|
|
13
|
-
countryCode: context.countryContext,
|
|
14
|
-
forceCartCreation: true,
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=getOrderCart.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getOrderCart.js","sourceRoot":"","sources":["../../../../src/resolvers/mutations/utils/getOrderCart.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,MAAwC,EAAE,OAAgB,EAAE,EAAE;IAC/F,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IACtC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IAEjC,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,kBAAkB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QACtD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC;QAClC,IAAI;QACJ,WAAW,EAAE,OAAO,CAAC,cAAc;QACnC,iBAAiB,EAAE,IAAI;KACxB,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Context } from '../../../context.js';
|
|
2
|
-
import { User } from '@unchainedshop/core-users';
|
|
3
|
-
import { OrderNotFoundError } from '../../../errors.js';
|
|
4
|
-
|
|
5
|
-
export const getOrderCart = async (params: { orderId?: string; user: User }, context: Context) => {
|
|
6
|
-
const { modules, services } = context;
|
|
7
|
-
const { orderId, user } = params;
|
|
8
|
-
|
|
9
|
-
if (orderId) {
|
|
10
|
-
const order = await modules.orders.findOrder({ orderId });
|
|
11
|
-
if (!order) throw new OrderNotFoundError({ orderId });
|
|
12
|
-
return order;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return services.orders.nextUserCart({
|
|
16
|
-
user,
|
|
17
|
-
countryCode: context.countryContext,
|
|
18
|
-
forceCartCreation: true,
|
|
19
|
-
});
|
|
20
|
-
};
|