@unchainedshop/platform 2.0.0-beta8 → 2.0.0-beta9

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.
Files changed (92) hide show
  1. package/jest.config.js +9 -0
  2. package/lib/bulk-importer/handlers/assortment/create.d.ts +3 -4
  3. package/lib/bulk-importer/handlers/assortment/create.js +5 -10
  4. package/lib/bulk-importer/handlers/assortment/create.js.map +1 -1
  5. package/lib/bulk-importer/handlers/assortment/remove.d.ts +2 -2
  6. package/lib/bulk-importer/handlers/assortment/remove.js.map +1 -1
  7. package/lib/bulk-importer/handlers/assortment/update.d.ts +3 -4
  8. package/lib/bulk-importer/handlers/assortment/update.js +4 -8
  9. package/lib/bulk-importer/handlers/assortment/update.js.map +1 -1
  10. package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.d.ts +3 -4
  11. package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.js +8 -5
  12. package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.js.map +1 -1
  13. package/lib/bulk-importer/handlers/assortment/upsertAssortmentContent.d.ts +3 -4
  14. package/lib/bulk-importer/handlers/assortment/upsertAssortmentContent.js +3 -3
  15. package/lib/bulk-importer/handlers/assortment/upsertAssortmentContent.js.map +1 -1
  16. package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.d.ts +3 -4
  17. package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.js +3 -4
  18. package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.js.map +1 -1
  19. package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.d.ts +3 -4
  20. package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.js +6 -5
  21. package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.js.map +1 -1
  22. package/lib/bulk-importer/handlers/assortment/upsertMedia.d.ts +3 -4
  23. package/lib/bulk-importer/handlers/assortment/upsertMedia.js +6 -7
  24. package/lib/bulk-importer/handlers/assortment/upsertMedia.js.map +1 -1
  25. package/lib/bulk-importer/handlers/filter/create.d.ts +3 -4
  26. package/lib/bulk-importer/handlers/filter/create.js +4 -6
  27. package/lib/bulk-importer/handlers/filter/create.js.map +1 -1
  28. package/lib/bulk-importer/handlers/filter/remove.d.ts +2 -2
  29. package/lib/bulk-importer/handlers/filter/remove.js.map +1 -1
  30. package/lib/bulk-importer/handlers/filter/update.d.ts +3 -4
  31. package/lib/bulk-importer/handlers/filter/update.js +3 -4
  32. package/lib/bulk-importer/handlers/filter/update.js.map +1 -1
  33. package/lib/bulk-importer/handlers/filter/upsertFilterContent.d.ts +3 -5
  34. package/lib/bulk-importer/handlers/filter/upsertFilterContent.js +3 -3
  35. package/lib/bulk-importer/handlers/filter/upsertFilterContent.js.map +1 -1
  36. package/lib/bulk-importer/handlers/filter/upsertFilterOptionContent.d.ts +2 -2
  37. package/lib/bulk-importer/handlers/filter/upsertFilterOptionContent.js +2 -2
  38. package/lib/bulk-importer/handlers/filter/upsertFilterOptionContent.js.map +1 -1
  39. package/lib/bulk-importer/handlers/product/create.d.ts +3 -4
  40. package/lib/bulk-importer/handlers/product/create.js +5 -9
  41. package/lib/bulk-importer/handlers/product/create.js.map +1 -1
  42. package/lib/bulk-importer/handlers/product/remove.d.ts +2 -2
  43. package/lib/bulk-importer/handlers/product/remove.js +2 -2
  44. package/lib/bulk-importer/handlers/product/remove.js.map +1 -1
  45. package/lib/bulk-importer/handlers/product/update.d.ts +3 -4
  46. package/lib/bulk-importer/handlers/product/update.js +4 -7
  47. package/lib/bulk-importer/handlers/product/update.js.map +1 -1
  48. package/lib/bulk-importer/handlers/product/upsertMedia.d.ts +3 -4
  49. package/lib/bulk-importer/handlers/product/upsertMedia.js +6 -7
  50. package/lib/bulk-importer/handlers/product/upsertMedia.js.map +1 -1
  51. package/lib/bulk-importer/handlers/product/upsertProductContent.d.ts +3 -4
  52. package/lib/bulk-importer/handlers/product/upsertProductContent.js +3 -3
  53. package/lib/bulk-importer/handlers/product/upsertProductContent.js.map +1 -1
  54. package/lib/bulk-importer/handlers/product/upsertVariations.d.ts +3 -4
  55. package/lib/bulk-importer/handlers/product/upsertVariations.js +16 -13
  56. package/lib/bulk-importer/handlers/product/upsertVariations.js.map +1 -1
  57. package/lib/bulk-importer/upsertAsset.d.ts +2 -2
  58. package/lib/bulk-importer/upsertAsset.js +2 -3
  59. package/lib/bulk-importer/upsertAsset.js.map +1 -1
  60. package/lib/setup/setupAccounts.js +2 -1
  61. package/lib/setup/setupAccounts.js.map +1 -1
  62. package/lib/setup/setupCarts.js.map +1 -1
  63. package/lib/templates/utils/getOrderAttachmentsData.d.ts +2 -2
  64. package/lib/templates/utils/getOrderAttachmentsData.js.map +1 -1
  65. package/lib/templates/utils/getOrderPositionsData.d.ts +2 -2
  66. package/lib/templates/utils/getOrderPositionsData.js.map +1 -1
  67. package/package.json +15 -14
  68. package/src/bulk-importer/handlers/assortment/create.ts +9 -18
  69. package/src/bulk-importer/handlers/assortment/remove.ts +2 -2
  70. package/src/bulk-importer/handlers/assortment/update.ts +5 -13
  71. package/src/bulk-importer/handlers/assortment/upsertAssortmentChildren.ts +9 -18
  72. package/src/bulk-importer/handlers/assortment/upsertAssortmentContent.ts +5 -12
  73. package/src/bulk-importer/handlers/assortment/upsertAssortmentFilters.ts +4 -5
  74. package/src/bulk-importer/handlers/assortment/upsertAssortmentProducts.ts +10 -18
  75. package/src/bulk-importer/handlers/assortment/upsertMedia.ts +13 -20
  76. package/src/bulk-importer/handlers/filter/create.ts +4 -8
  77. package/src/bulk-importer/handlers/filter/remove.ts +2 -2
  78. package/src/bulk-importer/handlers/filter/update.ts +4 -6
  79. package/src/bulk-importer/handlers/filter/upsertFilterContent.ts +5 -15
  80. package/src/bulk-importer/handlers/filter/upsertFilterOptionContent.ts +12 -12
  81. package/src/bulk-importer/handlers/product/create.ts +12 -23
  82. package/src/bulk-importer/handlers/product/remove.ts +4 -4
  83. package/src/bulk-importer/handlers/product/update.ts +7 -14
  84. package/src/bulk-importer/handlers/product/upsertMedia.ts +12 -16
  85. package/src/bulk-importer/handlers/product/upsertProductContent.ts +5 -15
  86. package/src/bulk-importer/handlers/product/upsertVariations.ts +26 -34
  87. package/src/bulk-importer/upsertAsset.ts +4 -5
  88. package/src/setup/setupAccounts.ts +7 -8
  89. package/src/setup/setupCarts.ts +1 -0
  90. package/src/templates/utils/getOrderAttachmentsData.ts +2 -2
  91. package/src/templates/utils/getOrderPositionsData.ts +2 -2
  92. package/tests/platform-index.test.ts +5 -0
