@labdigital/commercetools-mock 0.5.21 → 0.5.22

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.
@@ -1586,16 +1586,308 @@ const calculateLineItemTotalPrice = lineItem => lineItem.price.value.centAmount
1586
1586
 
1587
1587
  const calculateCartTotalPrice = cart => cart.lineItems.reduce((cur, item) => cur + item.totalPrice.centAmount, 0);
1588
1588
 
1589
+ class OrderRepository extends AbstractResourceRepository {
1590
+ constructor() {
1591
+ super(...arguments);
1592
+ this.actions = {
1593
+ addPayment: (projectKey, resource, {
1594
+ payment
1595
+ }) => {
1596
+ const resolvedPayment = this._storage.getByResourceIdentifier(projectKey, payment);
1597
+
1598
+ if (!resolvedPayment) {
1599
+ throw new Error(`Payment ${payment.id} not found`);
1600
+ }
1601
+
1602
+ if (!resource.paymentInfo) {
1603
+ resource.paymentInfo = {
1604
+ payments: []
1605
+ };
1606
+ }
1607
+
1608
+ resource.paymentInfo.payments.push({
1609
+ typeId: 'payment',
1610
+ id: payment.id
1611
+ });
1612
+ },
1613
+ changeOrderState: (projectKey, resource, {
1614
+ orderState
1615
+ }) => {
1616
+ resource.orderState = orderState;
1617
+ },
1618
+ changePaymentState: (projectKey, resource, {
1619
+ paymentState
1620
+ }) => {
1621
+ resource.paymentState = paymentState;
1622
+ },
1623
+ transitionState: (projectKey, resource, {
1624
+ state
1625
+ }) => {
1626
+ const resolvedType = this._storage.getByResourceIdentifier(projectKey, state);
1627
+
1628
+ if (!resolvedType) {
1629
+ throw new Error(`No state found with key=${state.key} or id=${state.key}`);
1630
+ }
1631
+
1632
+ resource.state = {
1633
+ typeId: 'state',
1634
+ id: resolvedType.id
1635
+ };
1636
+ },
1637
+ setBillingAddress: (projectKey, resource, {
1638
+ address
1639
+ }) => {
1640
+ resource.billingAddress = address;
1641
+ },
1642
+ setCustomerEmail: (projectKey, resource, {
1643
+ email
1644
+ }) => {
1645
+ resource.customerEmail = email;
1646
+ },
1647
+ setCustomField: (projectKey, resource, {
1648
+ name,
1649
+ value
1650
+ }) => {
1651
+ if (!resource.custom) {
1652
+ throw new Error('Resource has no custom field');
1653
+ }
1654
+
1655
+ resource.custom.fields[name] = value;
1656
+ },
1657
+ setCustomType: (projectKey, resource, {
1658
+ type,
1659
+ fields
1660
+ }) => {
1661
+ if (!type) {
1662
+ resource.custom = undefined;
1663
+ } else {
1664
+ const resolvedType = this._storage.getByResourceIdentifier(projectKey, type);
1665
+
1666
+ if (!resolvedType) {
1667
+ throw new Error(`Type ${type} not found`);
1668
+ }
1669
+
1670
+ resource.custom = {
1671
+ type: {
1672
+ typeId: 'type',
1673
+ id: resolvedType.id
1674
+ },
1675
+ fields: fields || []
1676
+ };
1677
+ }
1678
+ },
1679
+ setLocale: (projectKey, resource, {
1680
+ locale
1681
+ }) => {
1682
+ resource.locale = locale;
1683
+ },
1684
+ setOrderNumber: (projectKey, resource, {
1685
+ orderNumber
1686
+ }) => {
1687
+ resource.orderNumber = orderNumber;
1688
+ },
1689
+ setShippingAddress: (projectKey, resource, {
1690
+ address
1691
+ }) => {
1692
+ resource.shippingAddress = address;
1693
+ },
1694
+ setStore: (projectKey, resource, {
1695
+ store
1696
+ }) => {
1697
+ if (!store) return;
1698
+
1699
+ const resolvedType = this._storage.getByResourceIdentifier(projectKey, store);
1700
+
1701
+ if (!resolvedType) {
1702
+ throw new Error(`No store found with key=${store.key}`);
1703
+ }
1704
+
1705
+ const storeReference = resolvedType;
1706
+ resource.store = {
1707
+ typeId: 'store',
1708
+ key: storeReference.key
1709
+ };
1710
+ }
1711
+ };
1712
+ }
1713
+
1714
+ getTypeId() {
1715
+ return 'order';
1716
+ }
1717
+
1718
+ create(projectKey, draft) {
1719
+ assert(draft.cart, 'draft.cart is missing');
1720
+
1721
+ const cart = this._storage.getByResourceIdentifier(projectKey, draft.cart);
1722
+
1723
+ if (!cart) {
1724
+ throw new Error('Cannot find cart');
1725
+ }
1726
+
1727
+ const resource = { ...getBaseResourceProperties(),
1728
+ orderNumber: draft.orderNumber,
1729
+ orderState: 'Open',
1730
+ lineItems: [],
1731
+ customLineItems: [],
1732
+ totalPrice: cart.totalPrice,
1733
+ refusedGifts: [],
1734
+ origin: 'Customer',
1735
+ syncInfo: [],
1736
+ lastMessageSequenceNumber: 0
1737
+ };
1738
+ this.save(projectKey, resource);
1739
+ return resource;
1740
+ }
1741
+
1742
+ import(projectKey, draft) {
1743
+ var _draft$lineItems, _draft$customLineItem;
1744
+
1745
+ // TODO: Check if order with given orderNumber already exists
1746
+ assert(this, 'OrderRepository not valid');
1747
+ const resource = { ...getBaseResourceProperties(),
1748
+ billingAddress: draft.billingAddress,
1749
+ shippingAddress: draft.shippingAddress,
1750
+ custom: createCustomFields(draft.custom, projectKey, this._storage),
1751
+ customerEmail: draft.customerEmail,
1752
+ lastMessageSequenceNumber: 0,
1753
+ orderNumber: draft.orderNumber,
1754
+ orderState: draft.orderState || 'Open',
1755
+ origin: draft.origin || 'Customer',
1756
+ paymentState: draft.paymentState,
1757
+ refusedGifts: [],
1758
+ store: resolveStoreReference(draft.store, projectKey, this._storage),
1759
+ syncInfo: [],
1760
+ lineItems: ((_draft$lineItems = draft.lineItems) == null ? void 0 : _draft$lineItems.map(item => this.lineItemFromImportDraft.bind(this)(projectKey, item))) || [],
1761
+ customLineItems: ((_draft$customLineItem = draft.customLineItems) == null ? void 0 : _draft$customLineItem.map(item => this.customLineItemFromImportDraft.bind(this)(projectKey, item))) || [],
1762
+ totalPrice: {
1763
+ type: 'centPrecision',
1764
+ ...draft.totalPrice,
1765
+ fractionDigits: 2
1766
+ }
1767
+ };
1768
+ this.save(projectKey, resource);
1769
+ return resource;
1770
+ }
1771
+
1772
+ lineItemFromImportDraft(projectKey, draft) {
1773
+ let product;
1774
+ let variant;
1775
+
1776
+ if (draft.variant.sku) {
1777
+ variant = {
1778
+ id: 0,
1779
+ sku: draft.variant.sku
1780
+ };
1781
+
1782
+ var items = this._storage.query(projectKey, 'product', {
1783
+ where: [`masterData(current(masterVariant(sku="${draft.variant.sku}"))) or masterData(current(variants(sku="${draft.variant.sku}")))`]
1784
+ });
1785
+
1786
+ if (items.count !== 1) {
1787
+ throw new CommercetoolsError({
1788
+ code: 'General',
1789
+ message: `A product containing a variant with SKU '${draft.variant.sku}' not found.`
1790
+ });
1791
+ }
1792
+
1793
+ product = items.results[0];
1794
+
1795
+ if (product.masterData.current.masterVariant.sku === draft.variant.sku) {
1796
+ variant = product.masterData.current.masterVariant;
1797
+ } else {
1798
+ variant = product.masterData.current.variants.find(v => v.sku === draft.variant.sku);
1799
+ }
1800
+
1801
+ if (!variant) {
1802
+ throw new Error('Internal state error');
1803
+ }
1804
+ } else {
1805
+ throw new Error('No product found');
1806
+ }
1807
+
1808
+ const lineItem = { ...getBaseResourceProperties(),
1809
+ custom: createCustomFields(draft.custom, projectKey, this._storage),
1810
+ discountedPricePerQuantity: [],
1811
+ lineItemMode: 'Standard',
1812
+ name: draft.name,
1813
+ price: createPrice(draft.price),
1814
+ priceMode: 'Platform',
1815
+ productId: product.id,
1816
+ productType: product.productType,
1817
+ quantity: draft.quantity,
1818
+ state: draft.state || [],
1819
+ taxRate: draft.taxRate,
1820
+ totalPrice: createTypedMoney(draft.price.value),
1821
+ variant: {
1822
+ id: variant.id,
1823
+ sku: variant.sku,
1824
+ price: createPrice(draft.price)
1825
+ }
1826
+ };
1827
+ return lineItem;
1828
+ }
1829
+
1830
+ customLineItemFromImportDraft(projectKey, draft) {
1831
+ const lineItem = { ...getBaseResourceProperties(),
1832
+ custom: createCustomFields(draft.custom, projectKey, this._storage),
1833
+ discountedPricePerQuantity: [],
1834
+ money: createTypedMoney(draft.money),
1835
+ name: draft.name,
1836
+ quantity: draft.quantity,
1837
+ slug: draft.slug,
1838
+ state: [],
1839
+ totalPrice: createTypedMoney(draft.money)
1840
+ };
1841
+ return lineItem;
1842
+ }
1843
+
1844
+ getWithOrderNumber(projectKey, orderNumber, params = {}) {
1845
+ const result = this._storage.query(projectKey, this.getTypeId(), { ...params,
1846
+ where: [`orderNumber="${orderNumber}"`]
1847
+ });
1848
+
1849
+ if (result.count === 1) {
1850
+ return result.results[0];
1851
+ } // Catch this for now, should be checked when creating/updating
1852
+
1853
+
1854
+ if (result.count > 1) {
1855
+ throw new Error('Duplicate order numbers');
1856
+ }
1857
+
1858
+ return;
1859
+ }
1860
+
1861
+ }
1862
+
1589
1863
  class CartService extends AbstractService {
1590
1864
  constructor(parent, storage) {
1591
1865
  super(parent);
1592
1866
  this.repository = new CartRepository(storage);
1867
+ this.orderRepository = new OrderRepository(storage);
1593
1868
  }
1594
1869
 
1595
1870
  getBasePath() {
1596
1871
  return 'carts';
1597
1872
  }
1598
1873
 
1874
+ extraRoutes(parent) {
1875
+ parent.post('/replicate', (request, response) => {
1876
+ // @ts-ignore
1877
+ const cartOrOrder = request.body.reference.typeId === 'order' ? this.orderRepository.get(request.params.projectKey, request.body.reference.id) : this.repository.get(request.params.projectKey, request.body.reference.id);
1878
+
1879
+ if (!cartOrOrder) {
1880
+ return response.status(400).send();
1881
+ }
1882
+
1883
+ const newCart = this.repository.create(request.params.projectKey, { ...cartOrOrder,
1884
+ currency: cartOrOrder.totalPrice.currencyCode,
1885
+ discountCodes: []
1886
+ });
1887
+ return response.status(200).send(newCart);
1888
+ });
1889
+ }
1890
+
1599
1891
  }
