@ozdao/martyrs 0.2.473 → 0.2.474

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 (134) hide show
  1. package/dist/{Media-DW8RLbfM.js → Media-_vz04tII.js} +1 -1
  2. package/dist/{Media-y_TX6us_.mjs → Media-sGk7Bp9b.mjs} +1 -1
  3. package/dist/auth.server.js +6 -2
  4. package/dist/auth.server.mjs +6 -2
  5. package/dist/authJwt-CELQKF2s.js +82 -0
  6. package/dist/authJwt-DnXu3BFq.mjs +83 -0
  7. package/dist/builder.js +7 -4
  8. package/dist/builder.mjs +7 -4
  9. package/dist/chats.server.js +1 -1
  10. package/dist/chats.server.mjs +1 -1
  11. package/dist/community.server.js +4 -4
  12. package/dist/community.server.mjs +4 -4
  13. package/dist/events.server.js +4 -4
  14. package/dist/events.server.mjs +4 -4
  15. package/dist/files.server.js +1 -1
  16. package/dist/files.server.mjs +1 -1
  17. package/dist/gallery.server.js +3 -3
  18. package/dist/gallery.server.mjs +3 -3
  19. package/dist/{globals.abac-DT0VjfaZ.js → globals.abac-Bn-4tbX8.js} +110 -16
  20. package/dist/{globals.abac-CvmZM8XG.mjs → globals.abac-DZpTRxKR.mjs} +110 -16
  21. package/dist/globals.server.js +70 -10
  22. package/dist/globals.server.mjs +70 -10
  23. package/dist/{globals.verifier-C_VZYebB.mjs → globals.verifier-BdJxc8-8.mjs} +34 -0
  24. package/dist/{globals.verifier-ChDpCdy_.js → globals.verifier-CKYpYfQl.js} +34 -0
  25. package/dist/{index-CVXl1rB5.js → index-BOmxJQ5W.js} +7 -86
  26. package/dist/{index-Df8vtZx7.mjs → index-C_Fw0Umg.mjs} +7 -86
  27. package/dist/{main-CgmHzhq5.mjs → main-CqMtW7Hq.mjs} +274 -276
  28. package/dist/{main-CCfQH-Dd.js → main-CsGkbSyK.js} +2 -2
  29. package/dist/martyrs/src/components/Select/Select.vue.cjs +4 -4
  30. package/dist/martyrs/src/components/Select/Select.vue.cjs.map +1 -1
  31. package/dist/martyrs/src/components/Select/Select.vue.js +4 -4
  32. package/dist/martyrs/src/components/Select/Select.vue.js.map +1 -1
  33. package/dist/martyrs/src/modules/community/community.client.js +27 -27
  34. package/dist/martyrs/src/modules/community/community.client.js.map +1 -1
  35. package/dist/martyrs/src/modules/community/components/sections/HotPosts.vue.cjs +2 -3
  36. package/dist/martyrs/src/modules/community/components/sections/HotPosts.vue.cjs.map +1 -1
  37. package/dist/martyrs/src/modules/community/components/sections/HotPosts.vue.js +2 -3
  38. package/dist/martyrs/src/modules/community/components/sections/HotPosts.vue.js.map +1 -1
  39. package/dist/martyrs/src/modules/orders/components/pages/OrderCreate.vue.cjs +88 -27
  40. package/dist/martyrs/src/modules/orders/components/pages/OrderCreate.vue.cjs.map +1 -1
  41. package/dist/martyrs/src/modules/orders/components/pages/OrderCreate.vue.js +89 -28
  42. package/dist/martyrs/src/modules/orders/components/pages/OrderCreate.vue.js.map +1 -1
  43. package/dist/martyrs/src/modules/orders/store/shopcart.cjs +1 -0
  44. package/dist/martyrs/src/modules/orders/store/shopcart.cjs.map +1 -1
  45. package/dist/martyrs/src/modules/orders/store/shopcart.js +1 -0
  46. package/dist/martyrs/src/modules/orders/store/shopcart.js.map +1 -1
  47. package/dist/martyrs/src/modules/products/components/pages/CategoryEdit.vue.cjs +19 -0
  48. package/dist/martyrs/src/modules/products/components/pages/CategoryEdit.vue.cjs.map +1 -1
  49. package/dist/martyrs/src/modules/products/components/pages/CategoryEdit.vue.js +19 -0
  50. package/dist/martyrs/src/modules/products/components/pages/CategoryEdit.vue.js.map +1 -1
  51. package/dist/martyrs/src/modules/products/components/pages/Product.vue.cjs +1 -0
  52. package/dist/martyrs/src/modules/products/components/pages/Product.vue.cjs.map +1 -1
  53. package/dist/martyrs/src/modules/products/components/pages/Product.vue.js +1 -0
  54. package/dist/martyrs/src/modules/products/components/pages/Product.vue.js.map +1 -1
  55. package/dist/martyrs/src/modules/products/components/pages/ProductEdit.vue.cjs +2 -2
  56. package/dist/martyrs/src/modules/products/components/pages/ProductEdit.vue.cjs.map +1 -1
  57. package/dist/martyrs/src/modules/products/components/pages/ProductEdit.vue.js +2 -2
  58. package/dist/martyrs/src/modules/products/components/pages/ProductEdit.vue.js.map +1 -1
  59. package/dist/martyrs/src/modules/products/store/categories.cjs +2 -0
  60. package/dist/martyrs/src/modules/products/store/categories.cjs.map +1 -1
  61. package/dist/martyrs/src/modules/products/store/categories.js +2 -0
  62. package/dist/martyrs/src/modules/products/store/categories.js.map +1 -1
  63. package/dist/martyrs/src/modules/spots/components/pages/SpotEdit.vue.cjs +30 -24
  64. package/dist/martyrs/src/modules/spots/components/pages/SpotEdit.vue.cjs.map +1 -1
  65. package/dist/martyrs/src/modules/spots/components/pages/SpotEdit.vue.js +30 -24
  66. package/dist/martyrs/src/modules/spots/components/pages/SpotEdit.vue.js.map +1 -1
  67. package/dist/martyrs/src/modules/spots/components/sections/WorktimeEdit.vue.cjs +807 -0
  68. package/dist/martyrs/src/modules/spots/components/sections/WorktimeEdit.vue.cjs.map +1 -0
  69. package/dist/martyrs/src/modules/spots/components/sections/WorktimeEdit.vue.js +807 -0
  70. package/dist/martyrs/src/modules/spots/components/sections/WorktimeEdit.vue.js.map +1 -0
  71. package/dist/martyrs/src/modules/spots/store/spots.cjs +4 -1
  72. package/dist/martyrs/src/modules/spots/store/spots.cjs.map +1 -1
  73. package/dist/martyrs/src/modules/spots/store/spots.js +4 -1
  74. package/dist/martyrs/src/modules/spots/store/spots.js.map +1 -1
  75. package/dist/martyrs.cjs.js +1 -1
  76. package/dist/martyrs.css +1 -1
  77. package/dist/martyrs.es.js +1 -1
  78. package/dist/notifications.server.js +1 -1
  79. package/dist/notifications.server.mjs +1 -1
  80. package/dist/orders.server.js +5 -4
  81. package/dist/orders.server.mjs +5 -4
  82. package/dist/organizations.server.js +120 -47
  83. package/dist/organizations.server.mjs +120 -47
  84. package/dist/{ownership.schema-C0w02Vw1.mjs → ownership.schema-CNCotD3D.mjs} +10 -4
  85. package/dist/{ownership.schema-Ck2H9clB.js → ownership.schema-MxfJlPtq.js} +10 -4
  86. package/dist/products.server.js +415 -149
  87. package/dist/products.server.mjs +415 -149
  88. package/dist/{profile.schema-h61hhB2w.js → profile.schema-BLSuV_VC.js} +0 -4
  89. package/dist/{profile.schema-kP_zKXNt.mjs → profile.schema-BRuvQ7QV.mjs} +0 -4
  90. package/dist/{queryProcessor-CWnMIe2U.mjs → queryProcessor-CVKI651_.mjs} +62 -8
  91. package/dist/{queryProcessor-D6GuKfTV.js → queryProcessor-DSUqSk3I.js} +62 -8
  92. package/dist/rents.server.js +4 -4
  93. package/dist/rents.server.mjs +4 -4
  94. package/dist/spots.server.js +162 -8
  95. package/dist/spots.server.mjs +162 -8
  96. package/dist/style.css +27 -4
  97. package/dist/wallet.server.js +2 -2
  98. package/dist/wallet.server.mjs +2 -2
  99. package/package.json +1 -1
  100. package/src/builder/rspack/rspack.config.base.js +1 -1
  101. package/src/builder/rspack/rspack.config.client.js +13 -5
  102. package/src/components/Select/Select.vue +4 -2
  103. package/src/modules/auth/models/user.model.js +4 -1
  104. package/src/modules/community/components/sections/HotPosts.vue +1 -1
  105. package/src/modules/globals/controllers/classes/globals.abac.js +148 -23
  106. package/src/modules/globals/controllers/classes/globals.validator.js +37 -0
  107. package/src/modules/globals/controllers/classes/globals.verifier.js +2 -0
  108. package/src/modules/globals/controllers/policies/globals.policies.js +91 -74
  109. package/src/modules/globals/controllers/utils/queryProcessor.js +59 -11
  110. package/src/modules/globals/models/schemas/ownership.schema.js +11 -6
  111. package/src/modules/globals/models/schemas/profile.schema.js +0 -4
  112. package/src/modules/music/components/layouts/MusicLayout.vue +10 -58
  113. package/src/modules/music/components/pages/MusicHome.vue +5 -5
  114. package/src/modules/orders/components/pages/OrderCreate.vue +85 -12
  115. package/src/modules/orders/controllers/orders.controller.js +3 -0
  116. package/src/modules/orders/store/shopcart.js +1 -0
  117. package/src/modules/organizations/models/schemas/accesses.schema.js +18 -0
  118. package/src/modules/organizations/policies/organizations.policies.js +117 -61
  119. package/src/modules/products/components/pages/CategoryEdit.vue +27 -2
  120. package/src/modules/products/components/pages/Product.vue +1 -0
  121. package/src/modules/products/components/pages/ProductEdit.vue +2 -2
  122. package/src/modules/products/controllers/categories.controller.js +297 -133
  123. package/src/modules/products/middlewares/categories.verifier.js +177 -0
  124. package/src/modules/products/models/category.model.js +12 -14
  125. package/src/modules/products/routes/categories.routes.js +50 -11
  126. package/src/modules/products/store/categories.js +2 -0
  127. package/src/modules/spots/components/pages/SpotEdit.vue +21 -17
  128. package/src/modules/spots/components/sections/WorktimeEdit.vue +840 -0
  129. package/src/modules/spots/controllers/queries/getIsOpenNowStage.js +109 -0
  130. package/src/modules/spots/controllers/spots.controller.js +2 -1
  131. package/src/modules/spots/models/spot.model.js +59 -13
  132. package/src/modules/spots/store/spots.js +4 -1
  133. package/src/modules/products/middlewares/index.js +0 -11
  134. package/src/modules/products/middlewares/verifyCategory.js +0 -25
@@ -1,4 +1,4 @@
1
- import { ref, computed, onMounted, watch, createElementBlock, openBlock, createBlock, createCommentVNode, createElementVNode, createVNode, Fragment, renderList, unref, withCtx, createTextVNode } from "vue";
1
+ import { ref, computed, onMounted, watch, createElementBlock, openBlock, createBlock, createCommentVNode, createElementVNode, unref, toDisplayString, createVNode, Fragment, renderList, withCtx, createTextVNode } from "vue";
2
2
  import _sfc_main$9 from "../../../../components/Button/Button.vue2.js";
3
3
  import _sfc_main$7 from "../blocks/CardOrderItem.vue.js";
4
4
  import _sfc_main$1 from "../sections/AskToLogin.vue.js";
@@ -18,17 +18,30 @@ import { state, getters as getters$1, mutations, actions as actions$3 } from "..
18
18
  import { state as state$1, actions } from "../../../auth/views/store/users.js";
19
19
  /* empty css */
20
20
  const _hoisted_1 = { class: "bg-white pd-thin" };
21
- const _hoisted_2 = { class: "gap-small mn-b-thin cols-2" };
21
+ const _hoisted_2 = {
22
+ key: 3,
23
+ class: "w-100 gap-thin cols-1 mn-b-thin"
24
+ };
22
25
  const _hoisted_3 = {
23
- key: 2,
24
- class: "rows-1 gap-thin"
26
+ key: 0,
27
+ class: "bg-fifth-nano pd-small radius-medium t-center"
25
28
  };
26
29
  const _hoisted_4 = {
27
- key: 3,
30
+ key: 1,
31
+ class: "bg-fourth-nano pd-small radius-medium t-center"
32
+ };
33
+ const _hoisted_5 = { class: "t-fourth" };
34
+ const _hoisted_6 = { class: "gap-small mn-b-thin cols-2" };
35
+ const _hoisted_7 = {
36
+ key: 0,
37
+ class: "rows-1 gap-thin"
38
+ };
39
+ const _hoisted_8 = {
40
+ key: 1,
28
41
  class: "bg-white br-solid br-light br-1px pd-medium radius-medium"
29
42
  };
