@labdigital/commercetools-mock 0.10.0 → 0.10.1
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.ts +353 -188
- package/dist/index.global.js +930 -874
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +271 -215
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +271 -215
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
- package/src/ctMock.ts +15 -9
- package/src/helpers.ts +1 -1
- package/src/lib/projectionSearchFilter.ts +3 -2
- package/src/priceSelector.test.ts +1 -3
- package/src/product-projection-search.ts +1 -3
- package/src/projectAPI.test.ts +7 -0
- package/src/projectAPI.ts +17 -22
- package/src/repositories/abstract.ts +31 -24
- package/src/repositories/cart-discount.ts +3 -4
- package/src/repositories/cart.ts +20 -15
- package/src/repositories/category.ts +6 -7
- package/src/repositories/channel.ts +4 -5
- package/src/repositories/custom-object.ts +9 -13
- package/src/repositories/customer-group.ts +3 -4
- package/src/repositories/customer.ts +4 -5
- package/src/repositories/discount-code.ts +4 -5
- package/src/repositories/errors.ts +1 -3
- package/src/repositories/extension.ts +7 -8
- package/src/repositories/helpers.ts +2 -2
- package/src/repositories/index.ts +19 -3
- package/src/repositories/inventory-entry.ts +4 -5
- package/src/repositories/my-order.ts +2 -2
- package/src/repositories/order-edit.ts +39 -0
- package/src/repositories/order.test.ts +16 -11
- package/src/repositories/order.ts +15 -8
- package/src/repositories/payment.ts +6 -7
- package/src/repositories/product-discount.ts +4 -24
- package/src/repositories/product-projection.ts +11 -5
- package/src/repositories/product-selection.ts +40 -0
- package/src/repositories/product-type.ts +11 -28
- package/src/repositories/product.ts +7 -8
- package/src/repositories/project.ts +8 -8
- package/src/repositories/quote-request.ts +28 -0
- package/src/repositories/quote.ts +28 -0
- package/src/repositories/review.ts +34 -0
- package/src/repositories/shipping-method.ts +10 -11
- package/src/repositories/shopping-list.ts +4 -4
- package/src/repositories/staged-quote.ts +29 -0
- package/src/repositories/standalone-price.ts +36 -0
- package/src/repositories/state.ts +7 -8
- package/src/repositories/store.ts +11 -27
- package/src/repositories/subscription.ts +3 -4
- package/src/repositories/tax-category.ts +5 -22
- package/src/repositories/type.ts +12 -13
- package/src/repositories/zone.ts +4 -5
- package/src/server.ts +4 -4
- package/src/services/abstract.ts +3 -5
- package/src/services/cart-discount.ts +1 -1
- package/src/services/cart.test.ts +1 -1
- package/src/services/cart.ts +40 -33
- package/src/services/category.ts +1 -1
- package/src/services/channel.ts +1 -1
- package/src/services/custom-object.test.ts +1 -1
- package/src/services/custom-object.ts +2 -2
- package/src/services/customer-group.ts +1 -1
- package/src/services/customer.test.ts +1 -1
- package/src/services/customer.ts +3 -3
- package/src/services/discount-code.ts +1 -1
- package/src/services/extension.ts +1 -1
- package/src/services/inventory-entry.test.ts +1 -1
- package/src/services/inventory-entry.ts +1 -1
- package/src/services/my-cart.test.ts +2 -0
- package/src/services/my-cart.ts +1 -1
- package/src/services/my-customer.ts +1 -1
- package/src/services/my-order.ts +1 -1
- package/src/services/my-payment.ts +1 -1
- package/src/services/order.test.ts +24 -20
- package/src/services/order.ts +2 -2
- package/src/services/payment.ts +1 -1
- package/src/services/product-discount.ts +1 -17
- package/src/services/product-projection.test.ts +1 -1
- package/src/services/product-projection.ts +2 -2
- package/src/services/product-type.ts +1 -17
- package/src/services/product.test.ts +1 -1
- package/src/services/product.ts +1 -1
- package/src/services/project.ts +2 -3
- package/src/services/shipping-method.ts +1 -1
- package/src/services/shopping-list.ts +1 -1
- package/src/services/state.ts +1 -1
- package/src/services/store.ts +2 -18
- package/src/services/subscription.ts +1 -1
- package/src/services/tax-category.ts +1 -17
- package/src/services/type.ts +1 -1
- package/src/services/zone.ts +1 -1
- package/src/storage/abstract.ts +82 -0
- package/src/{storage.ts → storage/in-memory.ts} +57 -118
- package/src/storage/index.ts +2 -0
- package/src/types.ts +48 -119
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
QuoteRequest,
|
|
3
|
+
QuoteRequestDraft,
|
|
4
|
+
QuoteRequestUpdateAction,
|
|
5
|
+
} from '@commercetools/platform-sdk'
|
|
6
|
+
import { Writable } from '../types'
|
|
7
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
8
|
+
|
|
9
|
+
export class QuoteRequestRepository extends AbstractResourceRepository<'quote-request'> {
|
|
10
|
+
getTypeId() {
|
|
11
|
+
return 'quote-request' as const
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
create(context: RepositoryContext, draft: QuoteRequestDraft): QuoteRequest {
|
|
15
|
+
throw new Error('not implemented')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
actions: Partial<
|
|
19
|
+
Record<
|
|
20
|
+
QuoteRequestUpdateAction['action'],
|
|
21
|
+
(
|
|
22
|
+
context: RepositoryContext,
|
|
23
|
+
resource: Writable<QuoteRequest>,
|
|
24
|
+
action: any
|
|
25
|
+
) => void
|
|
26
|
+
>
|
|
27
|
+
> = {}
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Quote,
|
|
3
|
+
QuoteDraft,
|
|
4
|
+
QuoteUpdateAction,
|
|
5
|
+
} from '@commercetools/platform-sdk'
|
|
6
|
+
import { Writable } from '../types'
|
|
7
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
8
|
+
|
|
9
|
+
export class QuoteRepository extends AbstractResourceRepository<'quote'> {
|
|
10
|
+
getTypeId() {
|
|
11
|
+
return 'quote' as const
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
create(context: RepositoryContext, draft: QuoteDraft): Quote {
|
|
15
|
+
throw new Error('not implemented')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
actions: Partial<
|
|
19
|
+
Record<
|
|
20
|
+
QuoteUpdateAction['action'],
|
|
21
|
+
(
|
|
22
|
+
context: RepositoryContext,
|
|
23
|
+
resource: Writable<Quote>,
|
|
24
|
+
action: any
|
|
25
|
+
) => void
|
|
26
|
+
>
|
|
27
|
+
> = {}
|
|
28
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Review,
|
|
3
|
+
ReviewDraft,
|
|
4
|
+
ReviewUpdateAction,
|
|
5
|
+
} from '@commercetools/platform-sdk'
|
|
6
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
7
|
+
import { Writable } from '../types'
|
|
8
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
9
|
+
|
|
10
|
+
export class ReviewRepository extends AbstractResourceRepository<'review'> {
|
|
11
|
+
getTypeId() {
|
|
12
|
+
return 'review' as const
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
create(context: RepositoryContext, draft: ReviewDraft): Review {
|
|
16
|
+
const resource: Review = {
|
|
17
|
+
...getBaseResourceProperties(),
|
|
18
|
+
includedInStatistics: false,
|
|
19
|
+
}
|
|
20
|
+
this.saveNew(context, resource)
|
|
21
|
+
return resource
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
actions: Partial<
|
|
25
|
+
Record<
|
|
26
|
+
ReviewUpdateAction['action'],
|
|
27
|
+
(
|
|
28
|
+
context: RepositoryContext,
|
|
29
|
+
resource: Writable<Review>,
|
|
30
|
+
action: any
|
|
31
|
+
) => void
|
|
32
|
+
>
|
|
33
|
+
> = {}
|
|
34
|
+
}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
createCustomFields,
|
|
3
|
-
createTypedMoney,
|
|
4
|
-
getReferenceFromResourceIdentifier,
|
|
5
|
-
} from './helpers'
|
|
6
|
-
import {
|
|
7
|
-
ReferenceTypeId,
|
|
8
2
|
ShippingMethod,
|
|
9
3
|
ShippingMethodAddShippingRateAction,
|
|
10
4
|
ShippingMethodAddZoneAction,
|
|
@@ -25,14 +19,19 @@ import {
|
|
|
25
19
|
ZoneRateDraft,
|
|
26
20
|
ZoneReference,
|
|
27
21
|
} from '@commercetools/platform-sdk'
|
|
22
|
+
import deepEqual from 'deep-equal'
|
|
28
23
|
import { getBaseResourceProperties } from '../helpers'
|
|
24
|
+
import { Writable } from '../types'
|
|
29
25
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
30
|
-
import {
|
|
31
|
-
|
|
26
|
+
import {
|
|
27
|
+
createCustomFields,
|
|
28
|
+
createTypedMoney,
|
|
29
|
+
getReferenceFromResourceIdentifier,
|
|
30
|
+
} from './helpers'
|
|
32
31
|
|
|
33
|
-
export class ShippingMethodRepository extends AbstractResourceRepository {
|
|
34
|
-
getTypeId()
|
|
35
|
-
return 'shipping-method'
|
|
32
|
+
export class ShippingMethodRepository extends AbstractResourceRepository<'shipping-method'> {
|
|
33
|
+
getTypeId() {
|
|
34
|
+
return 'shipping-method' as const
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
create(
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CustomerReference,
|
|
3
|
-
ReferenceTypeId,
|
|
4
3
|
ShoppingList,
|
|
5
4
|
ShoppingListDraft,
|
|
6
5
|
} from '@commercetools/platform-sdk'
|
|
@@ -11,10 +10,11 @@ import {
|
|
|
11
10
|
getReferenceFromResourceIdentifier,
|
|
12
11
|
} from './helpers'
|
|
13
12
|
|
|
14
|
-
export class ShoppingListRepository extends AbstractResourceRepository {
|
|
15
|
-
getTypeId()
|
|
16
|
-
return 'shopping-list'
|
|
13
|
+
export class ShoppingListRepository extends AbstractResourceRepository<'shopping-list'> {
|
|
14
|
+
getTypeId() {
|
|
15
|
+
return 'shopping-list' as const
|
|
17
16
|
}
|
|
17
|
+
|
|
18
18
|
create(context: RepositoryContext, draft: ShoppingListDraft): ShoppingList {
|
|
19
19
|
// const product =
|
|
20
20
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Quote,
|
|
3
|
+
StagedQuote,
|
|
4
|
+
StagedQuoteDraft,
|
|
5
|
+
StagedQuoteUpdateAction,
|
|
6
|
+
} from '@commercetools/platform-sdk'
|
|
7
|
+
import { Writable } from '../types'
|
|
8
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
9
|
+
|
|
10
|
+
export class StagedQuoteRepository extends AbstractResourceRepository<'staged-quote'> {
|
|
11
|
+
getTypeId() {
|
|
12
|
+
return 'staged-quote' as const
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
create(context: RepositoryContext, draft: StagedQuoteDraft): StagedQuote {
|
|
16
|
+
throw new Error('not implemented')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
actions: Partial<
|
|
20
|
+
Record<
|
|
21
|
+
StagedQuoteUpdateAction['action'],
|
|
22
|
+
(
|
|
23
|
+
context: RepositoryContext,
|
|
24
|
+
resource: Writable<Quote>,
|
|
25
|
+
action: any
|
|
26
|
+
) => void
|
|
27
|
+
>
|
|
28
|
+
> = {}
|
|
29
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Review,
|
|
3
|
+
StandalonePrice,
|
|
4
|
+
StandalonePriceUpdateAction,
|
|
5
|
+
} from '@commercetools/platform-sdk'
|
|
6
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
7
|
+
import { Writable } from '../types'
|
|
8
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
9
|
+
|
|
10
|
+
export class StandAlonePriceRepository extends AbstractResourceRepository<'standalone-price'> {
|
|
11
|
+
getTypeId() {
|
|
12
|
+
return 'standalone-price' as const
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
create(context: RepositoryContext, draft: StandalonePrice): StandalonePrice {
|
|
16
|
+
const resource: StandalonePrice = {
|
|
17
|
+
...getBaseResourceProperties(),
|
|
18
|
+
active: draft.active,
|
|
19
|
+
sku: draft.sku,
|
|
20
|
+
value: draft.value,
|
|
21
|
+
}
|
|
22
|
+
this.saveNew(context, resource)
|
|
23
|
+
return resource
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
actions: Partial<
|
|
27
|
+
Record<
|
|
28
|
+
StandalonePriceUpdateAction['action'],
|
|
29
|
+
(
|
|
30
|
+
context: RepositoryContext,
|
|
31
|
+
resource: Writable<Review>,
|
|
32
|
+
action: any
|
|
33
|
+
) => void
|
|
34
|
+
>
|
|
35
|
+
> = {}
|
|
36
|
+
}
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import { getBaseResourceProperties } from '../helpers'
|
|
2
|
-
import { getReferenceFromResourceIdentifier } from './helpers'
|
|
3
1
|
import {
|
|
4
|
-
ReferenceTypeId,
|
|
5
|
-
StateReference,
|
|
6
2
|
State,
|
|
7
3
|
StateChangeKeyAction,
|
|
8
4
|
StateDraft,
|
|
5
|
+
StateReference,
|
|
9
6
|
StateSetDescriptionAction,
|
|
10
7
|
StateSetNameAction,
|
|
11
8
|
StateSetRolesAction,
|
|
12
9
|
StateSetTransitionsAction,
|
|
13
10
|
StateUpdateAction,
|
|
14
11
|
} from '@commercetools/platform-sdk'
|
|
12
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
13
|
+
import { Writable } from '../types'
|
|
15
14
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
16
|
-
import {
|
|
15
|
+
import { getReferenceFromResourceIdentifier } from './helpers'
|
|
17
16
|
|
|
18
|
-
export class StateRepository extends AbstractResourceRepository {
|
|
19
|
-
getTypeId()
|
|
20
|
-
return 'state'
|
|
17
|
+
export class StateRepository extends AbstractResourceRepository<'state'> {
|
|
18
|
+
getTypeId() {
|
|
19
|
+
return 'state' as const
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
create(context: RepositoryContext, draft: StateDraft): State {
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Store,
|
|
3
|
-
StoreDraft,
|
|
4
|
-
ReferenceTypeId,
|
|
5
|
-
StoreUpdateAction,
|
|
6
|
-
StoreSetNameAction,
|
|
7
2
|
ChannelReference,
|
|
8
|
-
StoreSetDistributionChannelsAction,
|
|
9
3
|
ChannelResourceIdentifier,
|
|
10
|
-
|
|
4
|
+
Store,
|
|
5
|
+
StoreDraft,
|
|
11
6
|
StoreSetCustomFieldAction,
|
|
12
7
|
StoreSetCustomTypeAction,
|
|
8
|
+
StoreSetDistributionChannelsAction,
|
|
9
|
+
StoreSetLanguagesAction,
|
|
10
|
+
StoreSetNameAction,
|
|
11
|
+
StoreUpdateAction,
|
|
13
12
|
} from '@commercetools/platform-sdk'
|
|
14
|
-
import { Writable } from 'types'
|
|
15
13
|
import { getBaseResourceProperties } from '../helpers'
|
|
14
|
+
import { Writable } from '../types'
|
|
16
15
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
17
16
|
import {
|
|
18
|
-
getReferenceFromResourceIdentifier,
|
|
19
17
|
createCustomFields,
|
|
18
|
+
getReferenceFromResourceIdentifier,
|
|
20
19
|
} from './helpers'
|
|
21
20
|
|
|
22
|
-
export class StoreRepository extends AbstractResourceRepository {
|
|
23
|
-
getTypeId()
|
|
24
|
-
return 'store'
|
|
21
|
+
export class StoreRepository extends AbstractResourceRepository<'store'> {
|
|
22
|
+
getTypeId() {
|
|
23
|
+
return 'store' as const
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
create(context: RepositoryContext, draft: StoreDraft): Store {
|
|
@@ -61,21 +60,6 @@ export class StoreRepository extends AbstractResourceRepository {
|
|
|
61
60
|
)
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
getWithKey(context: RepositoryContext, key: string): Store | undefined {
|
|
65
|
-
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
66
|
-
where: [`key="${key}"`],
|
|
67
|
-
})
|
|
68
|
-
if (result.count === 1) {
|
|
69
|
-
return result.results[0] as Store
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (result.count > 1) {
|
|
73
|
-
throw new Error('Duplicate store key')
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return
|
|
77
|
-
}
|
|
78
|
-
|
|
79
63
|
actions: Partial<
|
|
80
64
|
Record<
|
|
81
65
|
StoreUpdateAction['action'],
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
InvalidInputError,
|
|
3
|
-
ReferenceTypeId,
|
|
4
3
|
Subscription,
|
|
5
4
|
SubscriptionDraft,
|
|
6
5
|
} from '@commercetools/platform-sdk'
|
|
@@ -8,9 +7,9 @@ import { CommercetoolsError } from '../exceptions'
|
|
|
8
7
|
import { getBaseResourceProperties } from '../helpers'
|
|
9
8
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
10
9
|
|
|
11
|
-
export class SubscriptionRepository extends AbstractResourceRepository {
|
|
12
|
-
getTypeId()
|
|
13
|
-
return 'subscription'
|
|
10
|
+
export class SubscriptionRepository extends AbstractResourceRepository<'subscription'> {
|
|
11
|
+
getTypeId() {
|
|
12
|
+
return 'subscription' as const
|
|
14
13
|
}
|
|
15
14
|
create(context: RepositoryContext, draft: SubscriptionDraft): Subscription {
|
|
16
15
|
// TODO: We could actually test this here by using the aws sdk. For now
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ReferenceTypeId,
|
|
3
2
|
TaxCategory,
|
|
4
3
|
TaxCategoryAddTaxRateAction,
|
|
5
4
|
TaxCategoryChangeNameAction,
|
|
@@ -12,14 +11,14 @@ import {
|
|
|
12
11
|
TaxRate,
|
|
13
12
|
TaxRateDraft,
|
|
14
13
|
} from '@commercetools/platform-sdk'
|
|
14
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
15
15
|
import { getBaseResourceProperties } from '../helpers'
|
|
16
|
+
import { Writable } from '../types'
|
|
16
17
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
17
|
-
import { v4 as uuidv4 } from 'uuid'
|
|
18
|
-
import { Writable } from 'types'
|
|
19
18
|
|
|
20
|
-
export class TaxCategoryRepository extends AbstractResourceRepository {
|
|
21
|
-
getTypeId()
|
|
22
|
-
return 'tax-category'
|
|
19
|
+
export class TaxCategoryRepository extends AbstractResourceRepository<'tax-category'> {
|
|
20
|
+
getTypeId() {
|
|
21
|
+
return 'tax-category' as const
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
create(context: RepositoryContext, draft: TaxCategoryDraft): TaxCategory {
|
|
@@ -38,22 +37,6 @@ export class TaxCategoryRepository extends AbstractResourceRepository {
|
|
|
38
37
|
amount: draft.amount || 0,
|
|
39
38
|
})
|
|
40
39
|
|
|
41
|
-
getWithKey(context: RepositoryContext, key: string): TaxCategory | undefined {
|
|
42
|
-
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
43
|
-
where: [`key="${key}"`],
|
|
44
|
-
})
|
|
45
|
-
if (result.count === 1) {
|
|
46
|
-
return result.results[0] as TaxCategory
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Catch this for now, should be checked when creating/updating
|
|
50
|
-
if (result.count > 1) {
|
|
51
|
-
throw new Error('Duplicate tax category key')
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
|
|
57
40
|
actions: Partial<
|
|
58
41
|
Record<
|
|
59
42
|
TaxCategoryUpdateAction['action'],
|
package/src/repositories/type.ts
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Type,
|
|
3
|
-
TypeDraft,
|
|
4
|
-
InvalidOperationError,
|
|
5
|
-
ReferenceTypeId,
|
|
6
|
-
TypeUpdateAction,
|
|
7
2
|
FieldDefinition,
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
InvalidOperationError,
|
|
4
|
+
Type,
|
|
5
|
+
TypeAddEnumValueAction,
|
|
10
6
|
TypeAddFieldDefinitionAction,
|
|
11
7
|
TypeChangeEnumValueLabelAction,
|
|
12
|
-
TypeAddEnumValueAction,
|
|
13
8
|
TypeChangeFieldDefinitionOrderAction,
|
|
9
|
+
TypeChangeNameAction,
|
|
10
|
+
TypeDraft,
|
|
14
11
|
TypeRemoveFieldDefinitionAction,
|
|
12
|
+
TypeSetDescriptionAction,
|
|
13
|
+
TypeUpdateAction,
|
|
15
14
|
} from '@commercetools/platform-sdk'
|
|
16
|
-
import { CommercetoolsError } from '../exceptions'
|
|
17
15
|
import { isEqual } from 'lodash'
|
|
18
|
-
import {
|
|
16
|
+
import { CommercetoolsError } from '../exceptions'
|
|
19
17
|
import { getBaseResourceProperties } from '../helpers'
|
|
18
|
+
import { Writable } from '../types'
|
|
20
19
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
21
20
|
|
|
22
|
-
export class TypeRepository extends AbstractResourceRepository {
|
|
23
|
-
getTypeId()
|
|
24
|
-
return 'type'
|
|
21
|
+
export class TypeRepository extends AbstractResourceRepository<'type'> {
|
|
22
|
+
getTypeId() {
|
|
23
|
+
return 'type' as const
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
create(context: RepositoryContext, draft: TypeDraft): Type {
|
package/src/repositories/zone.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ReferenceTypeId,
|
|
3
2
|
Zone,
|
|
4
3
|
ZoneAddLocationAction,
|
|
5
4
|
ZoneChangeNameAction,
|
|
@@ -9,13 +8,13 @@ import {
|
|
|
9
8
|
ZoneSetKeyAction,
|
|
10
9
|
ZoneUpdateAction,
|
|
11
10
|
} from '@commercetools/platform-sdk'
|
|
12
|
-
import { Writable } from 'types'
|
|
13
11
|
import { getBaseResourceProperties } from '../helpers'
|
|
12
|
+
import { Writable } from '../types'
|
|
14
13
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
15
14
|
|
|
16
|
-
export class ZoneRepository extends AbstractResourceRepository {
|
|
17
|
-
getTypeId()
|
|
18
|
-
return 'zone'
|
|
15
|
+
export class ZoneRepository extends AbstractResourceRepository<'zone'> {
|
|
16
|
+
getTypeId() {
|
|
17
|
+
return 'zone' as const
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
create(context: RepositoryContext, draft: ZoneDraft): Zone {
|
package/src/server.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { CommercetoolsMock } from './index'
|
|
2
2
|
|
|
3
|
-
process.on('SIGINT', function() {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
})
|
|
3
|
+
process.on('SIGINT', function () {
|
|
4
|
+
console.info('Stopping server...')
|
|
5
|
+
process.exit()
|
|
6
|
+
})
|
|
7
7
|
|
|
8
8
|
const instance = new CommercetoolsMock()
|
|
9
9
|
|
package/src/services/abstract.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Update } from '@commercetools/platform-sdk'
|
|
2
|
-
import { ParsedQs } from 'qs'
|
|
3
2
|
import { Request, Response, Router } from 'express'
|
|
3
|
+
import { ParsedQs } from 'qs'
|
|
4
4
|
import { AbstractResourceRepository } from '../repositories/abstract'
|
|
5
5
|
import { getRepositoryContext } from '../repositories/helpers'
|
|
6
6
|
|
|
7
7
|
export default abstract class AbstractService {
|
|
8
8
|
protected abstract getBasePath(): string
|
|
9
|
-
public abstract repository: AbstractResourceRepository
|
|
9
|
+
public abstract repository: AbstractResourceRepository<any>
|
|
10
10
|
|
|
11
11
|
createStatusCode = 201
|
|
12
12
|
|
|
@@ -14,9 +14,7 @@ export default abstract class AbstractService {
|
|
|
14
14
|
this.registerRoutes(parent)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
extraRoutes(router: Router) {
|
|
18
|
-
|
|
19
|
-
}
|
|
17
|
+
extraRoutes(router: Router) {}
|
|
20
18
|
|
|
21
19
|
registerRoutes(parent: Router) {
|
|
22
20
|
const basePath = this.getBasePath()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Router } from 'express'
|
|
2
|
-
import AbstractService from './abstract'
|
|
3
2
|
import { CartDiscountRepository } from '../repositories/cart-discount'
|
|
3
|
+
import AbstractService from './abstract'
|
|
4
4
|
|
|
5
5
|
export class CartDiscountService extends AbstractService {
|
|
6
6
|
public repository: CartDiscountRepository
|
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
CentPrecisionMoney,
|
|
5
5
|
ProductDraft,
|
|
6
6
|
} from '@commercetools/platform-sdk'
|
|
7
|
+
import assert from 'assert'
|
|
7
8
|
import supertest from 'supertest'
|
|
8
9
|
import { CommercetoolsMock } from '../index'
|
|
9
|
-
import assert from 'assert'
|
|
10
10
|
|
|
11
11
|
describe('Carts Query', () => {
|
|
12
12
|
const ctMock = new CommercetoolsMock()
|
package/src/services/cart.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import AbstractService from './abstract'
|
|
2
|
-
import { Router } from 'express'
|
|
3
|
-
import { CartRepository } from '../repositories/cart'
|
|
4
1
|
import { Cart, CartDraft, Order } from '@commercetools/platform-sdk'
|
|
5
|
-
import {
|
|
2
|
+
import { Request, Response, Router } from 'express'
|
|
3
|
+
import { CartRepository } from '../repositories/cart'
|
|
6
4
|
import { getRepositoryContext } from '../repositories/helpers'
|
|
5
|
+
import { OrderRepository } from '../repositories/order'
|
|
6
|
+
import AbstractService from './abstract'
|
|
7
7
|
|
|
8
8
|
export class CartService extends AbstractService {
|
|
9
9
|
public repository: CartRepository
|
|
10
10
|
public orderRepository: OrderRepository
|
|
11
11
|
|
|
12
|
-
constructor(
|
|
12
|
+
constructor(
|
|
13
|
+
parent: Router,
|
|
14
|
+
cartRepository: CartRepository,
|
|
15
|
+
orderRepository: OrderRepository
|
|
16
|
+
) {
|
|
13
17
|
super(parent)
|
|
14
18
|
this.repository = cartRepository
|
|
15
19
|
this.orderRepository = orderRepository
|
|
@@ -20,33 +24,36 @@ export class CartService extends AbstractService {
|
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
extraRoutes(parent: Router) {
|
|
23
|
-
parent.post('/replicate', (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
27
|
+
parent.post('/replicate', this.replicate.bind(this))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
replicate(request: Request, response: Response) {
|
|
31
|
+
const context = getRepositoryContext(request)
|
|
32
|
+
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
const cartOrOrder: Cart | Order | null =
|
|
35
|
+
request.body.reference.typeId === 'order'
|
|
36
|
+
? this.orderRepository.get(context, request.body.reference.id)
|
|
37
|
+
: this.repository.get(context, request.body.reference.id)
|
|
38
|
+
|
|
39
|
+
if (!cartOrOrder) {
|
|
40
|
+
return response.status(400).send()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const cartDraft: CartDraft = {
|
|
44
|
+
...cartOrOrder,
|
|
45
|
+
currency: cartOrOrder.totalPrice.currencyCode,
|
|
46
|
+
discountCodes: [],
|
|
47
|
+
shipping: [], // TODO: cartOrOrder.shipping,
|
|
48
|
+
lineItems: cartOrOrder.lineItems.map((lineItem) => ({
|
|
49
|
+
...lineItem,
|
|
50
|
+
variantId: lineItem.variant.id,
|
|
51
|
+
sku: lineItem.variant.sku,
|
|
52
|
+
})),
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const newCart = this.repository.create(context, cartDraft)
|
|
56
|
+
|
|
57
|
+
return response.status(200).send(newCart)
|
|
51
58
|
}
|
|
52
59
|
}
|
package/src/services/category.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import AbstractService from './abstract'
|
|
2
1
|
import { Router } from 'express'
|
|
3
2
|
import { CategoryRepository } from '../repositories/category'
|
|
3
|
+
import AbstractService from './abstract'
|
|
4
4
|
|
|
5
5
|
export class CategoryServices extends AbstractService {
|
|
6
6
|
public repository: CategoryRepository
|
package/src/services/channel.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import AbstractService from './abstract'
|
|
2
1
|
import { Router } from 'express'
|
|
3
2
|
import { ChannelRepository } from '../repositories/channel'
|
|
3
|
+
import AbstractService from './abstract'
|
|
4
4
|
|
|
5
5
|
export class ChannelService extends AbstractService {
|
|
6
6
|
public repository: ChannelRepository
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CustomObject } from '@commercetools/platform-sdk'
|
|
2
|
-
import { getBaseResourceProperties } from '../helpers'
|
|
3
2
|
import supertest from 'supertest'
|
|
3
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
4
4
|
import { CommercetoolsMock } from '../index'
|
|
5
5
|
|
|
6
6
|
describe('CustomObject create', () => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CustomObjectDraft } from '@commercetools/platform-sdk'
|
|
2
2
|
import { Request, Response, Router } from 'express'
|
|
3
3
|
import { CustomObjectRepository } from '../repositories/custom-object'
|
|
4
|
-
import { CustomObjectDraft } from '@commercetools/platform-sdk'
|
|
5
4
|
import { getRepositoryContext } from '../repositories/helpers'
|
|
5
|
+
import AbstractService from './abstract'
|
|
6
6
|
|
|
7
7
|
export class CustomObjectService extends AbstractService {
|
|
8
8
|
public repository: CustomObjectRepository
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import AbstractService from './abstract'
|
|
2
1
|
import { Router } from 'express'
|
|
3
2
|
import { CustomerGroupRepository } from '../repositories/customer-group'
|
|
3
|
+
import AbstractService from './abstract'
|
|
4
4
|
|
|
5
5
|
export class CustomerGroupService extends AbstractService {
|
|
6
6
|
public repository: CustomerGroupRepository
|
package/src/services/customer.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import AbstractService from './abstract'
|
|
2
1
|
import { Router } from 'express'
|
|
3
|
-
import { CustomerRepository } from '../repositories/customer'
|
|
4
|
-
import { getBaseResourceProperties } from '../helpers'
|
|
5
2
|
import { v4 as uuidv4 } from 'uuid'
|
|
3
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
4
|
+
import { CustomerRepository } from '../repositories/customer'
|
|
6
5
|
import { getRepositoryContext } from '../repositories/helpers'
|
|
6
|
+
import AbstractService from './abstract'
|
|
7
7
|
|
|
8
8
|
export class CustomerService extends AbstractService {
|
|
9
9
|
public repository: CustomerRepository
|