1600
1892
 
1601
1893
  class CategoryRepository extends AbstractResourceRepository {
@@ -2264,155 +2556,13 @@ class PaymentRepository extends AbstractResourceRepository {
2264
2556
  constructor() {
2265
2557
  super(...arguments);
2266
2558
 
2267
- this.transactionFromTransactionDraft = (draft, projectKey) => ({ ...draft,
2268
- id: uuid.v4(),
2269
- amount: createTypedMoney(draft.amount),
2270
- custom: createCustomFields(draft.custom, projectKey, this._storage)
2271
- });
2272
-
2273
- this.actions = {
2274
- setCustomField: (projectKey, resource, {
2275
- name,
2276
- value
2277
- }) => {
2278
- if (!resource.custom) {
2279
- throw new Error('Resource has no custom field');
2280
- }
2281
-
2282
- resource.custom.fields[name] = value;
2283
- },
2284
- setCustomType: (projectKey, resource, {
2285
- type,
2286
- fields
2287
- }) => {
2288
- if (!type) {
2289
- resource.custom = undefined;
2290
- } else {
2291
- const resolvedType = this._storage.getByResourceIdentifier(projectKey, type);
2292
-
2293
- if (!resolvedType) {
2294
- throw new Error(`Type ${type} not found`);
2295
- }
2296
-
2297
- resource.custom = {
2298
- type: {
2299
- typeId: 'type',
2300
- id: resolvedType.id
2301
- },
2302
- fields: fields || []
2303
- };
2304
- }
2305
- },
2306
- addTransaction: (projectKey, resource, {
2307
- transaction
2308
- }) => {
2309
- resource.transactions = [...resource.transactions, this.transactionFromTransactionDraft(transaction, projectKey)];
2310
- },
2311
- changeTransactionState: (_projectKey, resource, {
2312
- transactionId,
2313
- state
2314
- }) => {
2315
- const index = resource.transactions.findIndex(e => e.id === transactionId);
2316
- const updatedTransaction = { ...resource.transactions[index],
2317
- state
2318
- };
2319
- resource.transactions[index] = updatedTransaction;
2320
- },
2321
- transitionState: (projectKey, resource, {
2322
- state
2323
- }) => {
2324
- const stateObj = this._storage.getByResourceIdentifier(projectKey, state);
2325
-
2326
- if (!stateObj) {
2327
- throw new Error(`State ${state} not found`);
2328
- }
2329
-
2330
- resource.paymentStatus.state = {
2331
- typeId: 'state',
2332
- id: stateObj.id,
2333
- obj: stateObj
2334
- };
2335
- }
2336
- };
2337
- }
2338
-
2339
- getTypeId() {
2340
- return 'payment';
2341
- }
2342
-
2343
- create(projectKey, draft) {
2344
- const resource = { ...getBaseResourceProperties(),
2345
- amountPlanned: createTypedMoney(draft.amountPlanned),
2346
- paymentMethodInfo: draft.paymentMethodInfo,
2347
- paymentStatus: draft.paymentStatus ? { ...draft.paymentStatus,
2348
- state: draft.paymentStatus.state ? getReferenceFromResourceIdentifier(draft.paymentStatus.state, projectKey, this._storage) : undefined
2349
- } : {},
2350
- transactions: (draft.transactions || []).map(t => this.transactionFromTransactionDraft(t, projectKey)),
2351
- interfaceInteractions: (draft.interfaceInteractions || []).map(interaction => createCustomFields(interaction, projectKey, this._storage)),
2352
- custom: createCustomFields(draft.custom, projectKey, this._storage)
2353
- };
2354
- this.save(projectKey, resource);
2355
- return resource;
2356
- }
2357
-
2358
- }
2359
-
2360
- class MyPaymentService extends AbstractService {
2361
- constructor(parent, storage) {
2362
- super(parent);
2363
- this.repository = new PaymentRepository(storage);
2364
- }
2365
-
2366
- getBasePath() {
2367
- return 'me/payments';
2368
- }
2369
-
2370
- }
2371
-
2372
- class OrderRepository extends AbstractResourceRepository {
2373
- constructor() {
2374
- super(...arguments);
2375
- this.actions = {
2376
- addPayment: (projectKey, resource, {
2377
- payment
2378
- }) => {
2379
- const resolvedPayment = this._storage.getByResourceIdentifier(projectKey, payment);
2380
-
2381
- if (!resolvedPayment) {
2382
- throw new Error(`Payment ${payment.id} not found`);
2383
- }
2384
-
2385
- if (!resource.paymentInfo) {
2386
- resource.paymentInfo = {
2387
- payments: []
2388
- };
2389
- }
2559
+ this.transactionFromTransactionDraft = (draft, projectKey) => ({ ...draft,
2560
+ id: uuid.v4(),
2561
+ amount: createTypedMoney(draft.amount),
2562
+ custom: createCustomFields(draft.custom, projectKey, this._storage)
2563
+ });
2390
2564
 
2391
- resource.paymentInfo.payments.push({
2392
- typeId: 'payment',
2393
- id: payment.id
2394
- });
2395
- },
2396
- changeOrderState: (projectKey, resource, {
2397
- orderState
2398
- }) => {
2399
- resource.orderState = orderState;
2400
- },
2401
- changePaymentState: (projectKey, resource, {
2402
- paymentState
2403
- }) => {
2404
- resource.paymentState = paymentState;
2405
- },
2406
- setBillingAddress: (projectKey, resource, {
2407
- address
2408
- }) => {
2409
- resource.billingAddress = address;
2410
- },
2411
- setCustomerEmail: (projectKey, resource, {
2412
- email
2413
- }) => {
2414
- resource.customerEmail = email;
2415
- },
2565
+ this.actions = {
2416
2566
  setCustomField: (projectKey, resource, {
2417
2567
  name,
2418
2568
  value
@@ -2445,186 +2595,68 @@ class OrderRepository extends AbstractResourceRepository {
2445
2595
  };
2446
2596
  }
2447
2597
  },
2448
- setLocale: (projectKey, resource, {
2449
- locale
2450
- }) => {
2451
- resource.locale = locale;
2452
- },
2453
- setOrderNumber: (projectKey, resource, {
2454
- orderNumber
2598
+ addTransaction: (projectKey, resource, {
2599
+ transaction
2455
2600
  }) => {
2456
- resource.orderNumber = orderNumber;
2601
+ resource.transactions = [...resource.transactions, this.transactionFromTransactionDraft(transaction, projectKey)];
2457
2602
  },
2458
- setShippingAddress: (projectKey, resource, {
2459
- address
2603
+ changeTransactionState: (_projectKey, resource, {
2604
+ transactionId,
2605
+ state
2460
2606
  }) => {
2461
- resource.shippingAddress = address;
2607
+ const index = resource.transactions.findIndex(e => e.id === transactionId);
2608
+ const updatedTransaction = { ...resource.transactions[index],
2609
+ state
2610
+ };
2611
+ resource.transactions[index] = updatedTransaction;
2462
2612
  },
2463
- setStore: (projectKey, resource, {
2464
- store
2613
+ transitionState: (projectKey, resource, {
2614
+ state
2465
2615
  }) => {
2466
- if (!store) return;
2467
-
2468
- const resolvedType = this._storage.getByResourceIdentifier(projectKey, store);
2616
+ const stateObj = this._storage.getByResourceIdentifier(projectKey, state);
2469
2617
 
2470
- if (!resolvedType) {
2471
- throw new Error(`No store found with key=${store.key}`);
2618
+ if (!stateObj) {
2619
+ throw new Error(`State ${state} not found`);
2472
2620
  }
2473
2621
 
2474
- const storeReference = resolvedType;
2475
- resource.store = {
2476
- typeId: 'store',
2477
- key: storeReference.key
2622
+ resource.paymentStatus.state = {
2623
+ typeId: 'state',
2624
+ id: stateObj.id,
2625
+ obj: stateObj
2478
2626
  };
2479
2627
  }
2480
2628
  };
2481
2629
  }
2482
2630
 
2483
2631
  getTypeId() {
2484
- return 'order';
2632
+ return 'payment';
2485
2633
  }
2486
2634
 
2487
2635
  create(projectKey, draft) {
2488
- assert(draft.cart, 'draft.cart is missing');
2489
-
2490
- const cart = this._storage.getByResourceIdentifier(projectKey, draft.cart);
2491
-
2492
- if (!cart) {
2493
- throw new Error('Cannot find cart');
2494
- }
2495
-
2496
- const resource = { ...getBaseResourceProperties(),
2497
- orderNumber: draft.orderNumber,
2498
- orderState: 'Open',
2499
- lineItems: [],
2500
- customLineItems: [],
2501
- totalPrice: cart.totalPrice,
2502
- refusedGifts: [],
2503
- origin: 'Customer',
2504
- syncInfo: [],
2505
- lastMessageSequenceNumber: 0
2506
- };
2507
- this.save(projectKey, resource);
2508
- return resource;
2509
- }
2510
-
2511
- import(projectKey, draft) {
2512
- var _draft$lineItems, _draft$customLineItem;
2513
-
2514
- // TODO: Check if order with given orderNumber already exists
2515
- assert(this, 'OrderRepository not valid');
2516
2636
  const resource = { ...getBaseResourceProperties(),
2517
- billingAddress: draft.billingAddress,
2518
- shippingAddress: draft.shippingAddress,
2519
- custom: createCustomFields(draft.custom, projectKey, this._storage),
2520
- customerEmail: draft.customerEmail,
2521
- lastMessageSequenceNumber: 0,
2522
- orderNumber: draft.orderNumber,
2523
- orderState: draft.orderState || 'Open',
2524
- origin: draft.origin || 'Customer',
2525
- paymentState: draft.paymentState,
2526
- refusedGifts: [],
2527
- store: resolveStoreReference(draft.store, projectKey, this._storage),
2528
- syncInfo: [],
2529
- lineItems: ((_draft$lineItems = draft.lineItems) == null ? void 0 : _draft$lineItems.map(item => this.lineItemFromImportDraft.bind(this)(projectKey, item))) || [],
2530
- customLineItems: ((_draft$customLineItem = draft.customLineItems) == null ? void 0 : _draft$customLineItem.map(item => this.customLineItemFromImportDraft.bind(this)(projectKey, item))) || [],
2531
- totalPrice: {
2532
- type: 'centPrecision',
2533
- ...draft.totalPrice,
2534
- fractionDigits: 2
2535
- }
2637
+ amountPlanned: createTypedMoney(draft.amountPlanned),
2638
+ paymentMethodInfo: draft.paymentMethodInfo,
2639
+ paymentStatus: draft.paymentStatus ? { ...draft.paymentStatus,
2640
+ state: draft.paymentStatus.state ? getReferenceFromResourceIdentifier(draft.paymentStatus.state, projectKey, this._storage) : undefined
2641
+ } : {},
2642
+ transactions: (draft.transactions || []).map(t => this.transactionFromTransactionDraft(t, projectKey)),
2643
+ interfaceInteractions: (draft.interfaceInteractions || []).map(interaction => createCustomFields(interaction, projectKey, this._storage)),
2644
+ custom: createCustomFields(draft.custom, projectKey, this._storage)
2536
2645
  };
2537
2646
  this.save(projectKey, resource);
2538
2647
  return resource;
2539
2648
  }
2540
2649
 
2541
- lineItemFromImportDraft(projectKey, draft) {
2542
- let product;
2543
- let variant;
2544
-
2545
- if (draft.variant.sku) {
2546
- variant = {
2547
- id: 0,
2548
- sku: draft.variant.sku
2549
- };
2550
-
2551
- var items = this._storage.query(projectKey, 'product', {
2552
- where: [`masterData(current(masterVariant(sku="${draft.variant.sku}"))) or masterData(current(variants(sku="${draft.variant.sku}")))`]
2553
- });
2554
-
2555
- if (items.count !== 1) {
2556
- throw new CommercetoolsError({
2557
- code: 'General',
2558
- message: `A product containing a variant with SKU '${draft.variant.sku}' not found.`
2559
- });
2560
- }
2561
-
2562
- product = items.results[0];
2563
-
2564
- if (product.masterData.current.masterVariant.sku === draft.variant.sku) {
2565
- variant = product.masterData.current.masterVariant;
2566
- } else {
2567
- variant = product.masterData.current.variants.find(v => v.sku === draft.variant.sku);
2568
- }
2569
-
2570
- if (!variant) {
2571
- throw new Error('Internal state error');
2572
- }
2573
- } else {
2574
- throw new Error('No product found');
2575
- }
2576
-
2577
- const lineItem = { ...getBaseResourceProperties(),
2578
- custom: createCustomFields(draft.custom, projectKey, this._storage),
2579
- discountedPricePerQuantity: [],
2580
- lineItemMode: 'Standard',
2581
- name: draft.name,
2582
- price: createPrice(draft.price),
2583
- priceMode: 'Platform',
2584
- productId: product.id,
2585
- productType: product.productType,
2586
- quantity: draft.quantity,
2587
- state: draft.state || [],
2588
- taxRate: draft.taxRate,
2589
- totalPrice: createTypedMoney(draft.price.value),
2590
- variant: {
2591
- id: variant.id,
2592
- sku: variant.sku,
2593
- price: createPrice(draft.price)
2594
- }
2595
- };
2596
- return lineItem;
2597
- }
2650
+ }
2598
2651
 
2599
- customLineItemFromImportDraft(projectKey, draft) {
2600
- const lineItem = { ...getBaseResourceProperties(),
2601
- custom: createCustomFields(draft.custom, projectKey, this._storage),
2602
- discountedPricePerQuantity: [],
2603
- money: createTypedMoney(draft.money),
2604
- name: draft.name,
2605
- quantity: draft.quantity,
2606
- slug: draft.slug,
2607
- state: [],
2608
- totalPrice: createTypedMoney(draft.money)
2609
- };
2610
- return lineItem;
2652
+ class MyPaymentService extends AbstractService {
2653
+ constructor(parent, storage) {
2654
+ super(parent);
2655
+ this.repository = new PaymentRepository(storage);
2611
2656
  }
2612
2657
 
2613
- getWithOrderNumber(projectKey, orderNumber, params = {}) {
2614
- const result = this._storage.query(projectKey, this.getTypeId(), { ...params,
2615
- where: [`orderNumber="${orderNumber}"`]
2616
- });
2617
-
2618
- if (result.count === 1) {
2619
- return result.results[0];
2620
- } // Catch this for now, should be checked when creating/updating
2621
-
2622
-
2623
- if (result.count > 1) {
2624
- throw new Error('Duplicate order numbers');
2625
- }
2626
-
2627
- return;
2658
+ getBasePath() {
2659
+ return 'me/payments';
2628
2660
  }
2629
2661
 
2630
2662
  }
@@ -3993,6 +4025,33 @@ class MyCustomerService extends AbstractService {
3993
4025
 
3994
4026
  }
3995
4027
 
4028
+ class MyOrderService extends AbstractService {
4029
+ constructor(parent, storage) {
4030
+ super(parent);
4031
+ this.repository = new OrderRepository(storage);
4032
+ }
4033
+
4034
+ getBasePath() {
4035
+ return 'me';
4036
+ }
4037
+
4038
+ registerRoutes(parent) {
4039
+ // Overwrite this function to be able to handle /me/active-cart path.
4040
+ const basePath = this.getBasePath();
4041
+ const router = express.Router({
4042
+ mergeParams: true
4043
+ });
4044
+ this.extraRoutes(router);
4045
+ router.get('/orders/', this.get.bind(this));
4046
+ router.get('/orders/:id', this.getWithId.bind(this));
4047
+ router.delete('/orders/:id', this.deletewithId.bind(this));
4048
+ router.post('/orders/', this.post.bind(this));
4049
+ router.post('/orders/:id', this.postWithId.bind(this));
4050
+ parent.use(`/${basePath}`, router);
4051
+ }
4052
+
4053
+ }
4054
+
3996
4055
  const DEFAULT_OPTIONS = {
3997
4056
  enableAuthentication: false,
3998
4057
  validateCredentials: false,
@@ -4091,6 +4150,7 @@ class CommercetoolsMock {
4091
4150
  order: new OrderService(projectRouter, this._storage),
4092
4151
  payment: new PaymentService(projectRouter, this._storage),
4093
4152
  'my-cart': new MyCartService(projectRouter, this._storage),
4153
+ 'my-order': new MyOrderService(projectRouter, this._storage),
4094
4154
  'my-customer': new MyCustomerService(projectRouter, this._storage),
4095
4155
  'my-payment': new MyPaymentService(projectRouter, this._storage),
4096
4156
  'shipping-method': new ShippingMethodService(projectRouter, this._storage),