30
- const _hoisted_5 = { class: "flex gap-thin flex-wrap mn-b-thin" };
31
- const _hoisted_6 = { class: "mn-b-thin" };
43
+ const _hoisted_9 = { class: "flex gap-thin flex-wrap mn-b-thin" };
44
+ const _hoisted_10 = { class: "mn-b-thin" };
32
45
  const _sfc_main = {
33
46
  __name: "OrderCreate",
34
47
  emits: ["page-loading", "page-loaded"],
@@ -37,7 +50,7 @@ const _sfc_main = {
37
50
  const isLocationLoading = ref(false);
38
51
  useRoute();
39
52
  const router = useRouter();
40
- const { returnCurrency } = useGlobalMixins();
53
+ const { returnCurrency, formatPrice } = useGlobalMixins();
41
54
  const order = computed(() => state.current);
42
55
  computed(() => state$1.current);
43
56
  const cartTotalPrice = getters.cartTotalPrice;
@@ -49,12 +62,46 @@ const _sfc_main = {
49
62
  return getters$1.getDeliveryPrice(type, distance, config);
50
63
  });
51
64
  const orderOrganization = ref({});
65
+ const spotOrganization = ref({});
66
+ const isOpen = ref(true);
67
+ const minOrderAmount = ref(0);
68
+ function checkIsOpenNow(worktime) {
69
+ var _a, _b, _c;
70
+ try {
71
+ console.log("[checkIsOpenNow] worktime:", worktime);
72
+ if (!worktime || typeof worktime !== "object" || Array.isArray(worktime) || !worktime.regular) {
73
+ console.log("[checkIsOpenNow] invalid, returning true");
74
+ return true;
75
+ }
76
+ const now = /* @__PURE__ */ new Date();
77
+ const currentDay = now.getDay();
78
+ const currentTime = `${String(now.getHours()).padStart(2, "0")}:${String(now.getMinutes()).padStart(2, "0")}`;
79
+ const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
80
+ console.log("[checkIsOpenNow] currentDay:", currentDay);
81
+ console.log("[checkIsOpenNow] currentTime:", currentTime);
82
+ const specialDay = (_a = worktime.special) == null ? void 0 : _a.find((s) => {
83
+ const d = new Date(s.date);
84
+ return d.getFullYear() === today.getFullYear() && d.getMonth() === today.getMonth() && d.getDate() === today.getDate();
85
+ });
86
+ if (specialDay) {
87
+ console.log("[checkIsOpenNow] specialDay:", specialDay);
88
+ if (!specialDay.isOpen) return false;
89
+ return (_b = specialDay.periods) == null ? void 0 : _b.some((p) => p.open <= currentTime && p.close > currentTime);
90
+ }
91
+ const regularDay = worktime.regular.find((d) => d.dayOfWeek === currentDay);
92
+ if (!regularDay || !regularDay.isOpen) return false;
93
+ return (_c = regularDay.periods) == null ? void 0 : _c.some((p) => p.open <= currentTime && p.close > currentTime);
94
+ } catch (err) {
95
+ console.error("[checkIsOpenNow] error:", err);
96
+ return true;
97
+ }
98
+ }
52
99
  if (!state$2.options.orders.allowUnauthenticatedOrders && !state$3.user._id) {
53
100
  router.push({ name: "Sign In" });
54
101
  }
55
102
  mutations.resetOrder();
56
103
  onMounted(async () => {
57
- var _a, _b, _c;
104
+ var _a, _b, _c, _d, _e;
58
105
  emits("page-loading");
59
106
  isLocationLoading.value = true;
60
107
  if (state$3.user._id) {
@@ -68,6 +115,12 @@ const _sfc_main = {
68
115
  location: (_a = state$2.position) == null ? void 0 : _a.location,
69
116
  lookup: ["spots"]
70
117
  });
118
+ if (orderOrganization.value && ((_c = (_b = orderOrganization.value[0]) == null ? void 0 : _b.spots) == null ? void 0 : _c.length) > 0) {
119
+ spotOrganization.value = orderOrganization.value[0].spots[0];
120
+ isOpen.value = checkIsOpenNow(spotOrganization.value.worktime);
121
+ console.log(spotOrganization.value);
122
+ minOrderAmount.value = spotOrganization.value || 0;
123
+ }
71
124
  isLocationLoading.value = false;
72
125
  emits("page-loaded");
73
126
  if (typeof gtag === "function") {
@@ -76,18 +129,18 @@ const _sfc_main = {
76
129
  // Замените на вашу валюту
77
130
  value: cartTotalPrice || 0,
78
131
  items: state$4.positions.map((item) => {
79
- var _a2, _b2, _c2, _d;
132
+ var _a2, _b2, _c2, _d2;
80
133
  return {
81
134
  item_id: (_a2 = item.product) == null ? void 0 : _a2._id,
82
135
  item_name: (_b2 = item.product) == null ? void 0 : _b2.name,
83
136
  price: item.price || 0,
84
137
  quantity: item.quantity || 1,
85
138
  item_category: ((_c2 = item.product) == null ? void 0 : _c2.category) || "",
86
- item_brand: ((_d = orderOrganization.value.profile) == null ? void 0 : _d.name) || ""
139
+ item_brand: ((_d2 = orderOrganization.value.profile) == null ? void 0 : _d2.name) || ""
87
140
  };
88
141
  }),
89
- organization: ((_b = orderOrganization.value.profile) == null ? void 0 : _b.name) || "",
90
- location: ((_c = state$2.position) == null ? void 0 : _c.location) || "unknown"
142
+ organization: ((_d = orderOrganization.value.profile) == null ? void 0 : _d.name) || "",
143
+ location: ((_e = state$2.position) == null ? void 0 : _e.location) || "unknown"
91
144
  });
92
145
  }
93
146
  });
@@ -217,13 +270,21 @@ const _sfc_main = {
217
270
  key: 0,
218
271
  class: "mn-b-thin"
219
272
  })) : createCommentVNode("", true),