@@ -1,4 +1,4 @@
1
- import { Context } from '@unchainedshop/types/api';
1
+ import { UnchainedCore } from '@unchainedshop/types/core';
2
2
  import convertTagsToLowerCase from '../utils/convertTagsToLowerCase';
3
3
  import upsertAssortmentChildren from './upsertAssortmentChildren';
4
4
  import upsertAssortmentContent from './upsertAssortmentContent';
@@ -8,10 +8,10 @@ import upsertMedia from './upsertMedia';
8
8
 
9
9
  export default async function createAssortment(
10
10
  payload: any,
11
- { logger, authorId, createShouldUpsertIfIDExists },
12
- unchainedAPI: Context,
11
+ { logger, createShouldUpsertIfIDExists },
12
+ unchainedAPI: UnchainedCore,
13
13
  ) {
14
- const { modules, userId } = unchainedAPI;
14
+ const { modules } = unchainedAPI;
15
15
  const { media, specification, products, children, filters, _id } = payload;
16
16
  if (!specification) throw new Error(`Specification is required when creating new assortment ${_id}`);
17
17
 
@@ -22,18 +22,13 @@ export default async function createAssortment(
22
22
 
23
23
  logger.debug('create assortment object', specification);
24
24
  try {
25
- await modules.assortments.create({ ...specification, _id, authorId }, userId);
25
+ await modules.assortments.create({ ...specification, _id });
26
26
  } catch (e) {
27
27
  if (!createShouldUpsertIfIDExists) throw e;
28
28
  logger.debug('entity already exists, falling back to update', specification);
29
- await modules.assortments.update(
30
- _id,
31
- {
32
- ...specification,
33
- authorId,
34
- },
35
- userId,
36
- );
29
+ await modules.assortments.update(_id, {
30
+ ...specification,
31
+ });
37
32
  }
38
33
 
39
34
  if (!(await modules.assortments.assortmentExists({ assortmentId: _id }))) {
@@ -45,7 +40,6 @@ export default async function createAssortment(
45
40
  {
46
41
  content: specification.content,
47
42
  assortmentId: _id,
48
- authorId,
49
43
  },
50
44
  unchainedAPI,
51
45
  );
@@ -55,7 +49,6 @@ export default async function createAssortment(
55
49
  {
56
50
  products: products || [],
57
51
  assortmentId: _id,
58
- authorId,
59
52
  },
60
53
  unchainedAPI,
61
54
  );
@@ -65,7 +58,6 @@ export default async function createAssortment(
65
58
  {
66
59
  children: children || [],
67
60
  assortmentId: _id,
68
- authorId,
69
61
  },
70
62
  unchainedAPI,
71
63
  );
@@ -75,13 +67,12 @@ export default async function createAssortment(
75
67
  {
76
68
  filters: filters || [],
77
69
  assortmentId: _id,
78
- authorId,
79
70
  },
80
71
  unchainedAPI,
81
72
  );
82
73
 
83
74
  logger.debug('create assortment media', media);
84
- await upsertMedia({ media: media || [], assortmentId: _id, authorId }, unchainedAPI);
75
+ await upsertMedia({ media: media || [], assortmentId: _id }, unchainedAPI);
85
76
 
86
77
  return {
87
78
  entity: 'ASSORTMENT',
@@ -1,6 +1,6 @@
1
- import { Context } from '@unchainedshop/types/api';
1
+ import { UnchainedCore } from '@unchainedshop/types/core';
2
2
 
3
- export default async function removeAssortment(payload, { logger }, unchainedAPI: Context) {
3
+ export default async function removeAssortment(payload, { logger }, unchainedAPI: UnchainedCore) {
4
4
  const { modules } = unchainedAPI;
5
5
  const { _id } = payload;
6
6
  logger.debug('remove assortment');
@@ -1,4 +1,4 @@
1
- import { Context } from '@unchainedshop/types/api';
1
+ import { UnchainedCore } from '@unchainedshop/types/core';
2
2
  import upsertAssortmentContent from './upsertAssortmentContent';
3
3
  import upsertAssortmentProducts from './upsertAssortmentProducts';
4
4
  import upsertAssortmentChildren from './upsertAssortmentChildren';
@@ -6,12 +6,8 @@ import upsertAssortmentFilters from './upsertAssortmentFilters';
6
6
  import upsertMedia from './upsertMedia';
7
7
  import convertTagsToLowerCase from '../utils/convertTagsToLowerCase';
8
8
 
9
- export default async function updateAssortment(
10
- payload: any,
11
- { logger, authorId },
12
- unchainedAPI: Context,
13
- ) {
14
- const { modules, userId } = unchainedAPI;
9
+ export default async function updateAssortment(payload: any, { logger }, unchainedAPI: UnchainedCore) {
10
+ const { modules } = unchainedAPI;
15
11
  const { media, specification, products, children, filters, _id } = payload;
16
12
 
17
13
  if (!(await modules.assortments.assortmentExists({ assortmentId: _id }))) {
@@ -23,14 +19,13 @@ export default async function updateAssortment(
23
19
 
24
20
  specification.tags = convertTagsToLowerCase(specification?.tags);
25
21
 
26
- await unchainedAPI.modules.assortments.update(_id, { ...specification, authorId }, userId);
22
+ await unchainedAPI.modules.assortments.update(_id, { ...specification });
27
23
  if (specification.content) {
28
24
  logger.debug('replace localized content for assortment', specification.content);
29
25
  await upsertAssortmentContent(
30
26
  {
31
27
  content: specification.content,
32
28
  assortmentId: _id,
33
- authorId,
34
29
  },
35
30
  unchainedAPI,
36
31
  );
@@ -43,7 +38,6 @@ export default async function updateAssortment(
43
38
  {
44
39
  products: products || [],
45
40
  assortmentId: _id,
46
- authorId,
47
41
  },
48
42
  unchainedAPI,
49
43
  );
@@ -55,7 +49,6 @@ export default async function updateAssortment(
55
49
  {
56
50
  children: children || [],
57
51
  assortmentId: _id,
58
- authorId,
59
52
  },
60
53
  unchainedAPI,
61
54
  );
@@ -67,14 +60,13 @@ export default async function updateAssortment(
67
60
  {
68
61
  filters: filters || [],
69
62
  assortmentId: _id,
70
- authorId,
71
63
  },
72
64
  unchainedAPI,
73
65
  );
74
66
  }
75
67
  if (media) {
76
68
  logger.debug('update assortment media', media);
77
- await upsertMedia({ media: media || [], assortmentId: _id, authorId }, unchainedAPI);
69
+ await upsertMedia({ media: media || [], assortmentId: _id }, unchainedAPI);
78
70
  }
79
71
 
80
72
  return {
@@ -1,8 +1,8 @@
1
- import { Context } from '@unchainedshop/types/api';
2
1
  import { AssortmentLink } from '@unchainedshop/types/assortments';
2
+ import { UnchainedCore } from '@unchainedshop/types/core';
3
3
  import convertTagsToLowerCase from '../utils/convertTagsToLowerCase';
4
4
 
5
- const upsert = async (assortmentLink: AssortmentLink, { modules, userId }: Context) => {
5
+ const upsert = async (assortmentLink: AssortmentLink, { modules }: UnchainedCore) => {
6
6
  if (
7
7
  !(await modules.assortments.assortmentExists({
8
8
  assortmentId: assortmentLink.childAssortmentId,
@@ -11,26 +11,18 @@ const upsert = async (assortmentLink: AssortmentLink, { modules, userId }: Conte
11
11
  throw new Error(`Can't link non-existing assortment ${assortmentLink.childAssortmentId}`);
12
12
  }
13
13
  try {
14
- const newAssortmentLink = await modules.assortments.links.create(
15
- assortmentLink,
16
- { skipInvalidation: true },
17
- userId,
18
- );
14
+ const newAssortmentLink = await modules.assortments.links.create(assortmentLink, {
15
+ skipInvalidation: true,
16
+ });
19
17
  return newAssortmentLink;
20
18
  } catch (e) {
21
- return modules.assortments.links.update(
22
- assortmentLink._id,
23
- assortmentLink,
24
- { skipInvalidation: true },
25
- userId,
26
- );
19
+ return modules.assortments.links.update(assortmentLink._id, assortmentLink, {
20
+ skipInvalidation: true,
21
+ });
27
22
  }
28
23
  };
29
24
 
30
- export default async (
31
- { children, authorId, assortmentId: parentAssortmentId },
32
- unchainedAPI: Context,
33
- ) => {
25
+ export default async ({ children, assortmentId: parentAssortmentId }, unchainedAPI: UnchainedCore) => {
34
26
  const { modules } = unchainedAPI;
35
27
  const assortmentLinkIds = await Promise.all(
36
28
  children.map(async ({ assortmentId: childAssortmentId, ...childrenRest }) => {
@@ -39,7 +31,6 @@ export default async (
39
31
  {
40
32
  ...childrenRest,
41
33
  tags,
42
- authorId,
43
34
  parentAssortmentId,
44
35
  childAssortmentId,
45
36
  } as AssortmentLink,
@@ -1,17 +1,10 @@
1
- import { Context } from '@unchainedshop/types/api';
2
1
  import { AssortmentText } from '@unchainedshop/types/assortments';
2
+ import { UnchainedCore } from '@unchainedshop/types/core';
3
3
 
4
- export default async ({ assortmentId, content, authorId }, { modules, userId }: Context) => {
4
+ export default async ({ assortmentId, content }, { modules }: UnchainedCore) => {
5
5
  await Promise.all(
6
- Object.entries(content).map(
7
- async ([locale, { authorId: tAuthorId, ...localizedData }]: [string, AssortmentText]) => {
8
- return modules.assortments.texts.upsertLocalizedText(
9
- assortmentId,
10
- locale,
11
- localizedData,
12
- tAuthorId || authorId || userId,
13
- );
14
- },
15
- ),
6
+ Object.entries(content).map(async ([locale, localizedData]: [string, AssortmentText]) => {
7
+ return modules.assortments.texts.upsertLocalizedText(assortmentId, locale, localizedData);
8
+ }),
16
9
  );
17
10
  };
@@ -1,8 +1,8 @@
1
- import { Context } from '@unchainedshop/types/api';
2
1
  import { AssortmentFilter } from '@unchainedshop/types/assortments';
2
+ import { UnchainedCore } from '@unchainedshop/types/core';
3
3
  import convertTagsToLowerCase from '../utils/convertTagsToLowerCase';
4
4
 
5
- const upsert = async (assortmentFilter: AssortmentFilter, { modules, userId }: Context) => {
5
+ const upsert = async (assortmentFilter: AssortmentFilter, { modules }: UnchainedCore) => {
6
6
  if (
7
7
  !(await modules.filters.filterExists({
8
8
  filterId: assortmentFilter.filterId,
@@ -11,14 +11,14 @@ const upsert = async (assortmentFilter: AssortmentFilter, { modules, userId }: C
11
11
  throw new Error(`Can't link non-existing filter ${assortmentFilter.filterId}`);
12
12
  }
13
13
  try {
14
- const newAssortmentFilter = await modules.assortments.filters.create(assortmentFilter, userId);
14
+ const newAssortmentFilter = await modules.assortments.filters.create(assortmentFilter);
15
15
  return newAssortmentFilter;
16
16
  } catch (e) {
17
17
  return modules.assortments.filters.update(assortmentFilter._id, assortmentFilter);
18
18
  }
19
19
  };
20
20
 
21
- export default async ({ filters, authorId, assortmentId }, unchainedAPI: Context) => {
21
+ export default async ({ filters, assortmentId }, unchainedAPI: UnchainedCore) => {
22
22
  const { modules } = unchainedAPI;
23
23
  const assortmentFilterIds = await Promise.all(
24
24
  filters.map(async (filter: AssortmentFilter) => {
@@ -27,7 +27,6 @@ export default async ({ filters, authorId, assortmentId }, unchainedAPI: Context
27
27
  {
28
28
  ...filter,
29
29
  tags,
30
- authorId,
31
30
  assortmentId,
32
31
  },
33
32
  unchainedAPI,
@@ -1,9 +1,9 @@
1
- import { Context } from '@unchainedshop/types/api';
2
1
  import { AssortmentProduct } from '@unchainedshop/types/assortments';
2
+ import { UnchainedCore } from '@unchainedshop/types/core';
3
3
  import convertTagsToLowerCase from '../utils/convertTagsToLowerCase';
4
4
 
5
- const upsert = async (assortmentProduct: AssortmentProduct, unchainedAPI: Context) => {
6
- const { modules, userId } = unchainedAPI;
5
+ const upsert = async (assortmentProduct: AssortmentProduct, unchainedAPI: UnchainedCore) => {
6
+ const { modules } = unchainedAPI;
7
7
  if (
8
8
  !(await modules.products.productExists({
9
9
  productId: assortmentProduct.productId,
@@ -12,25 +12,18 @@ const upsert = async (assortmentProduct: AssortmentProduct, unchainedAPI: Contex
12
12
  throw new Error(`Can't link non-existing product ${assortmentProduct.productId}`);
13
13
  }
14
14
  try {
15
- const newAssortmentProduct = await modules.assortments.products.create(
16
- assortmentProduct,
17
- {
18
- skipInvalidation: true,
19
- },
20
- userId,
21
- );
15
+ const newAssortmentProduct = await modules.assortments.products.create(assortmentProduct, {
16
+ skipInvalidation: true,
17
+ });
22
18
  return newAssortmentProduct;
23
19
  } catch (e) {
24
- return modules.assortments.products.update(
25
- assortmentProduct._id,
26
- assortmentProduct,
27
- { skipInvalidation: true },
28
- userId,
29
- );
20
+ return modules.assortments.products.update(assortmentProduct._id, assortmentProduct, {
21
+ skipInvalidation: true,
22
+ });
30
23
  }
31
24
  };
32
25
 
33
- export default async ({ products, authorId, assortmentId }, unchainedAPI: Context) => {
26
+ export default async ({ products, assortmentId }, unchainedAPI: UnchainedCore) => {
34
27
  const { modules } = unchainedAPI;
35
28
  const assortmentProductIds = await Promise.all(
36
29
  products.map(async (product: AssortmentProduct) => {
@@ -38,7 +31,6 @@ export default async ({ products, authorId, assortmentId }, unchainedAPI: Contex
38
31
  const assortmentProduct = await upsert(
39
32
  {
40
33
  ...product,
41
- authorId,
42
34
  tags,
43
35
  assortmentId,
44
36
  },
@@ -1,11 +1,11 @@
1
- import { Context } from '@unchainedshop/types/api';
2
1
  import { AssortmentMediaText } from '@unchainedshop/types/assortments.media';
2
+ import { UnchainedCore } from '@unchainedshop/types/core';
3
3
  import upsertAsset from '../../upsertAsset';
4
4
 
5
- const upsertMediaObject = async (media, unchainedAPI: Context) => {
6
- const { modules, userId } = unchainedAPI;
5
+ const upsertMediaObject = async (media, unchainedAPI: UnchainedCore) => {
6
+ const { modules } = unchainedAPI;
7
7
  try {
8
- const assortmentMedia = await modules.assortments.media.create(media, userId);
8
+ const assortmentMedia = await modules.assortments.media.create(media);
9
9
  return assortmentMedia;
10
10
  } catch (e) {
11
11
  const { _id, ...mediaData } = media;
@@ -13,8 +13,8 @@ const upsertMediaObject = async (media, unchainedAPI: Context) => {
13
13
  }
14
14
  };
15
15
 
16
- export default async ({ media, authorId, assortmentId }, unchainedAPI: Context) => {
17
- const { modules, userId } = unchainedAPI;
16
+ export default async ({ media, assortmentId }, unchainedAPI: UnchainedCore) => {
17
+ const { modules } = unchainedAPI;
18
18
  const mediaObjects = await Promise.all(
19
19
  media.map(async ({ asset, content, ...mediaData }) => {
20
20
  const file = await upsertAsset(
@@ -26,7 +26,6 @@ export default async ({ media, authorId, assortmentId }, unchainedAPI: Context)
26
26
 
27
27
  const mediaObject = await upsertMediaObject(
28
28
  {
29
- authorId,
30
29
  ...mediaData,
31
30
  assortmentId,
32
31
  mediaId: file._id,
@@ -38,19 +37,13 @@ export default async ({ media, authorId, assortmentId }, unchainedAPI: Context)
38
37
 
39
38
  if (content) {
40
39
  await Promise.all(
41
- Object.entries(content).map(
42
- async ([locale, { authorId: tAuthorId, ...localizedData }]: [
43
- string,
44
- AssortmentMediaText,
45
- ]) => {
46
- return modules.assortments.media.texts.upsertLocalizedText(
47
- mediaObject._id,
48
- locale,
49
- localizedData,
50
- tAuthorId || authorId || userId,
51
- );
52
- },
53
- ),
40
+ Object.entries(content).map(async ([locale, localizedData]: [string, AssortmentMediaText]) => {
41
+ return modules.assortments.media.texts.upsertLocalizedText(
42
+ mediaObject._id,
43
+ locale,
44
+ localizedData,
45
+ );
46
+ }),
54
47
  );
55
48
  }
56
49
  return mediaObject;
@@ -1,11 +1,11 @@
1
- import { Context } from '@unchainedshop/types/api';
1
+ import { UnchainedCore } from '@unchainedshop/types/core';
2
2
  import upsertFilterContent from './upsertFilterContent';
3
3
  import upsertFilterOptionContent from './upsertFilterOptionContent';
4
4
 
5
5
  export default async function createFilter(
6
6
  payload: any,
7
- { logger, authorId, createShouldUpsertIfIDExists },
8
- unchainedAPI: Context,
7
+ { logger, createShouldUpsertIfIDExists },
8
+ unchainedAPI: UnchainedCore,
9
9
  ) {
10
10
  const { modules } = unchainedAPI;
11
11
  const { specification, _id } = payload;
@@ -23,11 +23,9 @@ export default async function createFilter(
23
23
  ...filterData,
24
24
  _id,
25
25
  options: options?.map((option) => option.value) || [],
26
- authorId,
27
26
  },
28
27
  unchainedAPI,
29
28
  { skipInvalidation: true },
30
- unchainedAPI.userId,
31
29
  );
32
30
  } catch (e) {
33
31
  if (!createShouldUpsertIfIDExists) throw e;
@@ -38,11 +36,9 @@ export default async function createFilter(
38
36
  {
39
37
  ...filterData,
40
38
  options: options?.map((option) => option.value) || [],
41
- authorId,
42
39
  },
43
40
  unchainedAPI,
44
41
  { skipInvalidation: true },
45
- unchainedAPI.userId,
46
42
  );
47
43
  }
48
44
 
@@ -51,7 +47,7 @@ export default async function createFilter(
51
47
  }
52
48
 
53
49
  logger.debug('create localized content for filter', content);
54
- await upsertFilterContent({ content, filterId: _id, authorId }, unchainedAPI);
50
+ await upsertFilterContent({ content, filterId: _id }, unchainedAPI);
55
51
 
56
52
  logger.debug('create localized content for filter options', content);
57
53
  await upsertFilterOptionContent({ options, filterId: _id }, unchainedAPI);
@@ -1,6 +1,6 @@
1
- import { Context } from '@unchainedshop/types/api';
1
+ import { UnchainedCore } from '@unchainedshop/types/core';
2
2
 
3
- export default async function removeFilter(payload: any, { logger }, unchainedAPI: Context) {
3
+ export default async function removeFilter(payload: any, { logger }, unchainedAPI: UnchainedCore) {
4
4
  const { modules } = unchainedAPI;
5
5
  const { _id } = payload;
6
6
  logger.debug('remove filter');
@@ -1,11 +1,11 @@
1
- import { Context } from '@unchainedshop/types/api';
1
+ import { UnchainedCore } from '@unchainedshop/types/core';
2
2
  import upsertFilterContent from './upsertFilterContent';
3
3
  import upsertFilterOptionContent from './upsertFilterOptionContent';
4
4
 
5
5
  export default async function updateFilter(
6
6
  payload: any,
7
- { authorId, logger }: { authorId: string; logger: any },
8
- unchainedAPI: Context,
7
+ { logger }: { logger: any },
8
+ unchainedAPI: UnchainedCore,
9
9
  ) {
10
10
  const { modules } = unchainedAPI;
11
11
  const { specification, _id } = payload;
@@ -23,17 +23,15 @@ export default async function updateFilter(
23
23
  {
24
24
  ...filterData,
25
25
  options: options?.map((option) => option.value) || [],
26
- authorId,
27
26
  },
28
27
  unchainedAPI,
29
28
  { skipInvalidation: true },
30
- unchainedAPI.userId,
31
29
  );
32
30
  }
33
31
 
34
32
  if (content) {
35
33
  logger.debug('replace localized content for filter', content);
36
- await upsertFilterContent({ content, filterId: _id, authorId }, unchainedAPI);
34
+ await upsertFilterContent({ content, filterId: _id }, unchainedAPI);
37
35
  }
38
36
 
39
37
  if (options) {
@@ -1,20 +1,10 @@
1
- import { Context } from '@unchainedshop/types/api';
1
+ import { UnchainedCore } from '@unchainedshop/types/core';
2
2
  import { FilterText } from '@unchainedshop/types/filters';
3
3
 
4
- export default async function upsertFilterContent(
5
- { content, filterId, authorId },
6
- unchainedAPI: Context,
7
- ) {
4
+ export default async function upsertFilterContent({ content, filterId }, unchainedAPI: UnchainedCore) {
8
5
  return Promise.all(
9
- Object.entries(content).map(
10
- async ([locale, { authorId: tAuthorId, ...localizedData }]: [string, FilterText]) => {
11
- return unchainedAPI.modules.filters.texts.upsertLocalizedText(
12
- { filterId },
13
- locale,
14
- localizedData,
15
- tAuthorId || authorId || unchainedAPI.userId,
16
- );
17
- },
18
- ),
6
+ Object.entries(content).map(async ([locale, localizedData]: [string, FilterText]) => {
7
+ return unchainedAPI.modules.filters.texts.upsertLocalizedText({ filterId }, locale, localizedData);
8
+ }),
19
9
  );
20
10
  }
@@ -1,20 +1,20 @@
1
- import { Context } from '@unchainedshop/types/api';
1
+ import { UnchainedCore } from '@unchainedshop/types/core';
2
2
  import { FilterText } from '@unchainedshop/types/filters';
3
3
 
4
- export default async function upsertFilterOptionContent({ options, filterId }, unchainedAPI: Context) {
4
+ export default async function upsertFilterOptionContent(
5
+ { options, filterId },
6
+ unchainedAPI: UnchainedCore,
7
+ ) {
5
8
  return Promise.all(
6
9
  (options || []).map(async ({ content: optionContent, value: optionValue }) => {
7
10
  await Promise.all(
8
- Object.entries(optionContent).map(
9
- async ([locale, { authorId, ...localizedData }]: [string, FilterText]) => {
10
- return unchainedAPI.modules.filters.texts.upsertLocalizedText(
11
- { filterId, filterOptionValue: optionValue },
12
- locale,
13
- localizedData,
14
- authorId || unchainedAPI.userId,
15
- );
16
- },
17
- ),
11
+ Object.entries(optionContent).map(async ([locale, localizedData]: [string, FilterText]) => {
12
+ return unchainedAPI.modules.filters.texts.upsertLocalizedText(
13
+ { filterId, filterOptionValue: optionValue },
14
+ locale,
15
+ localizedData,
16
+ );
17
+ }),
18
18
  );
19
19
  }),
20
20
  );
@@ -1,4 +1,4 @@
1
- import { Context } from '@unchainedshop/types/api';
1
+ import { UnchainedCore } from '@unchainedshop/types/core';
2
2
  import upsertVariations from './upsertVariations';
3
3
  import upsertMedia from './upsertMedia';
4
4
  import upsertProductContent from './upsertProductContent';
@@ -6,10 +6,10 @@ import transformSpecificationToProductStructure from './transformSpecificationTo
6
6
 
7
7
  export default async function createProduct(
8
8
  payload: any,
9
- { logger, authorId, createShouldUpsertIfIDExists },
10
- unchainedAPI: Context,
9
+ { logger, createShouldUpsertIfIDExists },
10
+ unchainedAPI: UnchainedCore,
11
11
  ) {
12
- const { modules, userId } = unchainedAPI;
12
+ const { modules } = unchainedAPI;
13
13
  const { specification, media, variations, _id } = payload;
14
14
 
15
15
  if (!specification) throw new Error(`Specification is required when creating new product ${_id}`);
@@ -19,26 +19,17 @@ export default async function createProduct(
19
19
  const productData = transformSpecificationToProductStructure(specification);
20
20
  logger.debug('create product object', productData);
21
21
  try {
22
- await modules.products.create(
23
- {
24
- ...productData,
25
- _id,
26
- authorId,
27
- },
28
- userId,
29
- );
22
+ await modules.products.create({
23
+ ...productData,
24
+ _id,
25
+ });
30
26
  } catch (e) {
31
27
  if (!createShouldUpsertIfIDExists) throw e;
32
28
 
33
29
  logger.debug('entity already exists, falling back to update', specification);
34
- await modules.products.update(
35
- _id,
36
- {
37
- ...productData,
38
- authorId,
39
- },
40
- userId,
41
- );
30
+ await modules.products.update(_id, {
31
+ ...productData,
32
+ });
42
33
  }
43
34
 
44
35
  if (!(await modules.products.productExists({ productId: _id }))) {
@@ -50,7 +41,6 @@ export default async function createProduct(
50
41
  {
51
42
  content: specification.content,
52
43
  productId: _id,
53
- authorId,
54
44
  },
55
45
  unchainedAPI,
56
46
  );
@@ -60,13 +50,12 @@ export default async function createProduct(
60
50
  {
61
51
  variations: variations || [],
62
52
  productId: _id,
63
- authorId,
64
53
  },
65
54
  unchainedAPI,
66
55
  );
67
56
 
68
57
  logger.debug('create product media', media);
69
- await upsertMedia({ media: media || [], productId: _id, authorId }, unchainedAPI);
58
+ await upsertMedia({ media: media || [], productId: _id }, unchainedAPI);
70
59
 
71
60
  return {
72
61
  entity: 'PRODUCT',
@@ -1,11 +1,11 @@
1
- import { Context } from '@unchainedshop/types/api';
1
+ import { UnchainedCore } from '@unchainedshop/types/core';
2
2
 
3
- export default async function removeProduct(payload: any, { logger }, unchainedAPI: Context) {
4
- const { services, userId } = unchainedAPI;
3
+ export default async function removeProduct(payload: any, { logger }, unchainedAPI: UnchainedCore) {
4
+ const { services } = unchainedAPI;
5
5
  const { _id } = payload;
6
6
  logger.debug(`remove product ${_id}`);
7
7
 
8
- await services.products.removeProduct({ productId: _id, userId }, unchainedAPI);
8
+ await services.products.removeProduct({ productId: _id }, unchainedAPI);
9
9
 
10
10
  return {
11
11
  entity: 'PRODUCT',