@labdigital/commercetools-mock 2.61.3 → 2.62.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.mts +9 -7
- package/dist/index.mjs +208 -181
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/repositories/as-associate.test.ts +25 -0
- package/src/repositories/as-associate.ts +2 -0
- package/src/repositories/helpers.ts +4 -6
- package/src/repositories/index.ts +2 -0
- package/src/services/as-associate-shopping-list.test.ts +58 -0
- package/src/services/as-associate-shopping-list.ts +33 -0
- package/src/services/as-associate.ts +8 -0
package/dist/index.d.mts
CHANGED
|
@@ -113,10 +113,18 @@ declare class QuoteRequestRepository extends AbstractResourceRepository<"quote-r
|
|
|
113
113
|
createFromCart(context: RepositoryContext, cartReference: CartReference): QuoteRequest;
|
|
114
114
|
}
|
|
115
115
|
//#endregion
|
|
116
|
+
//#region src/repositories/shopping-list/index.d.ts
|
|
117
|
+
declare class ShoppingListRepository extends AbstractResourceRepository<"shopping-list"> {
|
|
118
|
+
constructor(config: Config);
|
|
119
|
+
create(context: RepositoryContext, draft: ShoppingListDraft): ShoppingList;
|
|
120
|
+
draftLineItemtoLineItem: (projectKey: string, draftLineItem: LineItemDraft) => ShoppingListLineItem;
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
116
123
|
//#region src/repositories/as-associate.d.ts
|
|
117
124
|
declare class AsAssociateOrderRepository extends OrderRepository {}
|
|
118
125
|
declare class AsAssociateCartRepository extends CartRepository {}
|
|
119
126
|
declare class AsAssociateQuoteRequestRepository extends QuoteRequestRepository {}
|
|
127
|
+
declare class AsAssociateShoppingListRepository extends ShoppingListRepository {}
|
|
120
128
|
//#endregion
|
|
121
129
|
//#region src/repositories/associate-role.d.ts
|
|
122
130
|
declare class AssociateRoleRepository extends AbstractResourceRepository<"associate-role"> {
|
|
@@ -1159,13 +1167,6 @@ declare class ShippingMethodRepository extends AbstractResourceRepository<"shipp
|
|
|
1159
1167
|
private _transformZoneRateDraft;
|
|
1160
1168
|
}
|
|
1161
1169
|
//#endregion
|
|
1162
|
-
//#region src/repositories/shopping-list/index.d.ts
|
|
1163
|
-
declare class ShoppingListRepository extends AbstractResourceRepository<"shopping-list"> {
|
|
1164
|
-
constructor(config: Config);
|
|
1165
|
-
create(context: RepositoryContext, draft: ShoppingListDraft): ShoppingList;
|
|
1166
|
-
draftLineItemtoLineItem: (projectKey: string, draftLineItem: LineItemDraft) => ShoppingListLineItem;
|
|
1167
|
-
}
|
|
1168
|
-
//#endregion
|
|
1169
1170
|
//#region src/repositories/standalone-price.d.ts
|
|
1170
1171
|
declare class StandAlonePriceRepository extends AbstractResourceRepository<"standalone-price"> {
|
|
1171
1172
|
constructor(config: Config);
|
|
@@ -1216,6 +1217,7 @@ declare const createRepositories: (config: Config) => {
|
|
|
1216
1217
|
cart: AsAssociateCartRepository;
|
|
1217
1218
|
order: AsAssociateOrderRepository;
|
|
1218
1219
|
"quote-request": AsAssociateQuoteRequestRepository;
|
|
1220
|
+
"shopping-list": AsAssociateShoppingListRepository;
|
|
1219
1221
|
};
|
|
1220
1222
|
"associate-role": AssociateRoleRepository;
|
|
1221
1223
|
"attribute-group": AttributeGroupRepository;
|
package/dist/index.mjs
CHANGED
|
@@ -666,11 +666,11 @@ const getBusinessUnitKeyReference = (id, projectKey, storage) => {
|
|
|
666
666
|
typeId: "business-unit",
|
|
667
667
|
key: id.key
|
|
668
668
|
};
|
|
669
|
-
const
|
|
670
|
-
if (!
|
|
669
|
+
const resource = storage.getByResourceIdentifier(projectKey, id);
|
|
670
|
+
if (!resource?.key) throw new Error("No business-unit found for reference");
|
|
671
671
|
return {
|
|
672
672
|
typeId: "business-unit",
|
|
673
|
-
key:
|
|
673
|
+
key: resource.key
|
|
674
674
|
};
|
|
675
675
|
};
|
|
676
676
|
|
|
@@ -1969,11 +1969,188 @@ var QuoteRequestRepository = class extends AbstractResourceRepository {
|
|
|
1969
1969
|
}
|
|
1970
1970
|
};
|
|
1971
1971
|
|
|
1972
|
+
//#endregion
|
|
1973
|
+
//#region src/repositories/shopping-list/actions.ts
|
|
1974
|
+
var ShoppingListUpdateHandler = class extends AbstractUpdateHandler {
|
|
1975
|
+
addLineItem(context, resource, { productId, variantId, sku, quantity = 1, addedAt, key }) {
|
|
1976
|
+
let product = null;
|
|
1977
|
+
if (productId) product = this._storage.get(context.projectKey, "product", productId, {});
|
|
1978
|
+
else if (sku) {
|
|
1979
|
+
const items = this._storage.query(context.projectKey, "product", { where: [`masterData(current(masterVariant(sku="${sku}"))) or masterData(current(variants(sku="${sku}")))`] });
|
|
1980
|
+
if (items.count === 1) product = items.results[0];
|
|
1981
|
+
}
|
|
1982
|
+
if (!product) throw new CommercetoolsError({
|
|
1983
|
+
code: "General",
|
|
1984
|
+
message: sku ? `A product containing a variant with SKU '${sku}' not found.` : `A product with ID '${productId}' not found.`
|
|
1985
|
+
});
|
|
1986
|
+
let varId = variantId;
|
|
1987
|
+
if (sku) varId = [product.masterData.current.masterVariant, ...product.masterData.current.variants].find((x) => x.sku === sku)?.id;
|
|
1988
|
+
if (!varId) varId = product.masterData.current.masterVariant.id;
|
|
1989
|
+
if (resource.lineItems.some((x) => x.productId === product?.id && x.variantId === varId)) resource.lineItems.forEach((x) => {
|
|
1990
|
+
if (x.productId === product?.id && x.variantId === varId) x.quantity += quantity;
|
|
1991
|
+
});
|
|
1992
|
+
else resource.lineItems.push({
|
|
1993
|
+
addedAt: addedAt ? addedAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
1994
|
+
id: v4(),
|
|
1995
|
+
key,
|
|
1996
|
+
productId: product.id,
|
|
1997
|
+
productSlug: product.masterData.current.slug,
|
|
1998
|
+
productType: product.productType,
|
|
1999
|
+
name: product.masterData.current.name,
|
|
2000
|
+
variantId: varId,
|
|
2001
|
+
quantity,
|
|
2002
|
+
published: Boolean(product.masterData.current)
|
|
2003
|
+
});
|
|
2004
|
+
}
|
|
2005
|
+
changeLineItemQuantity(context, resource, { lineItemId, lineItemKey, quantity }) {
|
|
2006
|
+
let lineItem;
|
|
2007
|
+
if (lineItemId) {
|
|
2008
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
2009
|
+
if (!lineItem) throw new CommercetoolsError({
|
|
2010
|
+
code: "General",
|
|
2011
|
+
message: `A line item with ID '${lineItemId}' not found.`
|
|
2012
|
+
});
|
|
2013
|
+
} else if (lineItemKey) {
|
|
2014
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
2015
|
+
if (!lineItem) throw new CommercetoolsError({
|
|
2016
|
+
code: "General",
|
|
2017
|
+
message: `A line item with Key '${lineItemKey}' not found.`
|
|
2018
|
+
});
|
|
2019
|
+
} else throw new CommercetoolsError({
|
|
2020
|
+
code: "General",
|
|
2021
|
+
message: "Either lineItemid or lineItemKey needs to be provided."
|
|
2022
|
+
});
|
|
2023
|
+
if (quantity === 0) resource.lineItems = resource.lineItems.filter((x) => x.id !== lineItemId);
|
|
2024
|
+
else resource.lineItems.forEach((x) => {
|
|
2025
|
+
if (x.id === lineItemId && quantity) x.quantity = quantity;
|
|
2026
|
+
});
|
|
2027
|
+
}
|
|
2028
|
+
changeName(context, resource, { name }) {
|
|
2029
|
+
resource.name = name;
|
|
2030
|
+
}
|
|
2031
|
+
removeLineItem(context, resource, { lineItemId, quantity }) {
|
|
2032
|
+
const lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
2033
|
+
if (!lineItem) throw new CommercetoolsError({
|
|
2034
|
+
code: "General",
|
|
2035
|
+
message: `A line item with ID '${lineItemId}' not found.`
|
|
2036
|
+
});
|
|
2037
|
+
if (!quantity || quantity >= lineItem.quantity) resource.lineItems = resource.lineItems.filter((x) => x.id !== lineItemId);
|
|
2038
|
+
else resource.lineItems.forEach((x) => {
|
|
2039
|
+
if (x.id === lineItemId && quantity) x.quantity -= quantity;
|
|
2040
|
+
});
|
|
2041
|
+
}
|
|
2042
|
+
setAnonymousId(context, resource, { anonymousId }) {
|
|
2043
|
+
resource.anonymousId = anonymousId;
|
|
2044
|
+
}
|
|
2045
|
+
setCustomer(context, resource, { customer }) {
|
|
2046
|
+
if (customer?.key) throw new Error("set customer on shoppinglist by key not implemented");
|
|
2047
|
+
if (customer?.id) resource.customer = {
|
|
2048
|
+
typeId: "customer",
|
|
2049
|
+
id: customer.id
|
|
2050
|
+
};
|
|
2051
|
+
}
|
|
2052
|
+
setCustomField(context, resource, { name, value }) {
|
|
2053
|
+
if (!resource.custom) throw new Error("Resource has no custom field");
|
|
2054
|
+
resource.custom.fields[name] = value;
|
|
2055
|
+
}
|
|
2056
|
+
setCustomType(context, resource, { type, fields }) {
|
|
2057
|
+
if (!type) resource.custom = void 0;
|
|
2058
|
+
else {
|
|
2059
|
+
const resolvedType = this._storage.getByResourceIdentifier(context.projectKey, type);
|
|
2060
|
+
if (!resolvedType) throw new Error(`Type ${type} not found`);
|
|
2061
|
+
resource.custom = {
|
|
2062
|
+
type: {
|
|
2063
|
+
typeId: "type",
|
|
2064
|
+
id: resolvedType.id
|
|
2065
|
+
},
|
|
2066
|
+
fields: fields || {}
|
|
2067
|
+
};
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
setDeleteDaysAfterLastModification(context, resource, { deleteDaysAfterLastModification }) {
|
|
2071
|
+
resource.deleteDaysAfterLastModification = deleteDaysAfterLastModification;
|
|
2072
|
+
}
|
|
2073
|
+
setDescription(context, resource, { description }) {
|
|
2074
|
+
resource.description = description;
|
|
2075
|
+
}
|
|
2076
|
+
setKey(context, resource, { key }) {
|
|
2077
|
+
resource.key = key;
|
|
2078
|
+
}
|
|
2079
|
+
setSlug(context, resource, { slug }) {
|
|
2080
|
+
resource.slug = slug;
|
|
2081
|
+
}
|
|
2082
|
+
setStore(context, resource, { store }) {
|
|
2083
|
+
if (store?.key) resource.store = {
|
|
2084
|
+
typeId: "store",
|
|
2085
|
+
key: store.key
|
|
2086
|
+
};
|
|
2087
|
+
if (store?.id) throw new Error("set store on shoppinglist by id not implemented");
|
|
2088
|
+
}
|
|
2089
|
+
};
|
|
2090
|
+
|
|
2091
|
+
//#endregion
|
|
2092
|
+
//#region src/repositories/shopping-list/index.ts
|
|
2093
|
+
var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
2094
|
+
constructor(config) {
|
|
2095
|
+
super("shopping-list", config);
|
|
2096
|
+
this.actions = new ShoppingListUpdateHandler(config.storage);
|
|
2097
|
+
}
|
|
2098
|
+
create(context, draft) {
|
|
2099
|
+
const lineItems = draft.lineItems?.map((draftLineItem) => this.draftLineItemtoLineItem(context.projectKey, draftLineItem)) ?? [];
|
|
2100
|
+
const resource = {
|
|
2101
|
+
...getBaseResourceProperties(),
|
|
2102
|
+
...draft,
|
|
2103
|
+
custom: createCustomFields(draft.custom, context.projectKey, this._storage),
|
|
2104
|
+
textLineItems: [],
|
|
2105
|
+
lineItems,
|
|
2106
|
+
customer: draft.customer ? getReferenceFromResourceIdentifier(draft.customer, context.projectKey, this._storage) : void 0,
|
|
2107
|
+
store: draft.store ? getStoreKeyReference(draft.store, context.projectKey, this._storage) : void 0,
|
|
2108
|
+
businessUnit: draft.businessUnit ? getBusinessUnitKeyReference(draft.businessUnit, context.projectKey, this._storage) : void 0
|
|
2109
|
+
};
|
|
2110
|
+
return this.saveNew(context, resource);
|
|
2111
|
+
}
|
|
2112
|
+
draftLineItemtoLineItem = (projectKey, draftLineItem) => {
|
|
2113
|
+
const { sku, productId, variantId } = draftLineItem;
|
|
2114
|
+
const lineItem = {
|
|
2115
|
+
...getBaseResourceProperties(),
|
|
2116
|
+
...draftLineItem,
|
|
2117
|
+
addedAt: draftLineItem.addedAt ?? "",
|
|
2118
|
+
productId: draftLineItem.productId ?? "",
|
|
2119
|
+
name: {},
|
|
2120
|
+
variantId,
|
|
2121
|
+
published: true,
|
|
2122
|
+
quantity: draftLineItem.quantity ?? 1,
|
|
2123
|
+
productType: {
|
|
2124
|
+
typeId: "product-type",
|
|
2125
|
+
id: ""
|
|
2126
|
+
},
|
|
2127
|
+
custom: createCustomFields(draftLineItem.custom, projectKey, this._storage)
|
|
2128
|
+
};
|
|
2129
|
+
if (productId && variantId) return lineItem;
|
|
2130
|
+
if (sku) {
|
|
2131
|
+
const items = this._storage.query(projectKey, "product", { where: [`masterData(current(masterVariant(sku="${sku}"))) or masterData(current(variants(sku="${sku}")))`] });
|
|
2132
|
+
if (items.count === 0) throw new Error(`Product with sku ${sku} not found`);
|
|
2133
|
+
const product = items.results[0];
|
|
2134
|
+
lineItem.variantId = [product.masterData.current.masterVariant, ...product.masterData.current.variants].find((e) => e.sku === sku)?.id;
|
|
2135
|
+
lineItem.productId = product.id;
|
|
2136
|
+
return lineItem;
|
|
2137
|
+
}
|
|
2138
|
+
if (productId) {
|
|
2139
|
+
const items = this._storage.query(projectKey, "product", { where: [`id="${productId}"`] });
|
|
2140
|
+
if (items.count === 0) throw new Error(`Product with id ${productId} not found`);
|
|
2141
|
+
lineItem.variantId = items.results[0].masterData.current.masterVariant.id;
|
|
2142
|
+
return lineItem;
|
|
2143
|
+
}
|
|
2144
|
+
throw new Error("must provide either sku, productId or variantId for ShoppingListLineItem");
|
|
2145
|
+
};
|
|
2146
|
+
};
|
|
2147
|
+
|
|
1972
2148
|
//#endregion
|
|
1973
2149
|
//#region src/repositories/as-associate.ts
|
|
1974
2150
|
var AsAssociateOrderRepository = class extends OrderRepository {};
|
|
1975
2151
|
var AsAssociateCartRepository = class extends CartRepository {};
|
|
1976
2152
|
var AsAssociateQuoteRequestRepository = class extends QuoteRequestRepository {};
|
|
2153
|
+
var AsAssociateShoppingListRepository = class extends ShoppingListRepository {};
|
|
1977
2154
|
|
|
1978
2155
|
//#endregion
|
|
1979
2156
|
//#region src/repositories/associate-role.ts
|
|
@@ -6243,182 +6420,6 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
6243
6420
|
}
|
|
6244
6421
|
};
|
|
6245
6422
|
|
|
6246
|
-
//#endregion
|
|
6247
|
-
//#region src/repositories/shopping-list/actions.ts
|
|
6248
|
-
var ShoppingListUpdateHandler = class extends AbstractUpdateHandler {
|
|
6249
|
-
addLineItem(context, resource, { productId, variantId, sku, quantity = 1, addedAt, key }) {
|
|
6250
|
-
let product = null;
|
|
6251
|
-
if (productId) product = this._storage.get(context.projectKey, "product", productId, {});
|
|
6252
|
-
else if (sku) {
|
|
6253
|
-
const items = this._storage.query(context.projectKey, "product", { where: [`masterData(current(masterVariant(sku="${sku}"))) or masterData(current(variants(sku="${sku}")))`] });
|
|
6254
|
-
if (items.count === 1) product = items.results[0];
|
|
6255
|
-
}
|
|
6256
|
-
if (!product) throw new CommercetoolsError({
|
|
6257
|
-
code: "General",
|
|
6258
|
-
message: sku ? `A product containing a variant with SKU '${sku}' not found.` : `A product with ID '${productId}' not found.`
|
|
6259
|
-
});
|
|
6260
|
-
let varId = variantId;
|
|
6261
|
-
if (sku) varId = [product.masterData.current.masterVariant, ...product.masterData.current.variants].find((x) => x.sku === sku)?.id;
|
|
6262
|
-
if (!varId) varId = product.masterData.current.masterVariant.id;
|
|
6263
|
-
if (resource.lineItems.some((x) => x.productId === product?.id && x.variantId === varId)) resource.lineItems.forEach((x) => {
|
|
6264
|
-
if (x.productId === product?.id && x.variantId === varId) x.quantity += quantity;
|
|
6265
|
-
});
|
|
6266
|
-
else resource.lineItems.push({
|
|
6267
|
-
addedAt: addedAt ? addedAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
6268
|
-
id: v4(),
|
|
6269
|
-
key,
|
|
6270
|
-
productId: product.id,
|
|
6271
|
-
productSlug: product.masterData.current.slug,
|
|
6272
|
-
productType: product.productType,
|
|
6273
|
-
name: product.masterData.current.name,
|
|
6274
|
-
variantId: varId,
|
|
6275
|
-
quantity,
|
|
6276
|
-
published: Boolean(product.masterData.current)
|
|
6277
|
-
});
|
|
6278
|
-
}
|
|
6279
|
-
changeLineItemQuantity(context, resource, { lineItemId, lineItemKey, quantity }) {
|
|
6280
|
-
let lineItem;
|
|
6281
|
-
if (lineItemId) {
|
|
6282
|
-
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
6283
|
-
if (!lineItem) throw new CommercetoolsError({
|
|
6284
|
-
code: "General",
|
|
6285
|
-
message: `A line item with ID '${lineItemId}' not found.`
|
|
6286
|
-
});
|
|
6287
|
-
} else if (lineItemKey) {
|
|
6288
|
-
lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
6289
|
-
if (!lineItem) throw new CommercetoolsError({
|
|
6290
|
-
code: "General",
|
|
6291
|
-
message: `A line item with Key '${lineItemKey}' not found.`
|
|
6292
|
-
});
|
|
6293
|
-
} else throw new CommercetoolsError({
|
|
6294
|
-
code: "General",
|
|
6295
|
-
message: "Either lineItemid or lineItemKey needs to be provided."
|
|
6296
|
-
});
|
|
6297
|
-
if (quantity === 0) resource.lineItems = resource.lineItems.filter((x) => x.id !== lineItemId);
|
|
6298
|
-
else resource.lineItems.forEach((x) => {
|
|
6299
|
-
if (x.id === lineItemId && quantity) x.quantity = quantity;
|
|
6300
|
-
});
|
|
6301
|
-
}
|
|
6302
|
-
changeName(context, resource, { name }) {
|
|
6303
|
-
resource.name = name;
|
|
6304
|
-
}
|
|
6305
|
-
removeLineItem(context, resource, { lineItemId, quantity }) {
|
|
6306
|
-
const lineItem = resource.lineItems.find((x) => x.id === lineItemId);
|
|
6307
|
-
if (!lineItem) throw new CommercetoolsError({
|
|
6308
|
-
code: "General",
|
|
6309
|
-
message: `A line item with ID '${lineItemId}' not found.`
|
|
6310
|
-
});
|
|
6311
|
-
if (!quantity || quantity >= lineItem.quantity) resource.lineItems = resource.lineItems.filter((x) => x.id !== lineItemId);
|
|
6312
|
-
else resource.lineItems.forEach((x) => {
|
|
6313
|
-
if (x.id === lineItemId && quantity) x.quantity -= quantity;
|
|
6314
|
-
});
|
|
6315
|
-
}
|
|
6316
|
-
setAnonymousId(context, resource, { anonymousId }) {
|
|
6317
|
-
resource.anonymousId = anonymousId;
|
|
6318
|
-
}
|
|
6319
|
-
setCustomer(context, resource, { customer }) {
|
|
6320
|
-
if (customer?.key) throw new Error("set customer on shoppinglist by key not implemented");
|
|
6321
|
-
if (customer?.id) resource.customer = {
|
|
6322
|
-
typeId: "customer",
|
|
6323
|
-
id: customer.id
|
|
6324
|
-
};
|
|
6325
|
-
}
|
|
6326
|
-
setCustomField(context, resource, { name, value }) {
|
|
6327
|
-
if (!resource.custom) throw new Error("Resource has no custom field");
|
|
6328
|
-
resource.custom.fields[name] = value;
|
|
6329
|
-
}
|
|
6330
|
-
setCustomType(context, resource, { type, fields }) {
|
|
6331
|
-
if (!type) resource.custom = void 0;
|
|
6332
|
-
else {
|
|
6333
|
-
const resolvedType = this._storage.getByResourceIdentifier(context.projectKey, type);
|
|
6334
|
-
if (!resolvedType) throw new Error(`Type ${type} not found`);
|
|
6335
|
-
resource.custom = {
|
|
6336
|
-
type: {
|
|
6337
|
-
typeId: "type",
|
|
6338
|
-
id: resolvedType.id
|
|
6339
|
-
},
|
|
6340
|
-
fields: fields || {}
|
|
6341
|
-
};
|
|
6342
|
-
}
|
|
6343
|
-
}
|
|
6344
|
-
setDeleteDaysAfterLastModification(context, resource, { deleteDaysAfterLastModification }) {
|
|
6345
|
-
resource.deleteDaysAfterLastModification = deleteDaysAfterLastModification;
|
|
6346
|
-
}
|
|
6347
|
-
setDescription(context, resource, { description }) {
|
|
6348
|
-
resource.description = description;
|
|
6349
|
-
}
|
|
6350
|
-
setKey(context, resource, { key }) {
|
|
6351
|
-
resource.key = key;
|
|
6352
|
-
}
|
|
6353
|
-
setSlug(context, resource, { slug }) {
|
|
6354
|
-
resource.slug = slug;
|
|
6355
|
-
}
|
|
6356
|
-
setStore(context, resource, { store }) {
|
|
6357
|
-
if (store?.key) resource.store = {
|
|
6358
|
-
typeId: "store",
|
|
6359
|
-
key: store.key
|
|
6360
|
-
};
|
|
6361
|
-
if (store?.id) throw new Error("set store on shoppinglist by id not implemented");
|
|
6362
|
-
}
|
|
6363
|
-
};
|
|
6364
|
-
|
|
6365
|
-
//#endregion
|
|
6366
|
-
//#region src/repositories/shopping-list/index.ts
|
|
6367
|
-
var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
6368
|
-
constructor(config) {
|
|
6369
|
-
super("shopping-list", config);
|
|
6370
|
-
this.actions = new ShoppingListUpdateHandler(config.storage);
|
|
6371
|
-
}
|
|
6372
|
-
create(context, draft) {
|
|
6373
|
-
const lineItems = draft.lineItems?.map((draftLineItem) => this.draftLineItemtoLineItem(context.projectKey, draftLineItem)) ?? [];
|
|
6374
|
-
const resource = {
|
|
6375
|
-
...getBaseResourceProperties(),
|
|
6376
|
-
...draft,
|
|
6377
|
-
custom: createCustomFields(draft.custom, context.projectKey, this._storage),
|
|
6378
|
-
textLineItems: [],
|
|
6379
|
-
lineItems,
|
|
6380
|
-
customer: draft.customer ? getReferenceFromResourceIdentifier(draft.customer, context.projectKey, this._storage) : void 0,
|
|
6381
|
-
store: draft.store ? getStoreKeyReference(draft.store, context.projectKey, this._storage) : void 0,
|
|
6382
|
-
businessUnit: draft.businessUnit ? getBusinessUnitKeyReference(draft.businessUnit, context.projectKey, this._storage) : void 0
|
|
6383
|
-
};
|
|
6384
|
-
return this.saveNew(context, resource);
|
|
6385
|
-
}
|
|
6386
|
-
draftLineItemtoLineItem = (projectKey, draftLineItem) => {
|
|
6387
|
-
const { sku, productId, variantId } = draftLineItem;
|
|
6388
|
-
const lineItem = {
|
|
6389
|
-
...getBaseResourceProperties(),
|
|
6390
|
-
...draftLineItem,
|
|
6391
|
-
addedAt: draftLineItem.addedAt ?? "",
|
|
6392
|
-
productId: draftLineItem.productId ?? "",
|
|
6393
|
-
name: {},
|
|
6394
|
-
variantId,
|
|
6395
|
-
published: true,
|
|
6396
|
-
quantity: draftLineItem.quantity ?? 1,
|
|
6397
|
-
productType: {
|
|
6398
|
-
typeId: "product-type",
|
|
6399
|
-
id: ""
|
|
6400
|
-
},
|
|
6401
|
-
custom: createCustomFields(draftLineItem.custom, projectKey, this._storage)
|
|
6402
|
-
};
|
|
6403
|
-
if (productId && variantId) return lineItem;
|
|
6404
|
-
if (sku) {
|
|
6405
|
-
const items = this._storage.query(projectKey, "product", { where: [`masterData(current(masterVariant(sku="${sku}"))) or masterData(current(variants(sku="${sku}")))`] });
|
|
6406
|
-
if (items.count === 0) throw new Error(`Product with sku ${sku} not found`);
|
|
6407
|
-
const product = items.results[0];
|
|
6408
|
-
lineItem.variantId = [product.masterData.current.masterVariant, ...product.masterData.current.variants].find((e) => e.sku === sku)?.id;
|
|
6409
|
-
lineItem.productId = product.id;
|
|
6410
|
-
return lineItem;
|
|
6411
|
-
}
|
|
6412
|
-
if (productId) {
|
|
6413
|
-
const items = this._storage.query(projectKey, "product", { where: [`id="${productId}"`] });
|
|
6414
|
-
if (items.count === 0) throw new Error(`Product with id ${productId} not found`);
|
|
6415
|
-
lineItem.variantId = items.results[0].masterData.current.masterVariant.id;
|
|
6416
|
-
return lineItem;
|
|
6417
|
-
}
|
|
6418
|
-
throw new Error("must provide either sku, productId or variantId for ShoppingListLineItem");
|
|
6419
|
-
};
|
|
6420
|
-
};
|
|
6421
|
-
|
|
6422
6423
|
//#endregion
|
|
6423
6424
|
//#region src/repositories/standalone-price.ts
|
|
6424
6425
|
var StandAlonePriceRepository = class extends AbstractResourceRepository {
|
|
@@ -6774,7 +6775,8 @@ const createRepositories = (config) => ({
|
|
|
6774
6775
|
"as-associate": {
|
|
6775
6776
|
cart: new AsAssociateCartRepository(config),
|
|
6776
6777
|
order: new AsAssociateOrderRepository(config),
|
|
6777
|
-
"quote-request": new AsAssociateQuoteRequestRepository(config)
|
|
6778
|
+
"quote-request": new AsAssociateQuoteRequestRepository(config),
|
|
6779
|
+
"shopping-list": new AsAssociateShoppingListRepository(config)
|
|
6778
6780
|
},
|
|
6779
6781
|
"associate-role": new AssociateRoleRepository(config),
|
|
6780
6782
|
"attribute-group": new AttributeGroupRepository(config),
|
|
@@ -7042,6 +7044,30 @@ var AsAssociateQuoteRequestService = class extends AbstractService {
|
|
|
7042
7044
|
}
|
|
7043
7045
|
};
|
|
7044
7046
|
|
|
7047
|
+
//#endregion
|
|
7048
|
+
//#region src/services/as-associate-shopping-list.ts
|
|
7049
|
+
var AsAssociateShoppingListService = class extends AbstractService {
|
|
7050
|
+
repository;
|
|
7051
|
+
constructor(parent, repository) {
|
|
7052
|
+
super(parent);
|
|
7053
|
+
this.repository = repository;
|
|
7054
|
+
}
|
|
7055
|
+
getBasePath() {
|
|
7056
|
+
return "shopping-lists";
|
|
7057
|
+
}
|
|
7058
|
+
registerRoutes(parent) {
|
|
7059
|
+
const basePath = this.getBasePath();
|
|
7060
|
+
const router = Router({ mergeParams: true });
|
|
7061
|
+
this.extraRoutes(router);
|
|
7062
|
+
router.get("/", this.get.bind(this));
|
|
7063
|
+
router.get("/:id", this.getWithId.bind(this));
|
|
7064
|
+
router.delete("/:id", this.deleteWithId.bind(this));
|
|
7065
|
+
router.post("/", this.post.bind(this));
|
|
7066
|
+
router.post("/:id", this.postWithId.bind(this));
|
|
7067
|
+
parent.use(`/${basePath}`, router);
|
|
7068
|
+
}
|
|
7069
|
+
};
|
|
7070
|
+
|
|
7045
7071
|
//#endregion
|
|
7046
7072
|
//#region src/services/as-associate.ts
|
|
7047
7073
|
var AsAssociateService = class {
|
|
@@ -7052,7 +7078,8 @@ var AsAssociateService = class {
|
|
|
7052
7078
|
this.subServices = {
|
|
7053
7079
|
order: new AsAssociateOrderService(this.router, repositories.order),
|
|
7054
7080
|
cart: new AsAssociateCartService(this.router, repositories.cart),
|
|
7055
|
-
"quote-request": new AsAssociateQuoteRequestService(this.router, repositories["quote-request"])
|
|
7081
|
+
"quote-request": new AsAssociateQuoteRequestService(this.router, repositories["quote-request"]),
|
|
7082
|
+
"shopping-list": new AsAssociateShoppingListService(this.router, repositories["shopping-list"])
|
|
7056
7083
|
};
|
|
7057
7084
|
parent.use("/as-associate/:associateId/in-business-unit/key=:businessUnitId", this.router);
|
|
7058
7085
|
}
|