220
- createElementVNode("div", _hoisted_2, [
221
- state$4.positions < 1 ? (openBlock(), createBlock(_sfc_main$2, { key: 0 })) : createCommentVNode("", true),
222
- order.value.status === true && state$4.positions.length > 0 ? (openBlock(), createBlock(_sfc_main$3, {
223
- key: 1,
224
- order: order.value
225
- }, null, 8, ["order"])) : createCommentVNode("", true),
226
- state.current.status !== true && state$4.positions.length > 0 ? (openBlock(), createElementBlock("div", _hoisted_3, [
273
+ state$4.positions < 1 ? (openBlock(), createBlock(_sfc_main$2, { key: 1 })) : createCommentVNode("", true),
274
+ order.value.status === true && state$4.positions.length > 0 ? (openBlock(), createBlock(_sfc_main$3, {
275
+ key: 2,
276
+ order: order.value
277
+ }, null, 8, ["order"])) : createCommentVNode("", true),
278
+ state$4.positions.length > 0 && state.current.status !== true ? (openBlock(), createElementBlock("div", _hoisted_2, [
279
+ !isOpen.value ? (openBlock(), createElementBlock("div", _hoisted_3, _cache[0] || (_cache[0] = [
280
+ createElementVNode("p", { class: "t-fourth" }, "⚠️ This spot is currently closed. You can place an order, but it will be processed when the spot opens.", -1)
281
+ ]))) : createCommentVNode("", true),
282
+ unref(cartTotalPrice) < minOrderAmount.value ? (openBlock(), createElementBlock("div", _hoisted_4, [
283
+ createElementVNode("p", _hoisted_5, "⚠️ Minimum order amount is " + toDisplayString(unref(formatPrice)(minOrderAmount.value)) + ". Your current total is " + toDisplayString(unref(formatPrice)(unref(cartTotalPrice))) + ".", 1)
284
+ ])) : createCommentVNode("", true)
285
+ ])) : createCommentVNode("", true),
286
+ createElementVNode("div", _hoisted_6, [
287
+ state.current.status !== true && state$4.positions.length > 0 ? (openBlock(), createElementBlock("div", _hoisted_7, [
227
288
  createVNode(_sfc_main$4, {
228
289
  customer: state.current.customer
229
290
  }, null, 8, ["customer"]),
@@ -238,9 +299,9 @@ const _sfc_main = {
238
299
  organization: orderOrganization.value[0]
239
300
  }, null, 8, ["order", "organization"])) : createCommentVNode("", true)
240
301
  ])) : createCommentVNode("", true),
241
- state$4.positions.length > 0 ? (openBlock(), createElementBlock("div", _hoisted_4, [
242
- _cache[1] || (_cache[1] = createElementVNode("h4", { class: "font-second mn-b-thin" }, "Your Order", -1)),
243
- createElementVNode("ul", _hoisted_5, [
302
+ state$4.positions.length > 0 ? (openBlock(), createElementBlock("div", _hoisted_8, [
303
+ _cache[2] || (_cache[2] = createElementVNode("h4", { class: "font-second mn-b-thin" }, "Your Order", -1)),
304
+ createElementVNode("ul", _hoisted_9, [
244
305
  (openBlock(true), createElementBlock(Fragment, null, renderList(state$4.positions, (product) => {
245
306
  return openBlock(), createBlock(_sfc_main$7, {
246
307
  key: product._id,
@@ -254,7 +315,7 @@ const _sfc_main = {
254
315
  }, null, 8, ["product", "increase", "decrease", "remove", "onUpdateRentDates"]);
255
316
  }), 128))
256
317
  ]),
257
- createElementVNode("div", _hoisted_6, [
318
+ createElementVNode("div", _hoisted_10, [
258
319
  createVNode(_sfc_main$8, {
259
320
  totalPrice: unref(cartTotalPrice),
260
321
  deliveryRate: deliveryCost.value,
@@ -270,14 +331,14 @@ const _sfc_main = {
270
331
  key: 0,
271
332
  submit: () => handleCreate(),
272
333
  class: "bg-main mn-b-small pd-small radius-big w-100 button",
273
- disabled: errorName.value || errorPhoneOrMessenger.value || _ctx.errorCity || errorAddress.value || errorDelivery.value || errorPayment.value || isLocationLoading.value
334
+ disabled: errorName.value || errorPhoneOrMessenger.value || _ctx.errorCity || errorAddress.value || errorDelivery.value || errorPayment.value || isLocationLoading.value || unref(cartTotalPrice) < minOrderAmount.value
274
335
  }, {
275
- default: withCtx(() => _cache[0] || (_cache[0] = [
336
+ default: withCtx(() => _cache[1] || (_cache[1] = [
276
337
  createElementVNode("span", null, "Place an Order", -1)
277
338
  ])),
278
339
  _: 1
279
340
  }, 8, ["submit", "disabled"])) : createCommentVNode("", true),
280
- _cache[2] || (_cache[2] = createElementVNode("p", { class: "mn-b-thin" }, [
341
+ _cache[3] || (_cache[3] = createElementVNode("p", { class: "mn-b-thin" }, [
281
342
  createTextVNode(" I agree that placing the order places me under an obligation to make a payment in accordance with "),
282
343
  createElementVNode("a", {
283
344
  class: "t-semi font-second t-second",
@@ -285,7 +346,7 @@ const _sfc_main = {
285
346
  target: "_blank"
286
347
  }, "Terms of Use.")
287
348
  ], -1)),
288
- _cache[3] || (_cache[3] = createElementVNode("p", null, null, -1))
349
+ _cache[4] || (_cache[4] = createElementVNode("p", null, null, -1))
289
350
  ])) : createCommentVNode("", true)
290
351
  ])
291
352
  ]);
@@ -1 +1 @@
1
- {"version":3,"file":"OrderCreate.vue.js","sources":["../../../../../../../src/modules/orders/components/pages/OrderCreate.vue"],"sourcesContent":["<template>\n\n<section class=\"bg-white pd-thin\">\n\n\t<!-- Ask to login -->\n\t<AskToLogin class=\"mn-b-thin\" v-if=\"auth.state.access.status === false\" /> \n\t<!-- Order form -->\n\t<div class=\"gap-small mn-b-thin cols-2\">\n\t\t<!-- Empty State -->\n\t\t<EmptyState \n\t\t\tv-if=\"shopcart.state.positions < 1\" \n\t\t/>\t\n\n\t\t<Succes \n\t\t\tv-if=\"order.status === true && shopcart.state.positions.length > 0\" \n\t\t\t:order=\"order\" \n\t\t/>\n\t\t<!-- Order Form -->\n\t\t<div\n\t\t\tv-if=\"orders.state.current.status !== true && shopcart.state.positions.length > 0\" \n\t\t\tclass=\"rows-1 gap-thin\"\n\t\t>\n\t\t\t<FormCustomerDetails\n\t\t\t\t:customer=\"orders.state.current.customer\"\n\t\t\t/>\n\t\t\t<FormPayment \t\n\t\t\t\tv-if=\"orders.state.current.status !== true && shopcart.state.positions.length > 0\"\n\t\t\t\t:order=\"orders.state.current\" \n\t\t\t\t:organization=\"orderOrganization[0]\" \n\t\t\t/>\n\t\t\t<FormDelivery \t\n\t\t\t\tv-if=\"orders.state.current.status !== true && shopcart.state.positions.length > 0\"\n\t\t\t\t:order=\"orders.state.current\" \n\t\t\t\t:organization=\"orderOrganization[0]\" \n\t\t\t/>\n\t\t\t\n\t\t</div>\n\n\t\t<!-- Order positions -->\n\t\t<div \n\t\t\tv-if=\"shopcart.state.positions.length > 0\" \n\t\t\tclass=\"bg-white br-solid br-light br-1px pd-medium radius-medium\"\n\t\t>\n\t\t\t<h4 class=\"font-second mn-b-thin\">Your Order</h4>\n\n\t\t\t<ul class=\"flex gap-thin flex-wrap mn-b-thin\">\n\t\t\t\t<CardOrderItem \n\t\t\t\t\tv-for=\"product in shopcart.state.positions\" \n\t\t\t\t\t:key=\"product._id\" \n\t\t\t\t\t:editable=\"true\" \n\t\t\t\t\t:product=\"product\" \n\t :increase=\"product => shopcart.actions.incrementItemQuantity(product._id)\"\n\t :decrease=\"product => shopcart.actions.decrementItemQuantity(product._id)\"\n\t :remove=\"product => shopcart.actions.removeProduct(product._id)\"\n\t\t\t\t\t@updateRentDates=\"(product, dates) => shopcart.actions.updateRentDates({ productId: product._id, dates })\"\n\t class=\"w-100 bg-white \"\n\t />\n\t\t\t</ul>\n\n\t\t\t\t<div \n\t\t\t\tclass=\"mn-b-thin\"\n\t\t\t>\t\n\t\t\t\t<PriceTotal \n :totalPrice=\"cartTotalPrice\"\n :deliveryRate=\"deliveryCost\"\n :currency=\"returnCurrency()\"\n :showFees=\"globals.state.options?.orders.showFees\"\n :feesRate=\"globals.state.options?.orders.feesRate || 0\"\n :showVat=\"globals.state.options?.orders.showVat\"\n :vatRate=\"globals.state.options?.orders.vatRate || 0\"\n :showDeliveryFee=\"globals.state.options?.orders.showDeliveryFee\"\n />\n\t\t\t</div>\n\t\t\t<!-- Send order -->\n\t\t <Button\n v-if=\"orders.state.current.status !== true && shopcart.state.positions.length > 0\"\n :submit=\"() => handleCreate()\"\n class=\"bg-main mn-b-small pd-small radius-big w-100 button\"\n :disabled=\"\n\t\t errorName \n\t\t || errorPhoneOrMessenger \n\t\t || errorCity \n\t\t || errorAddress \n\t\t || errorDelivery \n\t\t || errorPayment\n\t\t || isLocationLoading\n\t\t \"\n >\n <span>Place an Order</span>\n </Button>\n\n\t\t <p class='mn-b-thin'>\n\t\t\t\tI agree that placing the order places me under an obligation to make a payment in accordance with <a class=\"t-semi font-second t-second\" href=\"/legal/terms-of-use\" target=\"_blank\">Terms of Use.</a>\n\t\t\t</p>\n\t\t\t<p >\n\t\t\t\t\n\t\t\t</p>\n\t\t</div>\n\n\t</div>\n\n\t\n\t\n</section>\n\n</template>\n\n\n<script setup>\n///////////////////////////////////////////////////////////////////////////////////////////////////\n// Import components\n///////////////////////////////////////////////////////////////////////////////////////////////////\nimport Button from '@martyrs/src/components/Button/Button.vue'\n// Block\nimport CardOrderItem from '@martyrs/src/modules/orders/components/blocks/CardOrderItem.vue'\n// Sections\nimport AskToLogin from '@martyrs/src/modules/orders/components/sections/AskToLogin.vue'\nimport Succes from '@martyrs/src/modules/orders/components/sections/Succes.vue'\nimport EmptyState from '@martyrs/src/modules/orders/components/sections/EmptyState.vue'\n\nimport PriceTotal from '@martyrs/src/modules/orders/components/elements/PriceTotal.vue';\n\nimport FormCustomerDetails from '@martyrs/src/modules/orders/components/sections/FormCustomerDetails.vue'\nimport FormDelivery from '@martyrs/src/modules/orders/components/sections/FormDelivery.vue'\nimport FormPayment from '@martyrs/src/modules/orders/components/sections/FormPayment.vue'\n///////////////////////////////////////////////////////////////////////////////////////////////////\n// Import libs\n///////////////////////////////////////////////////////////////////////////////////////////////////\nimport { ref, computed, onMounted, watch } from 'vue'\nimport { useRoute,useRouter } from 'vue-router'\nimport { useGlobalMixins } from \"@martyrs/src/modules/globals/views/mixins/mixins.js\"\n\n// Store\nimport * as globals from '@martyrs/src/modules/globals/views/store/globals';\nimport * as auth from '@martyrs/src/modules/auth/views/store/auth';\nimport * as shopcart from '@martyrs/src/modules/orders/store/shopcart';\nimport * as organizations from '@martyrs/src/modules/organizations/store/organizations';\nimport * as orders from '@martyrs/src/modules/orders/store/orders';\nimport * as users from '@martyrs/src/modules/auth/views/store/users';\n\nconst emits = defineEmits(['page-loading', 'page-loaded']);\n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n// Variables and computed\n//////////////////////////////////////////////////////////////////////////////////////////////////\nconst isLocationLoading = ref(false)\n// Accessing router and store\nconst route = useRoute()\nconst router = useRouter()\nconst { returnCurrency } = useGlobalMixins()\n// COMPUTED\nconst order = computed(() => orders.state.current)\nconst user = computed(() => users.state.current)\n\nconst cartTotalPrice = shopcart.getters.cartTotalPrice\n\nconst deliveryCost = computed(() => {\n const type = orders.state.current.delivery.type\n const distance = orderOrganization.value[0]?.distance || 0\n const config = globals.state.options?.orders?.delivery_formula || {}\n\n return orders.getters.getDeliveryPrice(type, distance, config)\n})\n\n// Organization\nconst orderOrganization = ref({})\n\n\nif (!globals.state.options.orders.allowUnauthenticatedOrders && !auth.state.user._id) { \n\trouter.push({name: 'Sign In'})\t\n}\n\n\norders.mutations.resetOrder()\n\nonMounted(async()=> {\n\temits('page-loading');\n\n\tisLocationLoading.value = true\n\n\tif (auth.state.user._id) {\n\t\tlet data = await users.actions.read({ _id:auth.state.user._id, user: auth.state.user._id });\n\n\t\torders.state.current.customer.profile.name = users.state.current.profile.name\n\t\torders.state.current.customer.phone = users.state.current.phone\n\t\torders.state.current.customer.phone = users.state.current.phone\n\t}\n\n\torderOrganization.value = await organizations.actions.read({\n\t _id: shopcart.state.organization,\n\t location: globals.state.position?.location,\n\t lookup: ['spots']\n\t})\n\t\n \tisLocationLoading.value = false\n emits('page-loaded');\n\n if (typeof gtag === 'function') {\n gtag('event', 'begin_checkout', {\n currency: returnCurrency(), // Замените на вашу валюту\n value: cartTotalPrice || 0,\n items: shopcart.state.positions.map(item => ({\n item_id: item.product?._id,\n item_name: item.product?.name,\n price: item.price || 0,\n quantity: item.quantity || 1,\n item_category: item.product?.category || '',\n item_brand: orderOrganization.value.profile?.name || ''\n })),\n organization: orderOrganization.value.profile?.name || '',\n location: globals.state.position?.location || 'unknown'\n });\n }\n})\n\n\nwatch(\n () => orders.state.current.delivery,\n async (newVal) => {\n if (newVal?.location) {\n \tisLocationLoading.value = true\n\n orderOrganization.value = await organizations.actions.read({\n _id: shopcart.state.organization,\n location: newVal.location,\n lookup: ['spots']\n })\n\n isLocationLoading.value = false\n }\n },\n { deep: true }\n)\n\n\n/////////////////////////////\n// Store Verification\n/////////////////////////////\nconst errorName = computed(() => {\n if (orders.state.current.customer.name?.length < 2) { return true } else { return false }\n});\n\nconst errorPhoneOrMessenger = computed(() => {\n const hasMessengerType = orders.state.current.customer.messenger?.type;\n const hasMessengerValue = orders.state.current.customer.messenger?.value?.length >\t 2;\n const hasPhone = orders.state.current.customer.number?.length > 0;\n // Ошибка, если нет ни номера телефона, ни корректного типа и значения мессенджера\n return !hasPhone && !(hasMessengerType && hasMessengerValue);\n});\n\nconst errorAddress = computed(() => {\n const type = orders.state.current.delivery.type;\n if (type === \"pickup\") {\n return !orders.state.current.delivery.spot;\n } else if (type === \"courier\" || type === \"mail\") {\n const address = orders.state.current.delivery.address;\n return !address || typeof address !== 'string' || address.length < 2;\n }\n return false;\n});\n\nconst errorDelivery = computed(() => {\n if (orders.state.current.delivery.type) {return false } else {return true } \n})\n\nconst errorPayment = computed(() => {\n if (orders.state.current.payment.type) { return false } else {return true } \n})\n/////////////////////////////\n// Methods\n/////////////////////////////\nasync function handleCreate() {\n\n\torders.state.current.status = 'created';\n\n\torders.state.current.owner = {\n\t\ttarget: orderOrganization.value[0]._id,\n\t\ttype: 'organization'\n\t}\n\n\tif (auth.state.user._id) {\n\t\torders.state.current.creator = {\n\t\t\ttarget: auth.state.user._id,\n\t\t\ttype: 'user'\n\t\t}\n\t}\n\n\tif (auth.state.user._id) {\n\t\torders.state.current.customer = {\n\t\t\ttarget: auth.state.user._id,\n\t\t\ttype: 'user'\n\t\t}\n\t}\n\n\torders.state.current.positions = shopcart.state.positions\n\n \tconst referralCode = localStorage.getItem('referalCode');\n \n if (referralCode) {\n orders.state.current.referralCode = referralCode;\n }\n\n let order = await orders.actions.create(orders.state.current);\n\n if (order) {\n\t if (typeof gtag === 'function') {\n\t gtag('event', 'purchase', {\n\t transaction_id: order._id,\n\t value: cartTotalPrice || 0,\n\t currency: returnCurrency(), // Замените на вашу валюту\n\t tax: 0, // Если есть данные о налоге\n\t shipping: deliveryCost.value, // Если есть данные о доставке\n\t items: shopcart.state.positions.map(item => ({\n\t item_id: item.product?._id,\n\t item_name: item.product?.name ,\n\t price: item.price || 0,\n\t quantity: item.quantity || 1,\n\t item_category: item.product?.category || ''\n\t })),\n\t organization: orderOrganization.value?.profile?.name,\n\t location: globals.state.position?.location || 'unknown',\n\t referral_code: referralCode || null,\n\t user_id: auth.state.user._id || 'anonymous'\n\t });\n\t }\n\t}\n\n if (order) {\n \tawait router.push({\n \t\tname: 'Order',\n \t\tparams: {\n \t\t\torder: order._id\n \t\t}\n \t})\n \t\t\n \tshopcart.actions.resetShopcart()\n\n } else {\n \talert('something wrong')\n }\n}\n</script>\n\n<style lang=\"scss\">\n\n.round-wrapper {\n\tposition: relative;\n\n\t.round {\n\t\tmargin: 0;\n\t\tmargin-right: 1rem;\n\t}\n\n\tinput:checked {\n\t\tbackground: #00ff88;\n\t}\n\n\t.round-checkmark {\n\t\tposition: absolute;\n\t\twidth: 0.5rem;\n\t\theight: 0.5rem;\n\t\tbackground: white;\n\n\t\tleft: 0.5rem;\n\t\ttop: 0.5rem;\n\n\t\topacity: 1;\n\t}\n}\n</style>"],"names":["orders.state","users.state","shopcart.getters","globals.state","orders.getters","auth.state","orders.mutations","users.actions","organizations.actions","shopcart.state","_a","_b","_c","order","orders.actions","shopcart.actions"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4IA,UAAM,QAAQ;AAKd,UAAM,oBAAoB,IAAI,KAAK;AAErB,aAAQ;AACtB,UAAM,SAAS,UAAS;AACxB,UAAM,EAAE,eAAgB,IAAG,gBAAe;AAE1C,UAAM,QAAQ,SAAS,MAAMA,MAAa,OAAO;AACpC,aAAS,MAAMC,QAAY,OAAO;AAE/C,UAAM,iBAAiBC,QAAiB;AAExC,UAAM,eAAe,SAAS,MAAM;;AAClC,YAAM,OAAOF,MAAa,QAAQ,SAAS;AAC3C,YAAM,aAAW,uBAAkB,MAAM,CAAC,MAAzB,mBAA4B,aAAY;AACzD,YAAM,WAASG,mBAAc,YAAdA,mBAAuB,WAAvBA,mBAA+B,qBAAoB,CAAA;AAElE,aAAOC,UAAe,iBAAiB,MAAM,UAAU,MAAM;AAAA,IAC/D,CAAC;AAGD,UAAM,oBAAoB,IAAI,CAAE,CAAA;AAGhC,QAAI,CAACD,QAAc,QAAQ,OAAO,8BAA8B,CAACE,QAAW,KAAK,KAAK;AACrF,aAAO,KAAK,EAAC,MAAM,UAAS,CAAC;AAAA,IAC9B;AAGA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AAc,6BAAkB,UAAlB,mBAAyB,YAAzB,mBAAkC;AAAA,YAChD,YAAUT,aAAc,aAAdA,mBAAwB,aAAY;AAAA,YAC9C,eAAe,gBAAgB;AAAA,YAC/B,SAASE,QAAW,KAAK,OAAO;AAAA,UACvC,CAAM;AAAA,QACN;AAAA,MACA;AAEE,UAAIQ,QAAO;AACV,cAAM,OAAO,KAAK;AAAA,UACjB,MAAM;AAAA,UACN,QAAQ;AAAA,YACP,OAAOA,OAAM;AAAA,UAClB;AAAA,QACI,CAAA;AAEDE,kBAAiB,cAAa;AAAA,MAEjC,OAAS;AACN,cAAM,iBAAiB;AAAA,MAC1B;AAAA,IACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"OrderCreate.vue.js","sources":["../../../../../../../src/modules/orders/components/pages/OrderCreate.vue"],"sourcesContent":["<template>\n\n<section class=\"bg-white pd-thin\">\n\n\t<!-- Ask to login -->\n\t<AskToLogin class=\"mn-b-thin\" v-if=\"auth.state.access.status === false\" /> \n\n\t<!-- Empty State -->\n\t<EmptyState \n\t\tv-if=\"shopcart.state.positions < 1\" \n\t/>\t\n\t<Succes \n\t\tv-if=\"order.status === true && shopcart.state.positions.length > 0\" \n\t\t:order=\"order\" \n\t/>\n\t<!-- Уведомления о минимальной сумме заказа и времени работы -->\n\t<div v-if=\"shopcart.state.positions.length > 0 && orders.state.current.status !== true\" class=\"w-100 gap-thin cols-1 mn-b-thin\">\n\t\t<div v-if=\"!isOpen\" class=\"bg-fifth-nano pd-small radius-medium t-center\">\n\t\t\t<p class=\"t-fourth\">⚠️ This spot is currently closed. You can place an order, but it will be processed when the spot opens.</p>\n\t\t</div>\n\t\t<div v-if=\"cartTotalPrice < minOrderAmount\" class=\"bg-fourth-nano pd-small radius-medium t-center\">\n\t\t\t<p class=\"t-fourth\">⚠️ Minimum order amount is {{ formatPrice(minOrderAmount) }}. Your current total is {{ formatPrice(cartTotalPrice) }}.</p>\n\t\t</div>\n\t</div>\n\t\n\t<!-- Order form -->\n\t<div class=\"gap-small mn-b-thin cols-2\">\n\t\t<!-- Order Form -->\n\t\t<div\n\t\t\tv-if=\"orders.state.current.status !== true && shopcart.state.positions.length > 0\" \n\t\t\tclass=\"rows-1 gap-thin\"\n\t\t>\n\t\t\t<FormCustomerDetails\n\t\t\t\t:customer=\"orders.state.current.customer\"\n\t\t\t/>\n\t\t\t<FormPayment \t\n\t\t\t\tv-if=\"orders.state.current.status !== true && shopcart.state.positions.length > 0\"\n\t\t\t\t:order=\"orders.state.current\" \n\t\t\t\t:organization=\"orderOrganization[0]\" \n\t\t\t/>\n\t\t\t<FormDelivery \t\n\t\t\t\tv-if=\"orders.state.current.status !== true && shopcart.state.positions.length > 0\"\n\t\t\t\t:order=\"orders.state.current\" \n\t\t\t\t:organization=\"orderOrganization[0]\" \n\t\t\t/>\n\t\t\t\n\t\t</div>\n\n\t\t<!-- Order positions -->\n\t\t<div \n\t\t\tv-if=\"shopcart.state.positions.length > 0\" \n\t\t\tclass=\"bg-white br-solid br-light br-1px pd-medium radius-medium\"\n\t\t>\n\t\t\t<h4 class=\"font-second mn-b-thin\">Your Order</h4>\n\n\t\t\t<ul class=\"flex gap-thin flex-wrap mn-b-thin\">\n\t\t\t\t<CardOrderItem \n\t\t\t\t\tv-for=\"product in shopcart.state.positions\" \n\t\t\t\t\t:key=\"product._id\" \n\t\t\t\t\t:editable=\"true\" \n\t\t\t\t\t:product=\"product\" \n\t :increase=\"product => shopcart.actions.incrementItemQuantity(product._id)\"\n\t :decrease=\"product => shopcart.actions.decrementItemQuantity(product._id)\"\n\t :remove=\"product => shopcart.actions.removeProduct(product._id)\"\n\t\t\t\t\t@updateRentDates=\"(product, dates) => shopcart.actions.updateRentDates({ productId: product._id, dates })\"\n\t class=\"w-100 bg-white \"\n\t />\n\t\t\t</ul>\n\n\t\t\t\t<div \n\t\t\t\tclass=\"mn-b-thin\"\n\t\t\t>\t\n\t\t\t\t<PriceTotal \n :totalPrice=\"cartTotalPrice\"\n :deliveryRate=\"deliveryCost\"\n :currency=\"returnCurrency()\"\n :showFees=\"globals.state.options?.orders.showFees\"\n :feesRate=\"globals.state.options?.orders.feesRate || 0\"\n :showVat=\"globals.state.options?.orders.showVat\"\n :vatRate=\"globals.state.options?.orders.vatRate || 0\"\n :showDeliveryFee=\"globals.state.options?.orders.showDeliveryFee\"\n />\n\t\t\t</div>\n\t\t\t<!-- Send order -->\n\t\t <Button\n v-if=\"orders.state.current.status !== true && shopcart.state.positions.length > 0\"\n :submit=\"() => handleCreate()\"\n class=\"bg-main mn-b-small pd-small radius-big w-100 button\"\n :disabled=\"\n\t\t errorName \n\t\t || errorPhoneOrMessenger \n\t\t || errorCity \n\t\t || errorAddress \n\t\t || errorDelivery \n\t\t || errorPayment\n\t\t || isLocationLoading\n\t\t || cartTotalPrice < minOrderAmount\n\t\t \"\n >\n <span>Place an Order</span>\n </Button>\n\n\t\t <p class='mn-b-thin'>\n\t\t\t\tI agree that placing the order places me under an obligation to make a payment in accordance with <a class=\"t-semi font-second t-second\" href=\"/legal/terms-of-use\" target=\"_blank\">Terms of Use.</a>\n\t\t\t</p>\n\t\t\t<p >\n\t\t\t\t\n\t\t\t</p>\n\t\t</div>\n\n\t</div>\n\n\t\n\t\n</section>\n\n</template>\n\n\n<script setup>\n///////////////////////////////////////////////////////////////////////////////////////////////////\n// Import components\n///////////////////////////////////////////////////////////////////////////////////////////////////\nimport Button from '@martyrs/src/components/Button/Button.vue'\n// Block\nimport CardOrderItem from '@martyrs/src/modules/orders/components/blocks/CardOrderItem.vue'\n// Sections\nimport AskToLogin from '@martyrs/src/modules/orders/components/sections/AskToLogin.vue'\nimport Succes from '@martyrs/src/modules/orders/components/sections/Succes.vue'\nimport EmptyState from '@martyrs/src/modules/orders/components/sections/EmptyState.vue'\n\nimport PriceTotal from '@martyrs/src/modules/orders/components/elements/PriceTotal.vue';\n\nimport FormCustomerDetails from '@martyrs/src/modules/orders/components/sections/FormCustomerDetails.vue'\nimport FormDelivery from '@martyrs/src/modules/orders/components/sections/FormDelivery.vue'\nimport FormPayment from '@martyrs/src/modules/orders/components/sections/FormPayment.vue'\n///////////////////////////////////////////////////////////////////////////////////////////////////\n// Import libs\n///////////////////////////////////////////////////////////////////////////////////////////////////\nimport { ref, computed, onMounted, watch } from 'vue'\nimport { useRoute,useRouter } from 'vue-router'\nimport { useGlobalMixins } from \"@martyrs/src/modules/globals/views/mixins/mixins.js\"\n\n// Store\nimport * as globals from '@martyrs/src/modules/globals/views/store/globals';\nimport * as auth from '@martyrs/src/modules/auth/views/store/auth';\nimport * as shopcart from '@martyrs/src/modules/orders/store/shopcart';\nimport * as organizations from '@martyrs/src/modules/organizations/store/organizations';\nimport * as orders from '@martyrs/src/modules/orders/store/orders';\nimport * as users from '@martyrs/src/modules/auth/views/store/users';\n\nconst emits = defineEmits(['page-loading', 'page-loaded']);\n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n// Variables and computed\n//////////////////////////////////////////////////////////////////////////////////////////////////\nconst isLocationLoading = ref(false)\n// Accessing router and store\nconst route = useRoute()\nconst router = useRouter()\nconst { returnCurrency, formatPrice } = useGlobalMixins()\n// COMPUTED\nconst order = computed(() => orders.state.current)\nconst user = computed(() => users.state.current)\n\nconst cartTotalPrice = shopcart.getters.cartTotalPrice\n\nconst deliveryCost = computed(() => {\n const type = orders.state.current.delivery.type\n const distance = orderOrganization.value[0]?.distance || 0\n const config = globals.state.options?.orders?.delivery_formula || {}\n\n return orders.getters.getDeliveryPrice(type, distance, config)\n})\n\n// Organization\nconst orderOrganization = ref({})\nconst spotOrganization = ref({})\nconst isOpen = ref(true)\n\n// Новые переменные для проверки минимальной суммы заказа и времени работы\nconst minOrderAmount = ref(0)\n\nfunction checkIsOpenNow(worktime) {\n try {\n console.log('[checkIsOpenNow] worktime:', worktime);\n\n if (\n !worktime ||\n typeof worktime !== 'object' ||\n Array.isArray(worktime) ||\n !worktime.regular\n ) {\n console.log('[checkIsOpenNow] invalid, returning true');\n return true;\n }\n\n const now = new Date();\n const currentDay = now.getDay();\n const currentTime = `${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`;\n const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());\n\n console.log('[checkIsOpenNow] currentDay:', currentDay);\n console.log('[checkIsOpenNow] currentTime:', currentTime);\n\n const specialDay = worktime.special?.find(s => {\n const d = new Date(s.date);\n return (\n d.getFullYear() === today.getFullYear() &&\n d.getMonth() === today.getMonth() &&\n d.getDate() === today.getDate()\n );\n });\n\n if (specialDay) {\n console.log('[checkIsOpenNow] specialDay:', specialDay);\n if (!specialDay.isOpen) return false;\n return specialDay.periods?.some(p => p.open <= currentTime && p.close > currentTime);\n }\n\n const regularDay = worktime.regular.find(d => d.dayOfWeek === currentDay);\n if (!regularDay || !regularDay.isOpen) return false;\n\n return regularDay.periods?.some(p => p.open <= currentTime && p.close > currentTime);\n } catch (err) {\n console.error('[checkIsOpenNow] error:', err);\n return true;\n }\n}\n\n\nif (!globals.state.options.orders.allowUnauthenticatedOrders && !auth.state.user._id) { \n\trouter.push({name: 'Sign In'})\t\n}\n\n\norders.mutations.resetOrder()\n\nonMounted(async()=> {\n\temits('page-loading');\n\n\tisLocationLoading.value = true\n\n\tif (auth.state.user._id) {\n\t\tlet data = await users.actions.read({ _id:auth.state.user._id, user: auth.state.user._id });\n\n\t\torders.state.current.customer.profile.name = users.state.current.profile.name\n\t\torders.state.current.customer.phone = users.state.current.phone\n\t\torders.state.current.customer.phone = users.state.current.phone\n\t}\n\t\n\torderOrganization.value = await organizations.actions.read({\n\t _id: shopcart.state.organization,\n\t location: globals.state.position?.location,\n\t lookup: ['spots']\n\t})\n\t\n\t// Получаем информацию о минимальной сумме заказа и времени работы из spot\n\tif (orderOrganization.value && orderOrganization.value[0]?.spots?.length > 0) {\n\t spotOrganization.value = orderOrganization.value[0].spots[0];\n\t\tisOpen.value = checkIsOpenNow(spotOrganization.value.worktime);\n\t console.log(spotOrganization.value)\n\t minOrderAmount.value = spotOrganization.value || 0;\n\t}\n\n\n\t\n \tisLocationLoading.value = false\n emits('page-loaded');\n\n if (typeof gtag === 'function') {\n gtag('event', 'begin_checkout', {\n currency: returnCurrency(), // Замените на вашу валюту\n value: cartTotalPrice || 0,\n items: shopcart.state.positions.map(item => ({\n item_id: item.product?._id,\n item_name: item.product?.name,\n price: item.price || 0,\n quantity: item.quantity || 1,\n item_category: item.product?.category || '',\n item_brand: orderOrganization.value.profile?.name || ''\n })),\n organization: orderOrganization.value.profile?.name || '',\n location: globals.state.position?.location || 'unknown'\n });\n }\n})\n\n\nwatch(\n () => orders.state.current.delivery,\n async (newVal) => {\n if (newVal?.location) {\n \tisLocationLoading.value = true\n\n orderOrganization.value = await organizations.actions.read({\n _id: shopcart.state.organization,\n location: newVal.location,\n lookup: ['spots']\n })\n \n isLocationLoading.value = false\n }\n },\n { deep: true }\n)\n\n\n/////////////////////////////\n// Store Verification\n/////////////////////////////\nconst errorName = computed(() => {\n if (orders.state.current.customer.name?.length < 2) { return true } else { return false }\n});\n\nconst errorPhoneOrMessenger = computed(() => {\n const hasMessengerType = orders.state.current.customer.messenger?.type;\n const hasMessengerValue = orders.state.current.customer.messenger?.value?.length >\t 2;\n const hasPhone = orders.state.current.customer.number?.length > 0;\n // Ошибка, если нет ни номера телефона, ни корректного типа и значения мессенджера\n return !hasPhone && !(hasMessengerType && hasMessengerValue);\n});\n\nconst errorAddress = computed(() => {\n const type = orders.state.current.delivery.type;\n if (type === \"pickup\") {\n return !orders.state.current.delivery.spot;\n } else if (type === \"courier\" || type === \"mail\") {\n const address = orders.state.current.delivery.address;\n return !address || typeof address !== 'string' || address.length < 2;\n }\n return false;\n});\n\nconst errorDelivery = computed(() => {\n if (orders.state.current.delivery.type) {return false } else {return true } \n})\n\nconst errorPayment = computed(() => {\n if (orders.state.current.payment.type) { return false } else {return true } \n})\n/////////////////////////////\n// Methods\n/////////////////////////////\nasync function handleCreate() {\n\n\torders.state.current.status = 'created';\n\n\torders.state.current.owner = {\n\t\ttarget: orderOrganization.value[0]._id,\n\t\ttype: 'organization'\n\t}\n\n\tif (auth.state.user._id) {\n\t\torders.state.current.creator = {\n\t\t\ttarget: auth.state.user._id,\n\t\t\ttype: 'user'\n\t\t}\n\t}\n\n\tif (auth.state.user._id) {\n\t\torders.state.current.customer = {\n\t\t\ttarget: auth.state.user._id,\n\t\t\ttype: 'user'\n\t\t}\n\t}\n\n\torders.state.current.positions = shopcart.state.positions\n\n \tconst referralCode = localStorage.getItem('referalCode');\n \n if (referralCode) {\n orders.state.current.referralCode = referralCode;\n }\n\n let order = await orders.actions.create(orders.state.current);\n\n if (order) {\n\t if (typeof gtag === 'function') {\n\t gtag('event', 'purchase', {\n\t transaction_id: order._id,\n\t value: cartTotalPrice || 0,\n\t currency: returnCurrency(), // Замените на вашу валюту\n\t tax: 0, // Если есть данные о налоге\n\t shipping: deliveryCost.value, // Если есть данные о доставке\n\t items: shopcart.state.positions.map(item => ({\n\t item_id: item.product?._id,\n\t item_name: item.product?.name ,\n\t price: item.price || 0,\n\t quantity: item.quantity || 1,\n\t item_category: item.product?.category || ''\n\t })),\n\t organization: orderOrganization.value?.profile?.name,\n\t location: globals.state.position?.location || 'unknown',\n\t referral_code: referralCode || null,\n\t user_id: auth.state.user._id || 'anonymous'\n\t });\n\t }\n\t}\n\n if (order) {\n \tawait router.push({\n \t\tname: 'Order',\n \t\tparams: {\n \t\t\torder: order._id\n \t\t}\n \t})\n \t\t\n \tshopcart.actions.resetShopcart()\n\n } else {\n \talert('something wrong')\n }\n}\n</script>\n\n<style lang=\"scss\">\n\n.round-wrapper {\n\tposition: relative;\n\n\t.round {\n\t\tmargin: 0;\n\t\tmargin-right: 1rem;\n\t}\n\n\tinput:checked {\n\t\tbackground: #00ff88;\n\t}\n\n\t.round-checkmark {\n\t\tposition: absolute;\n\t\twidth: 0.5rem;\n\t\theight: 0.5rem;\n\t\tbackground: white;\n\n\t\tleft: 0.5rem;\n\t\ttop: 0.5rem;\n\n\t\topacity: 1;\n\t}\n}\n</style>"],"names":["orders.state","users.state","shopcart.getters","globals.state","orders.getters","auth.state","orders.mutations","users.actions","organizations.actions","shopcart.state","_a","_b","_c","_d","order","orders.actions","shopcart.actions"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuJA,UAAM,QAAQ;AAKd,UAAM,oBAAoB,IAAI,KAAK;AAErB,aAAQ;AACtB,UAAM,SAAS,UAAS;AACxB,UAAM,EAAE,gBAAgB,YAAW,IAAK,gBAAe;AAEvD,UAAM,QAAQ,SAAS,MAAMA,MAAa,OAAO;AACpC,aAAS,MAAMC,QAAY,OAAO;AAE/C,UAAM,iBAAiBC,QAAiB;AAExC,UAAM,eAAe,SAAS,MAAM;;AAClC,YAAM,OAAOF,MAAa,QAAQ,SAAS;AAC3C,YAAM,aAAW,uBAAkB,MAAM,CAAC,MAAzB,mBAA4B,aAAY;AACzD,YAAM,WAASG,mBAAc,YAAdA,mBAAuB,WAAvBA,mBAA+B,qBAAoB,CAAA;AAElE,aAAOC,UAAe,iBAAiB,MAAM,UAAU,MAAM;AAAA,IAC/D,CAAC;AAGD,UAAM,oBAAoB,IAAI,CAAE,CAAA;AAChC,UAAM,mBAAmB,IAAI,CAAE,CAAA;AAC/B,UAAM,SAAS,IAAI,IAAI;AAGvB,UAAM,iBAAiB,IAAI,CAAC;AAE5B,aAAS,eAAe,UAAU;;AAChC,UAAI;AACF,gBAAQ,IAAI,8BAA8B,QAAQ;AAElD,YACE,CAAC,YACD,OAAO,aAAa,YACpB,MAAM,QAAQ,QAAQ,KACtB,CAAC,SAAS,SACV;AACA,kBAAQ,IAAI,0CAA0C;AACtD,iBAAO;AAAA,QACb;AAEI,cAAM,MAAM,oBAAI,KAAM;AACtB,cAAM,aAAa,IAAI,OAAQ;AAC/B,cAAM,cAAc,GAAG,OAAO,IAAI,UAAU,EAAE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,UAAU,KAAK,YAAY;AAAA,gBAC3B,iBAAeC,MAAA,KAAK,YAAL,gBAAAA,IAAc,aAAY;AAAA,cAClD;AAAA,aAAS;AAAA,YACF,eAAc,6BAAkB,UAAlB,mBAAyB,YAAzB,mBAAkC;AAAA,YAChD,YAAUT,aAAc,aAAdA,mBAAwB,aAAY;AAAA,YAC9C,eAAe,gBAAgB;AAAA,YAC/B,SAASE,QAAW,KAAK,OAAO;AAAA,UACvC,CAAM;AAAA,QACN;AAAA,MACA;AAEE,UAAIS,QAAO;AACV,cAAM,OAAO,KAAK;AAAA,UACjB,MAAM;AAAA,UACN,QAAQ;AAAA,YACP,OAAOA,OAAM;AAAA,UAClB;AAAA,QACI,CAAA;AAEDE,kBAAiB,cAAa;AAAA,MAEjC,OAAS;AACN,cAAM,iBAAiB;AAAA,MAC1B;AAAA,IACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -45,6 +45,7 @@ const actions = {
45
45
  // Добавляем _id организации к каждому продукту
46
46
  });
47
47
  }
48
+ state.organization = organization;
48
49
  localStorage.setItem("shopcart", JSON.stringify({
49
50
  positions: state.positions,
50
51
  organization
@@ -1 +1 @@
1
- {"version":3,"file":"shopcart.cjs","sources":["../../../../../../src/modules/orders/store/shopcart.js"],"sourcesContent":["/////////////////////////////\n// DEPENDENCIES\n/////////////////////////////\nimport { reactive, watch, computed } from \"vue\";\n// Dependencies\nimport Cookies from 'js-cookie'\n// Globals \nimport { setError } from '@martyrs/src/modules/globals/views/store/globals'\n\n/////////////////////////////\n// State\n/////////////////////////////\nconst state = reactive({\n organization: null,\n positions: [],\n currentState: false\n});\n\n/////////////////////////////\n// Helpers\n/////////////////////////////\nconst helpers = {\n createCartItem(product, organization, type = 'sale') {\n return {\n _id: product._id,\n images: product.images,\n name: product.name,\n price: product.price,\n listing: product.listing,\n quantity: 1,\n org_id: organization,\n type: type\n };\n },\n\n saveToStorage() {\n localStorage.setItem(CART_STORAGE_KEY, JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n },\n\n async validateProduct(product) {\n const serverProduct = await api.fetchProduct(product._id);\n \n if (!serverProduct) {\n return false;\n }\n\n return serverProduct.price === product.price &&\n serverProduct.name === product.name &&\n serverProduct.available !== false;\n }\n};\n\n/////////////////////////////\n// SYNC PRODUCT IN SHOPCART\n/////////////////////////////\n// Constants\nconst CART_STORAGE_KEY = 'shopcart';\nconst SYNC_INTERVAL = 30000; // 30 seconds in milliseconds\n\n// API service\nconst api = {\n async fetchProduct(productId) {\n try {\n const response = await fetch(`/api/products/read`, { _id: productId});\n return await response.json();\n } catch (error) {\n console.error('Failed to fetch product:', error);\n return null;\n }\n }\n};\n\nasync function syncWithServer() {\n try {\n const invalidProducts = [];\n \n for (let i = 0; i < state.positions.length; i++) {\n const product = state.positions[i];\n const serverProduct = await api.fetchProduct(product._id);\n \n if (!serverProduct || \n serverProduct.price !== product.price || \n serverProduct.name !== product.name || \n serverProduct.available === false) {\n invalidProducts.push(product._id);\n }\n }\n\n if (invalidProducts.length > 0) {\n state.positions = state.positions.filter(\n product => !invalidProducts.includes(product._id)\n );\n helpers.saveToStorage();\n setError('Some products were removed from cart due to changes on server');\n }\n } catch (error) {\n console.error('Failed to sync with server:', error);\n }\n}\n// Initialize periodic sync\nlet syncInterval;\n\nconst startPeriodicSync = () => {\n syncInterval = setInterval(syncWithServer, SYNC_INTERVAL);\n};\n\nconst stopPeriodicSync = () => {\n if (syncInterval) {\n clearInterval(syncInterval);\n }\n};\n\n// Start sync when module is imported\n// startPeriodicSync();\n/////////////////////////////\n// Actions\n/////////////////////////////\nconst actions = {\n\n toggleShopcart () {\n state.currentState = state.currentState ? false : true;\n },\n\n setShopcart() {\n try {\n const storedShopcart = localStorage.getItem('shopcart');\n\n if (storedShopcart) {\n const shopcartData = JSON.parse(storedShopcart);\n state.positions = shopcartData.positions; // Восстанавливаем продукты\n state.organization = shopcartData.organization; // Восстанавливаем _id организации\n } \n } catch (error) {\n console.error(error);\n throw error;\n }\n },\n\n\n addProductToCart(product, organization, date) {\n console.log('organization shopcart is', organization)\n const cartItem = state.positions.find(\n (item) => item._id === product._id\n );\n\n if (cartItem) {\n cartItem.quantity++;\n } else {\n state.positions.push({\n _id: product._id,\n images: product.images,\n name: product.name,\n listing: product.listing,\n price: product.price,\n quantity: 1,\n date: date, \n org_id: organization, // Добавляем _id организации к каждому продукту\n });\n }\n\n // Обновляем объект корзины в localStorage, включая _id организации\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: organization // Сохраняем _id организации в корне объекта корзины\n }));\n },\n\n\n removeProduct(_id) {\n const cartItem = state.positions.find(\n (item) => item._id === _id\n );\n const cartItemIndex = state.positions.indexOf(cartItem);\n\n if (cartItemIndex > -1) {\n state.positions.splice(cartItemIndex, 1);\n \n // Сохраняем весь объект корзины, а не только позиции\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n }\n },\n\n\n decrementItemQuantity(_id) {\n const cartItem = state.positions.find(\n (item) => item._id === _id\n );\n const cartItemIndex = state.positions.indexOf(cartItem);\n \n if (cartItemIndex > -1) {\n cartItem.quantity--;\n \n if (cartItem.quantity < 1) {\n state.positions.splice(cartItemIndex, 1);\n }\n\n // Сохраняем весь объект корзины, а не только позиции\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n }\n },\n\n\n incrementItemQuantity(_id) {\n const cartItem = state.positions.find(\n (item) => item._id === _id\n );\n\n if (cartItem) {\n cartItem.quantity++;\n\n // Сохраняем весь объект корзины, а не только позиции\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n }\n },\n\n updateRentDates({ productId, dates }) {\n const product = state.positions.find(p => p._id === productId)\n\n if (product) {\n product.date = dates // Предполагается, что dates — объект { start, end }\n }\n\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n },\n\n\n resetShopcart() {\n state.positions = [];\n \n localStorage.removeItem('shopcart');\n },\n};\n\n/////////////////////////////\n// Getters\n/////////////////////////////\nconst getters = {\n cartTotalPrice: computed(() => {\n return Number(state.positions.reduce((total, product) => {\n // Проверяем тип листинга\n if (product.listing === 'rent') {\n const start = new Date(product.date.start)\n const end = new Date(product.date.end)\n const diffTime = Math.abs(end - start)\n return total + product.price * (Math.ceil(diffTime / (1000 * 60 * 60 * 24)) + 1);\n } else {\n // Для обычных товаров умножаем на количество\n return total + product.price * (product.quantity || 1);\n }\n }, 0));\n }),\n cartTotalAmount: computed(() => {\n return Number(state.positions.reduce((total, product) => {\n return total + product.quantity;\n }, 0));\n }),\n getStoreCartState: computed(() => {\n return Number(state.currentState);\n }),\n};\n/////////////////////////////\n// History\n/////////////////////////////\nconst history = []\nhistory.push(state) \n\n/////////////////////////////\n// Watch\n/////////////////////////////\nwatch(state, (newState, oldState) => {\n history.push(newState)\n})\n\n/////////////////////////////\n// Module Export\n/////////////////////////////\nexport {\n state,\n actions,\n getters\n}"],"names":["reactive","computed","watch"],"mappings":";;;;;AAYK,MAAC,QAAQA,IAAAA,SAAS;AAAA,EACrB,cAAc;AAAA,EACd,WAAW,CAAE;AAAA,EACb,cAAc;AAChB,CAAC;AAwGI,MAAC,UAAU;AAAA,EAEd,iBAAkB;AAChB,UAAM,eAAe,MAAM,eAAe,QAAQ;AAAA,EACnD;AAAA,EAED,cAAc;AACZ,QAAI;AACF,YAAM,iBAAiB,aAAa,QAAQ,UAAU;AAEtD,UAAI,gBAAgB;AAClB,cAAM,eAAe,KAAK,MAAM,cAAc;AAC9C,cAAM,YAAY,aAAa;AAC/B,cAAM,eAAe,aAAa;AAAA,MACnC;AAAA,IACF,SAAQ,OAAO;AACd,cAAQ,MAAM,KAAK;AACnB,YAAM;AAAA,IACZ;AAAA,EACG;AAAA,EAGD,iBAAiB,SAAS,cAAc,MAAM;AAC5C,YAAQ,IA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AAY;AACvD,aAAO,QAAQ,QAAQ;AAAA,IACxB,GAAE,CAAC,CAAC;AAAA,EACT,CAAG;AAAA,EACD,mBAAmBA,IAAQ,SAAC,MAAM;AAChC,WAAO,OAAO,MAAM,YAAY;AAAA,EACpC,CAAG;AACH;AAUAC,IAAAA,MAAM,OAAO,CAAC,UAAU,aAAa;AAErC,CAAC;;;;"}
1
+ {"version":3,"file":"shopcart.cjs","sources":["../../../../../../src/modules/orders/store/shopcart.js"],"sourcesContent":["/////////////////////////////\n// DEPENDENCIES\n/////////////////////////////\nimport { reactive, watch, computed } from \"vue\";\n// Dependencies\nimport Cookies from 'js-cookie'\n// Globals \nimport { setError } from '@martyrs/src/modules/globals/views/store/globals'\n\n/////////////////////////////\n// State\n/////////////////////////////\nconst state = reactive({\n organization: null,\n positions: [],\n currentState: false\n});\n\n/////////////////////////////\n// Helpers\n/////////////////////////////\nconst helpers = {\n createCartItem(product, organization, type = 'sale') {\n return {\n _id: product._id,\n images: product.images,\n name: product.name,\n price: product.price,\n listing: product.listing,\n quantity: 1,\n org_id: organization,\n type: type\n };\n },\n\n saveToStorage() {\n localStorage.setItem(CART_STORAGE_KEY, JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n },\n\n async validateProduct(product) {\n const serverProduct = await api.fetchProduct(product._id);\n \n if (!serverProduct) {\n return false;\n }\n\n return serverProduct.price === product.price &&\n serverProduct.name === product.name &&\n serverProduct.available !== false;\n }\n};\n\n/////////////////////////////\n// SYNC PRODUCT IN SHOPCART\n/////////////////////////////\n// Constants\nconst CART_STORAGE_KEY = 'shopcart';\nconst SYNC_INTERVAL = 30000; // 30 seconds in milliseconds\n\n// API service\nconst api = {\n async fetchProduct(productId) {\n try {\n const response = await fetch(`/api/products/read`, { _id: productId});\n return await response.json();\n } catch (error) {\n console.error('Failed to fetch product:', error);\n return null;\n }\n }\n};\n\nasync function syncWithServer() {\n try {\n const invalidProducts = [];\n \n for (let i = 0; i < state.positions.length; i++) {\n const product = state.positions[i];\n const serverProduct = await api.fetchProduct(product._id);\n \n if (!serverProduct || \n serverProduct.price !== product.price || \n serverProduct.name !== product.name || \n serverProduct.available === false) {\n invalidProducts.push(product._id);\n }\n }\n\n if (invalidProducts.length > 0) {\n state.positions = state.positions.filter(\n product => !invalidProducts.includes(product._id)\n );\n helpers.saveToStorage();\n setError('Some products were removed from cart due to changes on server');\n }\n } catch (error) {\n console.error('Failed to sync with server:', error);\n }\n}\n// Initialize periodic sync\nlet syncInterval;\n\nconst startPeriodicSync = () => {\n syncInterval = setInterval(syncWithServer, SYNC_INTERVAL);\n};\n\nconst stopPeriodicSync = () => {\n if (syncInterval) {\n clearInterval(syncInterval);\n }\n};\n\n// Start sync when module is imported\n// startPeriodicSync();\n/////////////////////////////\n// Actions\n/////////////////////////////\nconst actions = {\n\n toggleShopcart () {\n state.currentState = state.currentState ? false : true;\n },\n\n setShopcart() {\n try {\n const storedShopcart = localStorage.getItem('shopcart');\n\n if (storedShopcart) {\n const shopcartData = JSON.parse(storedShopcart);\n state.positions = shopcartData.positions; // Восстанавливаем продукты\n state.organization = shopcartData.organization; // Восстанавливаем _id организации\n } \n } catch (error) {\n console.error(error);\n throw error;\n }\n },\n\n\n addProductToCart(product, organization, date) {\n console.log('organization shopcart is', organization)\n const cartItem = state.positions.find(\n (item) => item._id === product._id\n );\n\n if (cartItem) {\n cartItem.quantity++;\n } else {\n state.positions.push({\n _id: product._id,\n images: product.images,\n name: product.name,\n listing: product.listing,\n price: product.price,\n quantity: 1,\n date: date, \n org_id: organization, // Добавляем _id организации к каждому продукту\n });\n }\n state.organization = organization\n\n // Обновляем объект корзины в localStorage, включая _id организации\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: organization // Сохраняем _id организации в корне объекта корзины\n }));\n },\n\n\n removeProduct(_id) {\n const cartItem = state.positions.find(\n (item) => item._id === _id\n );\n const cartItemIndex = state.positions.indexOf(cartItem);\n\n if (cartItemIndex > -1) {\n state.positions.splice(cartItemIndex, 1);\n \n // Сохраняем весь объект корзины, а не только позиции\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n }\n },\n\n\n decrementItemQuantity(_id) {\n const cartItem = state.positions.find(\n (item) => item._id === _id\n );\n const cartItemIndex = state.positions.indexOf(cartItem);\n \n if (cartItemIndex > -1) {\n cartItem.quantity--;\n \n if (cartItem.quantity < 1) {\n state.positions.splice(cartItemIndex, 1);\n }\n\n // Сохраняем весь объект корзины, а не только позиции\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n }\n },\n\n\n incrementItemQuantity(_id) {\n const cartItem = state.positions.find(\n (item) => item._id === _id\n );\n\n if (cartItem) {\n cartItem.quantity++;\n\n // Сохраняем весь объект корзины, а не только позиции\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n }\n },\n\n updateRentDates({ productId, dates }) {\n const product = state.positions.find(p => p._id === productId)\n\n if (product) {\n product.date = dates // Предполагается, что dates — объект { start, end }\n }\n\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n },\n\n\n resetShopcart() {\n state.positions = [];\n \n localStorage.removeItem('shopcart');\n },\n};\n\n/////////////////////////////\n// Getters\n/////////////////////////////\nconst getters = {\n cartTotalPrice: computed(() => {\n return Number(state.positions.reduce((total, product) => {\n // Проверяем тип листинга\n if (product.listing === 'rent') {\n const start = new Date(product.date.start)\n const end = new Date(product.date.end)\n const diffTime = Math.abs(end - start)\n return total + product.price * (Math.ceil(diffTime / (1000 * 60 * 60 * 24)) + 1);\n } else {\n // Для обычных товаров умножаем на количество\n return total + product.price * (product.quantity || 1);\n }\n }, 0));\n }),\n cartTotalAmount: computed(() => {\n return Number(state.positions.reduce((total, product) => {\n return total + product.quantity;\n }, 0));\n }),\n getStoreCartState: computed(() => {\n return Number(state.currentState);\n }),\n};\n/////////////////////////////\n// History\n/////////////////////////////\nconst history = []\nhistory.push(state) \n\n/////////////////////////////\n// Watch\n/////////////////////////////\nwatch(state, (newState, oldState) => {\n history.push(newState)\n})\n\n/////////////////////////////\n// Module Export\n/////////////////////////////\nexport {\n state,\n actions,\n getters\n}"],"names":["reactive","computed","watch"],"mappings":";;;;;AAYK,MAAC,QAAQA,IAAAA,SAAS;AAAA,EACrB,cAAc;AAAA,EACd,WAAW,CAAE;AAAA,EACb,cAAc;AAChB,CAAC;AAwGI,MAAC,UAAU;AAAA,EAEd,iBAAkB;AAChB,UAAM,eAAe,MAAM,eAAe,QAAQ;AAAA,EACnD;AAAA,EAED,cAAc;AACZ,QAAI;AACF,YAAM,iBAAiB,aAAa,QAAQ,UAAU;AAEtD,UAAI,gBAAgB;AAClB,cAAM,eAAe,KAAK,MAAM,cAAc;AAC9C,cAAM,YAAY,aAAa;AAC/B,cAAM,eAAe,aAAa;AAAA,MACnC;AAAA,IACF,SAAQ,OAAO;AACd,cAAQ,MAAM,KAAK;AACnB,YAAM;AAAA,IACZ;AAAA,EACG;AAAA,EAGD,iBAAiB,SAAS,cAAc,MAAM;AAC5C,YAAQ,IAAI,4BAA4B,YAAY;AACpD,UAAM,WAAW,MAAM,UAAU;AAAA,MAC/B,CAAC,SAAS,KAAK,QAAQ,QAAQ;AAAA,IAChC;AAED,QAAI,UAAU;AACZ,eAAS;AAAA,IACf,OAAW;AACL,YAAM,UAAU,KAAK;AAAA,QACnB,KAAK,QAAQ;AAAA,QACb,QAAQ,QAAQ;AAAA,QAChB,MAAM,QAAQ;AAAA,QACd,SAAS,QAAQ;AAAA,QACjB,OAAO,QAAQ;AAAA,QACf,UAAU;AAAA,QACV;AAAA,QACA,QAAQ;AAAA;AAAA,MAChB,CAAO;AAAA,IACP;AACI,UAAM,eAAe;AAGrB,iBAAa,QAAQ,YAAY,KAAK,UAAU;AAAA,MAC9C,WAAW,MAAM;AAAA,MACjB;AAAA;AAAA,IACN,CAAK,CAAC;AAAA,EACH;AAAA,EAGD,cAAc,KAAK;AACjB,UAAM,WAAW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B,CAAK,CAAC;AAAA,EACH;AAAA,EAGD,gBAAgB;AACd,UAAM,YAAY,CAAE;AAEpB,iBAAa,WAAW,UAAU;AAAA,EACnC;AACH;AAKK,MAAC,UAAU;AAAA,EACd,gBAAgBC,IAAQ,SAAC,MAAM;AAC7B,WAAO,OAAO,MAAM,UAAU,OAAO,CAAC,OAAO,YAAY;AAEvD,UAAI,QAAQ,YAAY,QAAQ;AAC9B,cAAM,QAAQ,IAAI,KAAK,QAAQ,KAAK,KAAK;AACzC,cAAM,MAAM,IAAI,KAAK,QAAQ,KAAK,GAAG;AACrC,cAAM,WAAW,KAAK,IAAI,MAAM,KAAK;AACrC,eAAO,QAAQ,QAAQ,SAAS,KAAK,KAAK,YAAY,MAAO,KAAK,KAAK,GAAG,IAAI;AAAA,MACtF,OAAa;AAEL,eAAO,QAAQ,QAAQ,SAAS,QAAQ,YAAY;AAAA,MAC5D;AAAA,IACK,GAAE,CAAC,CAAC;AAAA,EACT,CAAG;AAAA,EACD,iBAAiBA,IAAQ,SAAC,MAAM;AAC9B,WAAO,OAAO,MAAM,UAAU,OAAO,CAAC,OAAO,YAAY;AACvD,aAAO,QAAQ,QAAQ;AAAA,IACxB,GAAE,CAAC,CAAC;AAAA,EACT,CAAG;AAAA,EACD,mBAAmBA,IAAQ,SAAC,MAAM;AAChC,WAAO,OAAO,MAAM,YAAY;AAAA,EACpC,CAAG;AACH;AAUAC,IAAAA,MAAM,OAAO,CAAC,UAAU,aAAa;AAErC,CAAC;;;;"}
@@ -43,6 +43,7 @@ const actions = {
43
43
  // Добавляем _id организации к каждому продукту
44
44
  });
45
45
  }
46
+ state.organization = organization;
46
47
  localStorage.setItem("shopcart", JSON.stringify({
47
48
  positions: state.positions,
48
49
  organization
@@ -1 +1 @@
1
- {"version":3,"file":"shopcart.js","sources":["../../../../../../src/modules/orders/store/shopcart.js"],"sourcesContent":["/////////////////////////////\n// DEPENDENCIES\n/////////////////////////////\nimport { reactive, watch, computed } from \"vue\";\n// Dependencies\nimport Cookies from 'js-cookie'\n// Globals \nimport { setError } from '@martyrs/src/modules/globals/views/store/globals'\n\n/////////////////////////////\n// State\n/////////////////////////////\nconst state = reactive({\n organization: null,\n positions: [],\n currentState: false\n});\n\n/////////////////////////////\n// Helpers\n/////////////////////////////\nconst helpers = {\n createCartItem(product, organization, type = 'sale') {\n return {\n _id: product._id,\n images: product.images,\n name: product.name,\n price: product.price,\n listing: product.listing,\n quantity: 1,\n org_id: organization,\n type: type\n };\n },\n\n saveToStorage() {\n localStorage.setItem(CART_STORAGE_KEY, JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n },\n\n async validateProduct(product) {\n const serverProduct = await api.fetchProduct(product._id);\n \n if (!serverProduct) {\n return false;\n }\n\n return serverProduct.price === product.price &&\n serverProduct.name === product.name &&\n serverProduct.available !== false;\n }\n};\n\n/////////////////////////////\n// SYNC PRODUCT IN SHOPCART\n/////////////////////////////\n// Constants\nconst CART_STORAGE_KEY = 'shopcart';\nconst SYNC_INTERVAL = 30000; // 30 seconds in milliseconds\n\n// API service\nconst api = {\n async fetchProduct(productId) {\n try {\n const response = await fetch(`/api/products/read`, { _id: productId});\n return await response.json();\n } catch (error) {\n console.error('Failed to fetch product:', error);\n return null;\n }\n }\n};\n\nasync function syncWithServer() {\n try {\n const invalidProducts = [];\n \n for (let i = 0; i < state.positions.length; i++) {\n const product = state.positions[i];\n const serverProduct = await api.fetchProduct(product._id);\n \n if (!serverProduct || \n serverProduct.price !== product.price || \n serverProduct.name !== product.name || \n serverProduct.available === false) {\n invalidProducts.push(product._id);\n }\n }\n\n if (invalidProducts.length > 0) {\n state.positions = state.positions.filter(\n product => !invalidProducts.includes(product._id)\n );\n helpers.saveToStorage();\n setError('Some products were removed from cart due to changes on server');\n }\n } catch (error) {\n console.error('Failed to sync with server:', error);\n }\n}\n// Initialize periodic sync\nlet syncInterval;\n\nconst startPeriodicSync = () => {\n syncInterval = setInterval(syncWithServer, SYNC_INTERVAL);\n};\n\nconst stopPeriodicSync = () => {\n if (syncInterval) {\n clearInterval(syncInterval);\n }\n};\n\n// Start sync when module is imported\n// startPeriodicSync();\n/////////////////////////////\n// Actions\n/////////////////////////////\nconst actions = {\n\n toggleShopcart () {\n state.currentState = state.currentState ? false : true;\n },\n\n setShopcart() {\n try {\n const storedShopcart = localStorage.getItem('shopcart');\n\n if (storedShopcart) {\n const shopcartData = JSON.parse(storedShopcart);\n state.positions = shopcartData.positions; // Восстанавливаем продукты\n state.organization = shopcartData.organization; // Восстанавливаем _id организации\n } \n } catch (error) {\n console.error(error);\n throw error;\n }\n },\n\n\n addProductToCart(product, organization, date) {\n console.log('organization shopcart is', organization)\n const cartItem = state.positions.find(\n (item) => item._id === product._id\n );\n\n if (cartItem) {\n cartItem.quantity++;\n } else {\n state.positions.push({\n _id: product._id,\n images: product.images,\n name: product.name,\n listing: product.listing,\n price: product.price,\n quantity: 1,\n date: date, \n org_id: organization, // Добавляем _id организации к каждому продукту\n });\n }\n\n // Обновляем объект корзины в localStorage, включая _id организации\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: organization // Сохраняем _id организации в корне объекта корзины\n }));\n },\n\n\n removeProduct(_id) {\n const cartItem = state.positions.find(\n (item) => item._id === _id\n );\n const cartItemIndex = state.positions.indexOf(cartItem);\n\n if (cartItemIndex > -1) {\n state.positions.splice(cartItemIndex, 1);\n \n // Сохраняем весь объект корзины, а не только позиции\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n }\n },\n\n\n decrementItemQuantity(_id) {\n const cartItem = state.positions.find(\n (item) => item._id === _id\n );\n const cartItemIndex = state.positions.indexOf(cartItem);\n \n if (cartItemIndex > -1) {\n cartItem.quantity--;\n \n if (cartItem.quantity < 1) {\n state.positions.splice(cartItemIndex, 1);\n }\n\n // Сохраняем весь объект корзины, а не только позиции\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n }\n },\n\n\n incrementItemQuantity(_id) {\n const cartItem = state.positions.find(\n (item) => item._id === _id\n );\n\n if (cartItem) {\n cartItem.quantity++;\n\n // Сохраняем весь объект корзины, а не только позиции\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n }\n },\n\n updateRentDates({ productId, dates }) {\n const product = state.positions.find(p => p._id === productId)\n\n if (product) {\n product.date = dates // Предполагается, что dates — объект { start, end }\n }\n\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n },\n\n\n resetShopcart() {\n state.positions = [];\n \n localStorage.removeItem('shopcart');\n },\n};\n\n/////////////////////////////\n// Getters\n/////////////////////////////\nconst getters = {\n cartTotalPrice: computed(() => {\n return Number(state.positions.reduce((total, product) => {\n // Проверяем тип листинга\n if (product.listing === 'rent') {\n const start = new Date(product.date.start)\n const end = new Date(product.date.end)\n const diffTime = Math.abs(end - start)\n return total + product.price * (Math.ceil(diffTime / (1000 * 60 * 60 * 24)) + 1);\n } else {\n // Для обычных товаров умножаем на количество\n return total + product.price * (product.quantity || 1);\n }\n }, 0));\n }),\n cartTotalAmount: computed(() => {\n return Number(state.positions.reduce((total, product) => {\n return total + product.quantity;\n }, 0));\n }),\n getStoreCartState: computed(() => {\n return Number(state.currentState);\n }),\n};\n/////////////////////////////\n// History\n/////////////////////////////\nconst history = []\nhistory.push(state) \n\n/////////////////////////////\n// Watch\n/////////////////////////////\nwatch(state, (newState, oldState) => {\n history.push(newState)\n})\n\n/////////////////////////////\n// Module Export\n/////////////////////////////\nexport {\n state,\n actions,\n getters\n}"],"names":[],"mappings":";;;AAYK,MAAC,QAAQ,SAAS;AAAA,EACrB,cAAc;AAAA,EACd,WAAW,CAAE;AAAA,EACb,cAAc;AAChB,CAAC;AAwGI,MAAC,UAAU;AAAA,EAEd,iBAAkB;AAChB,UAAM,eAAe,MAAM,eAAe,QAAQ;AAAA,EACnD;AAAA,EAED,cAAc;AACZ,QAAI;AACF,YAAM,iBAAiB,aAAa,QAAQ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K,KAAK,YAAY,MAAO,KAAK,KAAK,GAAG,IAAI;AAAA,MACtF,OAAa;AAEL,eAAO,QAAQ,QAAQ,SAAS,QAAQ,YAAY;AAAA,MAC5D;AAAA,IACK,GAAE,CAAC,CAAC;AAAA,EACT,CAAG;AAAA,EACD,iBAAiB,SAAS,MAAM;AAC9B,WAAO,OAAO,MAAM,UAAU,OAAO,CAAC,OAAO,YAAY;AACvD,aAAO,QAAQ,QAAQ;AAAA,IACxB,GAAE,CAAC,CAAC;AAAA,EACT,CAAG;AAAA,EACD,mBAAmB,SAAS,MAAM;AAChC,WAAO,OAAO,MAAM,YAAY;AAAA,EACpC,CAAG;AACH;AAUA,MAAM,OAAO,CAAC,UAAU,aAAa;AAErC,CAAC;"}
1
+ {"version":3,"file":"shopcart.js","sources":["../../../../../../src/modules/orders/store/shopcart.js"],"sourcesContent":["/////////////////////////////\n// DEPENDENCIES\n/////////////////////////////\nimport { reactive, watch, computed } from \"vue\";\n// Dependencies\nimport Cookies from 'js-cookie'\n// Globals \nimport { setError } from '@martyrs/src/modules/globals/views/store/globals'\n\n/////////////////////////////\n// State\n/////////////////////////////\nconst state = reactive({\n organization: null,\n positions: [],\n currentState: false\n});\n\n/////////////////////////////\n// Helpers\n/////////////////////////////\nconst helpers = {\n createCartItem(product, organization, type = 'sale') {\n return {\n _id: product._id,\n images: product.images,\n name: product.name,\n price: product.price,\n listing: product.listing,\n quantity: 1,\n org_id: organization,\n type: type\n };\n },\n\n saveToStorage() {\n localStorage.setItem(CART_STORAGE_KEY, JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n },\n\n async validateProduct(product) {\n const serverProduct = await api.fetchProduct(product._id);\n \n if (!serverProduct) {\n return false;\n }\n\n return serverProduct.price === product.price &&\n serverProduct.name === product.name &&\n serverProduct.available !== false;\n }\n};\n\n/////////////////////////////\n// SYNC PRODUCT IN SHOPCART\n/////////////////////////////\n// Constants\nconst CART_STORAGE_KEY = 'shopcart';\nconst SYNC_INTERVAL = 30000; // 30 seconds in milliseconds\n\n// API service\nconst api = {\n async fetchProduct(productId) {\n try {\n const response = await fetch(`/api/products/read`, { _id: productId});\n return await response.json();\n } catch (error) {\n console.error('Failed to fetch product:', error);\n return null;\n }\n }\n};\n\nasync function syncWithServer() {\n try {\n const invalidProducts = [];\n \n for (let i = 0; i < state.positions.length; i++) {\n const product = state.positions[i];\n const serverProduct = await api.fetchProduct(product._id);\n \n if (!serverProduct || \n serverProduct.price !== product.price || \n serverProduct.name !== product.name || \n serverProduct.available === false) {\n invalidProducts.push(product._id);\n }\n }\n\n if (invalidProducts.length > 0) {\n state.positions = state.positions.filter(\n product => !invalidProducts.includes(product._id)\n );\n helpers.saveToStorage();\n setError('Some products were removed from cart due to changes on server');\n }\n } catch (error) {\n console.error('Failed to sync with server:', error);\n }\n}\n// Initialize periodic sync\nlet syncInterval;\n\nconst startPeriodicSync = () => {\n syncInterval = setInterval(syncWithServer, SYNC_INTERVAL);\n};\n\nconst stopPeriodicSync = () => {\n if (syncInterval) {\n clearInterval(syncInterval);\n }\n};\n\n// Start sync when module is imported\n// startPeriodicSync();\n/////////////////////////////\n// Actions\n/////////////////////////////\nconst actions = {\n\n toggleShopcart () {\n state.currentState = state.currentState ? false : true;\n },\n\n setShopcart() {\n try {\n const storedShopcart = localStorage.getItem('shopcart');\n\n if (storedShopcart) {\n const shopcartData = JSON.parse(storedShopcart);\n state.positions = shopcartData.positions; // Восстанавливаем продукты\n state.organization = shopcartData.organization; // Восстанавливаем _id организации\n } \n } catch (error) {\n console.error(error);\n throw error;\n }\n },\n\n\n addProductToCart(product, organization, date) {\n console.log('organization shopcart is', organization)\n const cartItem = state.positions.find(\n (item) => item._id === product._id\n );\n\n if (cartItem) {\n cartItem.quantity++;\n } else {\n state.positions.push({\n _id: product._id,\n images: product.images,\n name: product.name,\n listing: product.listing,\n price: product.price,\n quantity: 1,\n date: date, \n org_id: organization, // Добавляем _id организации к каждому продукту\n });\n }\n state.organization = organization\n\n // Обновляем объект корзины в localStorage, включая _id организации\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: organization // Сохраняем _id организации в корне объекта корзины\n }));\n },\n\n\n removeProduct(_id) {\n const cartItem = state.positions.find(\n (item) => item._id === _id\n );\n const cartItemIndex = state.positions.indexOf(cartItem);\n\n if (cartItemIndex > -1) {\n state.positions.splice(cartItemIndex, 1);\n \n // Сохраняем весь объект корзины, а не только позиции\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n }\n },\n\n\n decrementItemQuantity(_id) {\n const cartItem = state.positions.find(\n (item) => item._id === _id\n );\n const cartItemIndex = state.positions.indexOf(cartItem);\n \n if (cartItemIndex > -1) {\n cartItem.quantity--;\n \n if (cartItem.quantity < 1) {\n state.positions.splice(cartItemIndex, 1);\n }\n\n // Сохраняем весь объект корзины, а не только позиции\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n }\n },\n\n\n incrementItemQuantity(_id) {\n const cartItem = state.positions.find(\n (item) => item._id === _id\n );\n\n if (cartItem) {\n cartItem.quantity++;\n\n // Сохраняем весь объект корзины, а не только позиции\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n }\n },\n\n updateRentDates({ productId, dates }) {\n const product = state.positions.find(p => p._id === productId)\n\n if (product) {\n product.date = dates // Предполагается, что dates — объект { start, end }\n }\n\n localStorage.setItem('shopcart', JSON.stringify({\n positions: state.positions,\n organization: state.organization\n }));\n },\n\n\n resetShopcart() {\n state.positions = [];\n \n localStorage.removeItem('shopcart');\n },\n};\n\n/////////////////////////////\n// Getters\n/////////////////////////////\nconst getters = {\n cartTotalPrice: computed(() => {\n return Number(state.positions.reduce((total, product) => {\n // Проверяем тип листинга\n if (product.listing === 'rent') {\n const start = new Date(product.date.start)\n const end = new Date(product.date.end)\n const diffTime = Math.abs(end - start)\n return total + product.price * (Math.ceil(diffTime / (1000 * 60 * 60 * 24)) + 1);\n } else {\n // Для обычных товаров умножаем на количество\n return total + product.price * (product.quantity || 1);\n }\n }, 0));\n }),\n cartTotalAmount: computed(() => {\n return Number(state.positions.reduce((total, product) => {\n return total + product.quantity;\n }, 0));\n }),\n getStoreCartState: computed(() => {\n return Number(state.currentState);\n }),\n};\n/////////////////////////////\n// History\n/////////////////////////////\nconst history = []\nhistory.push(state) \n\n/////////////////////////////\n// Watch\n/////////////////////////////\nwatch(state, (newState, oldState) => {\n history.push(newState)\n})\n\n/////////////////////////////\n// Module Export\n/////////////////////////////\nexport {\n state,\n actions,\n getters\n}"],"names":[],"mappings":";;;AAYK,MAAC,QAAQ,SAAS;AAAA,EACrB,cAAc;AAAA,EACd,WAAW,CAAE;AAAA,EACb,cAAc;AAChB,CAAC;AAwGI,MAAC,UAAU;AAAA,EAEd,iBAAkB;AAChB,UAAM,eAAe,MAAM,eAAe,QAAQ;AAAA,EACnD;AAAA,EAED,cAAc;AACZ,QAAI;AACF,YAAM,iBAAiB,aAAa,QAAQ,UAAU;AAEtD,UAAI,gBAAgB;AAClB,cAAM,eAAe,KAAK,MAAM,cAAc;AAC9C,cAAM,YAAY,aAAa;AAC/B,cAAM,eAAe,aAAa;AAAA,MACnC;AAAA,IACF,SAAQ,OAAO;AACd,cAAQ,MAAM,KAAK;AACnB,YAAM;AAAA,IACZ;AAAA,EACG;AAAA,EAGD,iBAAiB,SAAS,cAAc,MAAM;AAC5C,YAAQ,IAAI,4BAA4B,YAAY;AACpD,UAAM,WAAW,MAAM,UAAU;AAAA,MAC/B,CAAC,SAAS,KAAK,QAAQ,QAAQ;AAAA,IAChC;AAED,QAAI,UAAU;AACZ,eAAS;AAAA,IACf,OAAW;AACL,YAAM,UAAU,KAAK;AAAA,QACnB,KAAK,QAAQ;AAAA,QACb,QAAQ,QAAQ;AAAA,QAChB,MAAM,QAAQ;AAAA,QACd,SAAS,QAAQ;AAAA,QACjB,OAAO,QAAQ;AAAA,QACf,UAAU;AAAA,QACV;AAAA,QACA,QAAQ;AAAA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,UAAM,UAAU,MAAM,UAAU,KAAK,OAAK,EAAE,QAAQ,SAAS;AAE7D,QAAI,SAAS;AACX,cAAQ,OAAO;AAAA,IACrB;AAEI,iBAAa,QAAQ,YAAY,KAAK,UAAU;AAAA,MAC9C,WAAW,MAAM;AAAA,MACjB,cAAc,MAAM;AAAA,IAC1B,CAAK,CAAC;AAAA,EACH;AAAA,EAGD,gBAAgB;AACd,UAAM,YAAY,CAAE;AAEpB,iBAAa,WAAW,UAAU;AAAA,EACnC;AACH;AAKK,MAAC,UAAU;AAAA,EACd,gBAAgB,SAAS,MAAM;AAC7B,WAAO,OAAO,MAAM,UAAU,OAAO,CAAC,OAAO,YAAY;AAEvD,UAAI,QAAQ,YAAY,QAAQ;AAC9B,cAAM,QAAQ,IAAI,KAAK,QAAQ,KAAK,KAAK;AACzC,cAAM,MAAM,IAAI,KAAK,QAAQ,KAAK,GAAG;AACrC,cAAM,WAAW,KAAK,IAAI,MAAM,KAAK;AACrC,eAAO,QAAQ,QAAQ,SAAS,KAAK,KAAK,YAAY,MAAO,KAAK,KAAK,GAAG,IAAI;AAAA,MACtF,OAAa;AAEL,eAAO,QAAQ,QAAQ,SAAS,QAAQ,YAAY;AAAA,MAC5D;AAAA,IACK,GAAE,CAAC,CAAC;AAAA,EACT,CAAG;AAAA,EACD,iBAAiB,SAAS,MAAM;AAC9B,WAAO,OAAO,MAAM,UAAU,OAAO,CAAC,OAAO,YAAY;AACvD,aAAO,QAAQ,QAAQ;AAAA,IACxB,GAAE,CAAC,CAAC;AAAA,EACT,CAAG;AAAA,EACD,mBAAmB,SAAS,MAAM;AAChC,WAAO,OAAO,MAAM,YAAY;AAAA,EACpC,CAAG;AACH;AAUA,MAAM,OAAO,CAAC,UAAU,aAAa;AAErC,CAAC;"}
@@ -59,9 +59,28 @@ const _sfc_main = {
59
59
  });
60
60
  async function onSubmit() {
61
61
  if (route.params.category) {
62
+ categories.state.current.creator = {
63
+ type: categories.state.current.creator.type,
64
+ hidden: categories.state.current.creator.hidden,
65
+ target: categories.state.current.creator.target._id
66
+ };
67
+ categories.state.current.owner = {
68
+ type: categories.state.current.owner.type,
69
+ target: categories.state.current.owner.target._id
70
+ };
62
71
  await categories.actions.update(categories.state.current);
63
72
  redirectTo();
64
73
  } else {
74
+ categories.state.current.creator = {
75
+ type: "user",
76
+ hidden: false,
77
+ target: auth.state.user._id
78
+ };
79
+ categories.state.current.owner = {
80
+ type: route.params._id ? "organization" : "platform",
81
+ hidden: false,
82
+ target: route.params._id ? route.params._id : null
83
+ };
65
84
  await categories.actions.create(categories.state.current);
66
85
  redirectTo();
67
86
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CategoryEdit.vue.cjs","sources":["../../../../../../../src/modules/products/components/pages/CategoryEdit.vue"],"sourcesContent":["<template>\n <div v-if=\"!isLoading\" class=\"pd-thin bg-white for-transition w-100\">\n <Block v-if=\"!MOBILE_APP\" class=\"radius-big mn-b-thin flex-nowrap flex-v-center flex\">\n <h1 class=\"mn-r-auto\">\n {{route.params.category ? 'Edit Category' : 'Add Category'}}\n </h1>\n\n <Button \n :submit=\"onSubmit\"\n class=\"pd-small radius-big bg-main t-black uppercase t-medium\"\n >\n Save Category \n </Button>\n </Block>\n \n <Block \n title=\"Profile\"\n class=\"mn-b-thin\"\n >\n\n <div class=\"mn-b-medium w-100 flex-nowrap gap-thin flex\">\n <UploadImage \n v-model:photo=\"categories.state.current.photo\"\n :uploadPath=\"'categories'\"\n class=\"w-8r aspect-1x1 o-hidden mn-r-small radius-extra\" \n />\n <Field\n v-model:field=\"categories.state.current.name\"\n label=\"Name\"\n placeholder=\"Enter category name\"\n class=\"w-100 mn-b-small bg-white radius-small pd-medium\"\n /> \n </div>\n\n <div class=\"mn-b-medium w-100 flex-nowrap gap-thin flex\">\n\n\n <Field\n v-model:field=\"categories.state.current.order\"\n label=\"Order\"\n :disabled=\"true\"\n class=\"w-40 bg-white radius-small pd-medium\"\n /> \n <Field\n v-model:field=\"categories.state.current.url\"\n label=\"URL\"\n placeholder=\"Enter category URL\"\n class=\"w-100 bg-white radius-small pd-medium\"\n /> \n \n </div>\n\n <Select \n v-model:select=\"categories.state.current.status\"\n label=\"Status\"\n :options=\"[\n 'draft', \n 'internal',\n 'published',\n 'removed'\n ]\"\n placeholder=\"Display product\"\n class=\"pos-relative w-100 mn-b-small bg-white radius-small pd-medium\"\n />\n\n <div class=\"flex-v-center flex-nowrap flex\">\n <h4 class=\"mn-r-thin t-medium\">Localization</h4>\n \n <button \n @click=\"() => categories.state.current.localization.push({locale: '', text: ''})\" \n class=\"i-small pd-thin button-delete button\"\n >\n +\n </button>\n </div>\n <div \n class=\"gap-thin mn-b-thin flex-nowrap flex\" \n v-for=\"(item, index) in categories.state.current.localization\" \n :key=\"index\"\n > \n <Field\n v-model:field=\"item.locale\"\n placeholder=\"Locale\"\n class=\"w-100 bg-white radius-small pd-medium\"\n /> \n <Field\n v-model:field=\"item.text\"\n placeholder=\"Text\"\n class=\"w-100 bg-white radius-small pd-medium\"\n />\n <div\n @click=\"() => categories.state.current.localization.splice(index, 1)\" \n class=\"radius-small pd-small flex-center flex aspect-1x1 bg-red\"\n >\n <IconDelete \n class=\"i-medium\"\n />\n </div>\n </div>\n\n \n </Block>\n <!-- Subcategories -->\n <!-- <Block\n title=\"Subcategories\"\n placeholder=\"No subcategories added yet\"\n :actions=\"[{\n label: '+',\n function: () => categories.state.current.children.push({name: '', url: ''})\n }]\"\n class=\"mn-b-thin\"\n >\n \n <div \n class=\"gap-thin mn-b-thin flex-nowrap flex\" \n v-for=\"(item, index) in categories.state.current.children\" \n :key=\"index\"\n > \n <Field\n v-model:field=\"item.name\"\n placeholder=\"Subcategory name\"\n class=\"w-100 bg-white radius-small pd-medium\"\n /> \n <Field\n v-model:field=\"item.url\"\n placeholder=\"Subcategory\"\n class=\"w-100 bg-white radius-small pd-medium\"\n />\n <div\n @click=\"() => categories.state.current.children.splice(index, 1)\" \n class=\"radius-small pd-small flex-center flex aspect-1x1 bg-red\"\n >\n <IconDelete \n class=\"i-medium\"\n />\n </div>\n </div> \n </Block> -->\n <!-- Filters -->\n <Block\n title=\"Filters\"\n placeholder=\"No filters added yet\"\n :actions=\"[{\n label: '+',\n function: () => categories.state.current.filters.push({name: '', url: ''})\n }]\"\n >\n <div \n class=\"gap-thin mn-b-thin flex-nowrap flex\" \n v-for=\"(item, index) in categories.state.current.filters\" \n :key=\"index\"\n > \n <Field\n v-model:field=\"item.name\"\n placeholder=\"Filter name\"\n class=\"w-100 bg-white radius-small pd-medium\"\n /> \n <Field\n v-model:field=\"item.options\"\n placeholder=\"Filter options divided by ,\"\n class=\"w-100 bg-white radius-small pd-medium\"\n />\n <div\n @click=\"() => categories.state.current.filters.splice(index, 1)\" \n class=\"radius-small pd-small flex-center flex aspect-1x1 bg-red\"\n >\n <IconDelete \n class=\"i-medium\"\n />\n </div>\n </div> \n </Block>\n </div>\n \n</template>\n\n<script setup>\n // Import libs\n import { computed, onUnmounted, onMounted, ref } from 'vue'\n import { useRoute,useRouter } from 'vue-router'\n \n import IconDelete from '@martyrs/src/modules/icons/navigation/IconDelete.vue';\n\n import Button from \"@martyrs/src/components/Button/Button.vue\";\n import Select from \"@martyrs/src/components/Select/Select.vue\";\n import UploadImage from '@martyrs/src/components/UploadImage/UploadImage.vue';\n import Field from \"@martyrs/src/components/Field/Field.vue\";\n import Feed from '@martyrs/src/components/Feed/Feed.vue'\n\n\n import Block from '@martyrs/src/components/Block/Block.vue';\n\n import IconCheckmark from '@martyrs/src/modules/icons/navigation/IconCheckmark.vue'\n\n // Import the new store structure\n import * as globals from '@martyrs/src/modules/globals/views/store/globals';\n import * as auth from '@martyrs/src/modules/auth/views/store/auth'; \n import * as categories from '@martyrs/src/modules/products/store/categories';\n\n const route = useRoute()\n const router = useRouter()\n\n const emits = defineEmits(['page-loading', 'page-loaded']);\n\n // Data prefetching\n const isLoading = ref(true)\n onMounted(async () => {\n emits('page-loading');\n if (route.params.category) {\n await categories.actions.read({url: route.params.category})\n } else {\n categories.actions.clean() // Adjusted based on the new store's method to reset the category state\n }\n\n emits('page-loaded');\n isLoading.value = false\n })\n\n // Accessing state\n const category = computed(() => categories.state.current)\n const routePath = computed(() => route.name)\n\n // Navigation Bar\n globals.state.navigation_bar.actions = [{\n component: IconCheckmark,\n props: {\n fill: \"rgb(var(--main))\" \n },\n condition: () => auth.state.user && auth.state.user._id,\n action: () => onSubmit()\n }],\n\n onUnmounted(() => {\n globals.state.navigation_bar.actions = [];\n });\n\n\n\n // Functions\n async function onSubmit() {\n if (route.params.category) {\n await categories.actions.update(categories.state.current)\n redirectTo()\n } else {\n await categories.actions.create(categories.state.current)\n redirectTo()\n }\n }\n\n function redirectTo () {\n router.push({\n name: 'Categories', \n params: { \n _id: route.params._id\n } \n })\n }\n</script>\n\n<style lang=\"scss\">\n /* Your styles here */\n</style>\n"],"names":["useRoute","useRouter","ref","onMounted","categories.actions","computed","categories.state","globals.state","IconCheckmark","auth.state","onUnmounted"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuME,UAAM,QAAQA,UAAQ,SAAA;AACtB,UAAM,SAASC,UAAS,UAAA;AAExB,UAAM,QAAQ;AAGd,UAAM,YAAYC,IAAAA,IAAI,IAAI;AAC1BC,QAAAA,UAAU,YAAY;AACpB,YAAM,cAAc;AACpB,UAAI,MAAM,OAAO,UAAU;AACzB,cAAMC,WAAAA,QAAmB,KAAK,EAAC,KAAK,MAAM,OAAO,SAAQ,CAAC;AAAA,MAChE,OAAW;AACLA,mBAAAA,QAAmB,MAAO;AAAA,MAChC;AAEI,YAAM,aAAa;AACnB,gBAAU,QAAQ;AAAA,IACnB,CAAA;AAGgBC,QAAQ,SAAC,MAAMC,WAAAA,MAAiB,OAAO;AACtCD,QAAQ,SAAC,MAAM,MAAM,IAAI;AAG3CE,kBAAc,eAAe,UAAU,CAAC;AAAA,MACtC,WAAWC,cAAa;AAAA,MACxB,OAAO;AAAA,QACL,MAAM;AAAA,MACP;AAAA,MACD,WAAW,MAAMC,KAAU,MAAC,QAAQA,KAAU,MAAC,KAAK;AAAA,MACpD,QAAQ,MAAM,SAAQ;AAAA,IAC1B,CAAG,GAEFC,IAAAA,YAAY,MAAM;AACfH,oBAAc,eAAe,UAAU,CAAE;AAAA,IAC7C,CAAG;AAKD,mBAAe,WAAW;AACxB,UAAI,MAAM,OAAO,UAAU;AACzB,cAAMH,WAAkB,QAAC,OAAOE,WAAAA,MAAiB,OAAO;AACxD,mBAAU;AAAA,MAChB,OAAW;AACL,cAAMF,WAAkB,QAAC,OAAOE,WAAAA,MAAiB,OAAO;AACxD,mBAAU;AAAA,MAChB;AAAA,IACA;AAEE,aAAS,aAAc;AACrB,aAAO,KAAK;AAAA,QACV,MAAM;AAAA,QACN,QAAQ;AAAA,UACN,KAAK,MAAM,OAAO;AAAA,QACnB;AAAA,MACF,CAAA;AAAA,IACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"CategoryEdit.vue.cjs","sources":["../../../../../../../src/modules/products/components/pages/CategoryEdit.vue"],"sourcesContent":["<template>\n <div v-if=\"!isLoading\" class=\"pd-thin bg-white for-transition w-100\">\n <Block v-if=\"!MOBILE_APP\" class=\"radius-big mn-b-thin flex-nowrap flex-v-center flex\">\n <h1 class=\"mn-r-auto\">\n {{route.params.category ? 'Edit Category' : 'Add Category'}}\n </h1>\n\n <Button \n :submit=\"onSubmit\"\n class=\"pd-small radius-big bg-main t-black uppercase t-medium\"\n >\n Save Category \n </Button>\n </Block>\n \n <Block \n title=\"Profile\"\n class=\"mn-b-thin\"\n >\n <div class=\"mn-b-medium w-100 flex-nowrap gap-thin flex\">\n <UploadImage \n v-model:photo=\"categories.state.current.photo\"\n :uploadPath=\"'categories'\"\n class=\"w-8r aspect-1x1 o-hidden mn-r-small radius-extra\" \n />\n <Field\n v-model:field=\"categories.state.current.name\"\n label=\"Name\"\n placeholder=\"Enter category name\"\n class=\"w-100 mn-b-small bg-white radius-small pd-medium\"\n /> \n </div>\n\n <div class=\"mn-b-medium w-100 flex-nowrap gap-thin flex\">\n\n\n <Field\n v-model:field=\"categories.state.current.order\"\n label=\"Order\"\n :disabled=\"true\"\n class=\"w-40 bg-white radius-small pd-medium\"\n /> \n <Field\n v-model:field=\"categories.state.current.url\"\n label=\"URL\"\n placeholder=\"Enter category URL\"\n class=\"w-100 bg-white radius-small pd-medium\"\n /> \n \n </div>\n\n <Select \n v-model:select=\"categories.state.current.status\"\n label=\"Status\"\n :options=\"[\n 'draft', \n 'internal',\n 'published',\n 'removed'\n ]\"\n placeholder=\"Display product\"\n class=\"pos-relative w-100 mn-b-small bg-white radius-small pd-medium\"\n />\n\n <div class=\"flex-v-center flex-nowrap flex\">\n <h4 class=\"mn-r-thin t-medium\">Localization</h4>\n \n <button \n @click=\"() => categories.state.current.localization.push({locale: '', text: ''})\" \n class=\"i-small pd-thin button-delete button\"\n >\n +\n </button>\n </div>\n <div \n class=\"gap-thin mn-b-thin flex-nowrap flex\" \n v-for=\"(item, index) in categories.state.current.localization\" \n :key=\"index\"\n > \n <Field\n v-model:field=\"item.locale\"\n placeholder=\"Locale\"\n class=\"w-100 bg-white radius-small pd-medium\"\n /> \n <Field\n v-model:field=\"item.text\"\n placeholder=\"Text\"\n class=\"w-100 bg-white radius-small pd-medium\"\n />\n <div\n @click=\"() => categories.state.current.localization.splice(index, 1)\" \n class=\"radius-small pd-small flex-center flex aspect-1x1 bg-red\"\n >\n <IconDelete \n class=\"i-medium\"\n />\n </div>\n </div>\n\n \n </Block>\n <!-- Subcategories -->\n <!-- <Block\n title=\"Subcategories\"\n placeholder=\"No subcategories added yet\"\n :actions=\"[{\n label: '+',\n function: () => categories.state.current.children.push({name: '', url: ''})\n }]\"\n class=\"mn-b-thin\"\n >\n \n <div \n class=\"gap-thin mn-b-thin flex-nowrap flex\" \n v-for=\"(item, index) in categories.state.current.children\" \n :key=\"index\"\n > \n <Field\n v-model:field=\"item.name\"\n placeholder=\"Subcategory name\"\n class=\"w-100 bg-white radius-small pd-medium\"\n /> \n <Field\n v-model:field=\"item.url\"\n placeholder=\"Subcategory\"\n class=\"w-100 bg-white radius-small pd-medium\"\n />\n <div\n @click=\"() => categories.state.current.children.splice(index, 1)\" \n class=\"radius-small pd-small flex-center flex aspect-1x1 bg-red\"\n >\n <IconDelete \n class=\"i-medium\"\n />\n </div>\n </div> \n </Block> -->\n <!-- Filters -->\n <Block\n title=\"Filters\"\n placeholder=\"No filters added yet\"\n :actions=\"[{\n label: '+',\n function: () => categories.state.current.filters.push({name: '', url: ''})\n }]\"\n >\n <div \n class=\"gap-thin mn-b-thin flex-nowrap flex\" \n v-for=\"(item, index) in categories.state.current.filters\" \n :key=\"index\"\n > \n <Field\n v-model:field=\"item.name\"\n placeholder=\"Filter name\"\n class=\"w-100 bg-white radius-small pd-medium\"\n /> \n <Field\n v-model:field=\"item.options\"\n placeholder=\"Filter options divided by ,\"\n class=\"w-100 bg-white radius-small pd-medium\"\n />\n <div\n @click=\"() => categories.state.current.filters.splice(index, 1)\" \n class=\"radius-small pd-small flex-center flex aspect-1x1 bg-red\"\n >\n <IconDelete \n class=\"i-medium\"\n />\n </div>\n </div> \n </Block>\n </div>\n \n</template>\n\n<script setup>\n // Import libs\n import { computed, onUnmounted, onMounted, ref } from 'vue'\n import { useRoute,useRouter } from 'vue-router'\n \n import IconDelete from '@martyrs/src/modules/icons/navigation/IconDelete.vue';\n\n import Button from \"@martyrs/src/components/Button/Button.vue\";\n import Select from \"@martyrs/src/components/Select/Select.vue\";\n import UploadImage from '@martyrs/src/components/UploadImage/UploadImage.vue';\n import Field from \"@martyrs/src/components/Field/Field.vue\";\n import Feed from '@martyrs/src/components/Feed/Feed.vue'\n\n\n import Block from '@martyrs/src/components/Block/Block.vue';\n\n import IconCheckmark from '@martyrs/src/modules/icons/navigation/IconCheckmark.vue'\n\n // Import the new store structure\n import * as globals from '@martyrs/src/modules/globals/views/store/globals';\n import * as auth from '@martyrs/src/modules/auth/views/store/auth'; \n import * as categories from '@martyrs/src/modules/products/store/categories';\n\n const route = useRoute()\n const router = useRouter()\n\n const emits = defineEmits(['page-loading', 'page-loaded']);\n\n // Data prefetching\n const isLoading = ref(true)\n onMounted(async () => {\n emits('page-loading');\n if (route.params.category) {\n await categories.actions.read({url: route.params.category})\n } else {\n categories.actions.clean() // Adjusted based on the new store's method to reset the category state\n }\n\n emits('page-loaded');\n isLoading.value = false\n })\n\n // Accessing state\n const category = computed(() => categories.state.current)\n const routePath = computed(() => route.name)\n\n // Navigation Bar\n globals.state.navigation_bar.actions = [{\n component: IconCheckmark,\n props: {\n fill: \"rgb(var(--main))\" \n },\n condition: () => auth.state.user && auth.state.user._id,\n action: () => onSubmit()\n }],\n\n onUnmounted(() => {\n globals.state.navigation_bar.actions = [];\n });\n\n\n\n // Functions\n async function onSubmit() {\n if (route.params.category) {\n\n categories.state.current.creator = {\n type: categories.state.current.creator.type,\n hidden: categories.state.current.creator.hidden,\n target: categories.state.current.creator.target._id\n }\n\n categories.state.current.owner = {\n type: categories.state.current.owner.type,\n target: categories.state.current.owner.target._id\n }\n\n await categories.actions.update(categories.state.current)\n\n redirectTo()\n } else {\n\n categories.state.current.creator = {\n type: 'user',\n hidden: false,\n target: auth.state.user._id\n }\n\n categories.state.current.owner = {\n type: route.params._id ? 'organization' : 'platform',\n hidden: false,\n target: route.params._id ? route.params._id : null\n }\n\n await categories.actions.create(categories.state.current)\n redirectTo()\n }\n }\n\n function redirectTo () {\n router.push({\n name: 'Categories', \n params: { \n _id: route.params._id\n } \n })\n }\n</script>\n\n<style lang=\"scss\">\n /* Your styles here */\n</style>\n"],"names":["useRoute","useRouter","ref","onMounted","categories.actions","computed","categories.state","globals.state","IconCheckmark","auth.state","onUnmounted"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AChB,OAAW;AAELA,mBAAgB,MAAC,QAAQ,UAAU;AAAA,UACjC,MAAM;AAAA,UACN,QAAQ;AAAA,UACR,QAAQG,KAAU,MAAC,KAAK;AAAA,QAChC;AAEMH,mBAAgB,MAAC,QAAQ,QAAQ;AAAA,UAC/B,MAAM,MAAM,OAAO,MAAM,iBAAiB;AAAA,UAC1C,QAAQ;AAAA,UACR,QAAQ,MAAM,OAAO,MAAM,MAAM,OAAO,MAAM;AAAA,QACtD;AAEM,cAAMF,WAAkB,QAAC,OAAOE,WAAAA,MAAiB,OAAO;AACxD,mBAAU;AAAA,MAChB;AAAA,IACA;AAEE,aAAS,aAAc;AACrB,aAAO,KAAK;AAAA,QACV,MAAM;AAAA,QACN,QAAQ;AAAA,UACN,KAAK,MAAM,OAAO;AAAA,QACnB;AAAA,MACF,CAAA;AAAA,IACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -57,9 +57,28 @@ const _sfc_main = {
57
57
  });
58
58
  async function onSubmit() {
59
59
  if (route.params.category) {
60
+ state.current.creator = {
61
+ type: state.current.creator.type,
62
+ hidden: state.current.creator.hidden,
63
+ target: state.current.creator.target._id
64
+ };
65
+ state.current.owner = {
66
+ type: state.current.owner.type,
67
+ target: state.current.owner.target._id
68
+ };
60
69
  await actions.update(state.current);
61
70
  redirectTo();
62
71
  } else {
72
+ state.current.creator = {
73
+ type: "user",
74
+ hidden: false,
75
+ target: state$1.user._id
76
+ };
77
+ state.current.owner = {
78
+ type: route.params._id ? "organization" : "platform",
79
+ hidden: false,
80
+ target: route.params._id ? route.params._id : null
81
+ };
63
82
  await actions.create(state.current);
64
83
  redirectTo();
65
84
  }