@ozdao/prometheus-framework 0.2.309 → 0.2.311

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. package/dist/products.server.js +192 -195
  2. package/dist/products.server.mjs +192 -195
  3. package/dist/prometheus-framework/src/components/Block/Block.vue.cjs +1 -1
  4. package/dist/prometheus-framework/src/components/Block/Block.vue.cjs.map +1 -1
  5. package/dist/prometheus-framework/src/components/Block/Block.vue.js +1 -1
  6. package/dist/prometheus-framework/src/components/Block/Block.vue.js.map +1 -1
  7. package/dist/prometheus-framework/src/components/Chips/Chips.vue2.cjs +2 -1
  8. package/dist/prometheus-framework/src/components/Chips/Chips.vue2.cjs.map +1 -1
  9. package/dist/prometheus-framework/src/components/Chips/Chips.vue2.js +3 -2
  10. package/dist/prometheus-framework/src/components/Chips/Chips.vue2.js.map +1 -1
  11. package/dist/prometheus-framework/src/components/EditImages/EditImages.vue2.cjs +1 -1
  12. package/dist/prometheus-framework/src/components/EditImages/EditImages.vue2.cjs.map +1 -1
  13. package/dist/prometheus-framework/src/components/EditImages/EditImages.vue2.js +1 -1
  14. package/dist/prometheus-framework/src/components/EditImages/EditImages.vue2.js.map +1 -1
  15. package/dist/prometheus-framework/src/components/Field/Field.vue.cjs +13 -12
  16. package/dist/prometheus-framework/src/components/Field/Field.vue.cjs.map +1 -1
  17. package/dist/prometheus-framework/src/components/Field/Field.vue.js +13 -12
  18. package/dist/prometheus-framework/src/components/Field/Field.vue.js.map +1 -1
  19. package/dist/prometheus-framework/src/modules/auth/views/middlewares/auth.validation.cjs +1 -0
  20. package/dist/prometheus-framework/src/modules/auth/views/middlewares/auth.validation.cjs.map +1 -1
  21. package/dist/prometheus-framework/src/modules/auth/views/middlewares/auth.validation.js +1 -0
  22. package/dist/prometheus-framework/src/modules/auth/views/middlewares/auth.validation.js.map +1 -1
  23. package/dist/prometheus-framework/src/modules/auth/views/store/auth.cjs +6 -2
  24. package/dist/prometheus-framework/src/modules/auth/views/store/auth.cjs.map +1 -1
  25. package/dist/prometheus-framework/src/modules/auth/views/store/auth.js +6 -2
  26. package/dist/prometheus-framework/src/modules/auth/views/store/auth.js.map +1 -1
  27. package/dist/prometheus-framework/src/modules/backoffice/components/pages/Dashboard.vue.cjs +2 -4
  28. package/dist/prometheus-framework/src/modules/backoffice/components/pages/Dashboard.vue.cjs.map +1 -1
  29. package/dist/prometheus-framework/src/modules/backoffice/components/pages/Dashboard.vue.js +3 -5
  30. package/dist/prometheus-framework/src/modules/backoffice/components/pages/Dashboard.vue.js.map +1 -1
  31. package/dist/prometheus-framework/src/modules/community/components/layouts/Community.vue.cjs +1 -1
  32. package/dist/prometheus-framework/src/modules/community/components/layouts/Community.vue.js +1 -1
  33. package/dist/prometheus-framework/src/modules/community/components/pages/Community.vue.cjs +1 -1
  34. package/dist/prometheus-framework/src/modules/community/components/pages/Community.vue.js +1 -1
  35. package/dist/prometheus-framework/src/modules/gallery/components/sections/BackofficeGallery.vue.cjs +1 -1
  36. package/dist/prometheus-framework/src/modules/gallery/components/sections/BackofficeGallery.vue.js +1 -1
  37. package/dist/prometheus-framework/src/modules/globals/views/components/partials/BottomNavigationBar.vue.cjs +3 -3
  38. package/dist/prometheus-framework/src/modules/globals/views/components/partials/BottomNavigationBar.vue.cjs.map +1 -1
  39. package/dist/prometheus-framework/src/modules/globals/views/components/partials/BottomNavigationBar.vue.js +3 -3
  40. package/dist/prometheus-framework/src/modules/globals/views/components/partials/BottomNavigationBar.vue.js.map +1 -1
  41. package/dist/prometheus-framework/src/modules/globals/views/components/partials/Header.vue.cjs +1 -1
  42. package/dist/prometheus-framework/src/modules/globals/views/components/partials/Header.vue.js +1 -1
  43. package/dist/prometheus-framework/src/modules/globals/views/components/partials/NavigationBar.vue.cjs +18 -15
  44. package/dist/prometheus-framework/src/modules/globals/views/components/partials/NavigationBar.vue.cjs.map +1 -1
  45. package/dist/prometheus-framework/src/modules/globals/views/components/partials/NavigationBar.vue.js +21 -18
  46. package/dist/prometheus-framework/src/modules/globals/views/components/partials/NavigationBar.vue.js.map +1 -1
  47. package/dist/prometheus-framework/src/modules/globals/views/store/globals.cjs +4 -0
  48. package/dist/prometheus-framework/src/modules/globals/views/store/globals.cjs.map +1 -1
  49. package/dist/prometheus-framework/src/modules/globals/views/store/globals.js +4 -0
  50. package/dist/prometheus-framework/src/modules/globals/views/store/globals.js.map +1 -1
  51. package/dist/prometheus-framework/src/modules/orders/components/pages/OrderCreateBackoffice.vue.cjs +1 -1
  52. package/dist/prometheus-framework/src/modules/orders/components/pages/OrderCreateBackoffice.vue.js +1 -1
  53. package/dist/prometheus-framework/src/modules/orders/components/sections/FormAddCustomer.vue.cjs +1 -1
  54. package/dist/prometheus-framework/src/modules/orders/components/sections/FormAddCustomer.vue.js +1 -1
  55. package/dist/prometheus-framework/src/modules/orders/components/sections/FormCustomerDetails.vue.cjs +1 -1
  56. package/dist/prometheus-framework/src/modules/orders/components/sections/FormCustomerDetails.vue.js +1 -1
  57. package/dist/prometheus-framework/src/modules/orders/components/sections/FormPayment.vue.cjs +1 -1
  58. package/dist/prometheus-framework/src/modules/orders/components/sections/FormPayment.vue.js +1 -1
  59. package/dist/prometheus-framework/src/modules/organizations/components/pages/DepartmentEdit.vue.cjs +1 -1
  60. package/dist/prometheus-framework/src/modules/organizations/components/pages/DepartmentEdit.vue.js +1 -1
  61. package/dist/prometheus-framework/src/modules/organizations/components/pages/Organization.vue.cjs +1 -1
  62. package/dist/prometheus-framework/src/modules/organizations/components/pages/Organization.vue.cjs.map +1 -1
  63. package/dist/prometheus-framework/src/modules/organizations/components/pages/Organization.vue.js +1 -1
  64. package/dist/prometheus-framework/src/modules/organizations/components/pages/Organization.vue.js.map +1 -1
  65. package/dist/prometheus-framework/src/modules/organizations/components/pages/OrganizationBackoffice.vue.cjs +1 -2
  66. package/dist/prometheus-framework/src/modules/organizations/components/pages/OrganizationBackoffice.vue.cjs.map +1 -1
  67. package/dist/prometheus-framework/src/modules/organizations/components/pages/OrganizationBackoffice.vue.js +2 -3
  68. package/dist/prometheus-framework/src/modules/organizations/components/pages/OrganizationBackoffice.vue.js.map +1 -1
  69. package/dist/prometheus-framework/src/modules/organizations/components/pages/OrganizationEdit.vue.cjs +1 -1
  70. package/dist/prometheus-framework/src/modules/organizations/components/pages/OrganizationEdit.vue.js +1 -1
  71. package/dist/prometheus-framework/src/modules/organizations/components/sections/MembersAdd.vue.cjs +1 -1
  72. package/dist/prometheus-framework/src/modules/organizations/components/sections/MembersAdd.vue.js +1 -1
  73. package/dist/prometheus-framework/src/modules/organizations/components/sections/Organizations.vue.cjs +1 -1
  74. package/dist/prometheus-framework/src/modules/organizations/components/sections/Organizations.vue.js +1 -1
  75. package/dist/prometheus-framework/src/modules/pages/pages.client.cjs +554 -554
  76. package/dist/prometheus-framework/src/modules/pages/pages.client.js +554 -554
  77. package/dist/prometheus-framework/src/modules/products/components/blocks/CardCategory.vue.cjs +3 -3
  78. package/dist/prometheus-framework/src/modules/products/components/blocks/CardCategory.vue.cjs.map +1 -1
  79. package/dist/prometheus-framework/src/modules/products/components/blocks/CardCategory.vue.js +3 -3
  80. package/dist/prometheus-framework/src/modules/products/components/blocks/CardCategory.vue.js.map +1 -1
  81. package/dist/prometheus-framework/src/modules/products/components/blocks/CardPosition.vue.cjs +1 -1
  82. package/dist/prometheus-framework/src/modules/products/components/blocks/CardPosition.vue.js +1 -1
  83. package/dist/prometheus-framework/src/modules/products/components/blocks/CardProduct.vue.cjs +11 -10
  84. package/dist/prometheus-framework/src/modules/products/components/blocks/CardProduct.vue.cjs.map +1 -1
  85. package/dist/prometheus-framework/src/modules/products/components/blocks/CardProduct.vue.js +11 -10
  86. package/dist/prometheus-framework/src/modules/products/components/blocks/CardProduct.vue.js.map +1 -1
  87. package/dist/prometheus-framework/src/modules/products/components/pages/Categories.vue.cjs +78 -43
  88. package/dist/prometheus-framework/src/modules/products/components/pages/Categories.vue.cjs.map +1 -1
  89. package/dist/prometheus-framework/src/modules/products/components/pages/Categories.vue.js +83 -48
  90. package/dist/prometheus-framework/src/modules/products/components/pages/Categories.vue.js.map +1 -1
  91. package/dist/prometheus-framework/src/modules/products/components/pages/CategoryEdit.vue.cjs +80 -30
  92. package/dist/prometheus-framework/src/modules/products/components/pages/CategoryEdit.vue.cjs.map +1 -1
  93. package/dist/prometheus-framework/src/modules/products/components/pages/CategoryEdit.vue.js +91 -41
  94. package/dist/prometheus-framework/src/modules/products/components/pages/CategoryEdit.vue.js.map +1 -1
  95. package/dist/prometheus-framework/src/modules/products/components/pages/EditLeftover.vue.cjs +1 -1
  96. package/dist/prometheus-framework/src/modules/products/components/pages/EditLeftover.vue.js +1 -1
  97. package/dist/prometheus-framework/src/modules/products/components/pages/ProductEdit.vue.cjs +119 -80
  98. package/dist/prometheus-framework/src/modules/products/components/pages/ProductEdit.vue.cjs.map +1 -1
  99. package/dist/prometheus-framework/src/modules/products/components/pages/ProductEdit.vue.js +132 -93
  100. package/dist/prometheus-framework/src/modules/products/components/pages/ProductEdit.vue.js.map +1 -1
  101. package/dist/prometheus-framework/src/modules/products/components/pages/Products.vue.cjs +39 -21
  102. package/dist/prometheus-framework/src/modules/products/components/pages/Products.vue.cjs.map +1 -1
  103. package/dist/prometheus-framework/src/modules/products/components/pages/Products.vue.js +51 -33
  104. package/dist/prometheus-framework/src/modules/products/components/pages/Products.vue.js.map +1 -1
  105. package/dist/prometheus-framework/src/modules/products/components/sections/CategoriesTree.vue.cjs +96 -0
  106. package/dist/prometheus-framework/src/modules/products/components/sections/CategoriesTree.vue.cjs.map +1 -0
  107. package/dist/prometheus-framework/src/modules/products/components/sections/CategoriesTree.vue.js +96 -0
  108. package/dist/prometheus-framework/src/modules/products/components/sections/CategoriesTree.vue.js.map +1 -0
  109. package/dist/prometheus-framework/src/modules/products/components/sections/EditProductInfo.vue.cjs +21 -7
  110. package/dist/prometheus-framework/src/modules/products/components/sections/EditProductInfo.vue.cjs.map +1 -1
  111. package/dist/prometheus-framework/src/modules/products/components/sections/EditProductInfo.vue.js +21 -7
  112. package/dist/prometheus-framework/src/modules/products/components/sections/EditProductInfo.vue.js.map +1 -1
  113. package/dist/prometheus-framework/src/modules/products/components/sections/Filters.vue.cjs +1 -1
  114. package/dist/prometheus-framework/src/modules/products/components/sections/Filters.vue.js +1 -1
  115. package/dist/prometheus-framework/src/modules/products/products.client.cjs.map +1 -1
  116. package/dist/prometheus-framework/src/modules/products/products.client.js.map +1 -1
  117. package/dist/prometheus-framework/src/modules/products/router/categories.router.cjs +17 -5
  118. package/dist/prometheus-framework/src/modules/products/router/categories.router.cjs.map +1 -1
  119. package/dist/prometheus-framework/src/modules/products/router/categories.router.js +17 -5
  120. package/dist/prometheus-framework/src/modules/products/router/categories.router.js.map +1 -1
  121. package/dist/prometheus-framework/src/modules/products/router/products.router.cjs +1 -12
  122. package/dist/prometheus-framework/src/modules/products/router/products.router.cjs.map +1 -1
  123. package/dist/prometheus-framework/src/modules/products/router/products.router.js +1 -12
  124. package/dist/prometheus-framework/src/modules/products/router/products.router.js.map +1 -1
  125. package/dist/prometheus-framework/src/modules/products/store/categories.cjs +52 -71
  126. package/dist/prometheus-framework/src/modules/products/store/categories.cjs.map +1 -1
  127. package/dist/prometheus-framework/src/modules/products/store/categories.js +52 -71
  128. package/dist/prometheus-framework/src/modules/products/store/categories.js.map +1 -1
  129. package/dist/prometheus-framework/src/modules/products/store/products.cjs +6 -8
  130. package/dist/prometheus-framework/src/modules/products/store/products.cjs.map +1 -1
  131. package/dist/prometheus-framework/src/modules/products/store/products.js +6 -8
  132. package/dist/prometheus-framework/src/modules/products/store/products.js.map +1 -1
  133. package/dist/prometheus-framework/src/modules/reports/components/sections/FormReport.vue.cjs +1 -1
  134. package/dist/prometheus-framework/src/modules/reports/components/sections/FormReport.vue.js +1 -1
  135. package/dist/prometheus-framework/src/modules/spots/components/blocks/SpotMemberModify.vue.cjs +1 -1
  136. package/dist/prometheus-framework/src/modules/spots/components/blocks/SpotMemberModify.vue.js +1 -1
  137. package/dist/prometheus-framework/src/modules/spots/components/pages/SpotEdit.vue.cjs +1 -1
  138. package/dist/prometheus-framework/src/modules/spots/components/pages/SpotEdit.vue.js +1 -1
  139. package/dist/prometheus-framework/src/modules/wallet/views/components/blocks/CryptoDeposit.vue.cjs +1 -1
  140. package/dist/prometheus-framework/src/modules/wallet/views/components/blocks/CryptoDeposit.vue.js +1 -1
  141. package/dist/prometheus-framework/src/modules/wallet/views/components/pages/Wallet.vue.cjs +1 -1
  142. package/dist/prometheus-framework/src/modules/wallet/views/components/pages/Wallet.vue.js +1 -1
  143. package/package.json +1 -1
  144. package/src/components/Block/Block.vue +1 -1
  145. package/src/components/EditImages/EditImages.vue +1 -1
  146. package/src/modules/auth/views/middlewares/auth.validation.js +1 -0
  147. package/src/modules/auth/views/store/auth.js +6 -2
  148. package/src/modules/backoffice/components/pages/Dashboard.vue +1 -3
  149. package/src/modules/globals/views/components/partials/BottomNavigationBar.vue +3 -3
  150. package/src/modules/globals/views/components/partials/NavigationBar.vue +4 -4
  151. package/src/modules/globals/views/store/globals.js +5 -0
  152. package/src/modules/organizations/components/pages/Organization.vue +1 -1
  153. package/src/modules/organizations/components/pages/OrganizationBackoffice.vue +1 -2
  154. package/src/modules/products/components/blocks/CardCategory.vue +14 -3
  155. package/src/modules/products/components/blocks/CardProduct.vue +12 -11
  156. package/src/modules/products/components/pages/Categories.vue +120 -28
  157. package/src/modules/products/components/pages/CategoryEdit.vue +206 -151
  158. package/src/modules/products/components/pages/ProductEdit.vue +107 -69
  159. package/src/modules/products/components/pages/Products.vue +35 -20
  160. package/src/modules/products/components/sections/CategoriesTree.vue +102 -0
  161. package/src/modules/products/components/sections/EditProductInfo.vue +53 -40
  162. package/src/modules/products/controllers/categories.controller.js +175 -97
  163. package/src/modules/products/controllers/products.controller.js +4 -2
  164. package/src/modules/products/models/category.model.js +15 -66
  165. package/src/modules/products/models/product.model.js +15 -12
  166. package/src/modules/products/products.client.js +0 -1
  167. package/src/modules/products/router/categories.router.js +17 -5
  168. package/src/modules/products/router/products.router.js +0 -12
  169. package/src/modules/products/routes/categories.routes.js +5 -34
  170. package/src/modules/products/store/categories.js +69 -83
  171. package/src/modules/products/store/products.js +6 -8
@@ -7,7 +7,7 @@
7
7
  <h2 class="mn-r-medium">Products</h2>
8
8
  <button
9
9
  @click="$router.push({
10
- name: route.params._id ? 'Organization_ProductAdd' : 'ProductAdd'
10
+ name: route.params?._id ? 'Organization_ProductAdd' : 'ProductAdd'
11
11
  })"
12
12
  class="radius-100 i-big hover-scale-1 cursor-pointer t-white bg-second">
13
13
  +
@@ -31,8 +31,9 @@
31
31
  gap-micro pd-small pd-t-thin pd-b-thin
32
32
  pos-sticky pos-t-0
33
33
  z-index-1
34
+
34
35
  "
35
- tabClass="bg-white pd-small radius-small w-100"
36
+ tabClass="bg-white uppercase pd-small radius-small w-100"
36
37
  />
37
38
 
38
39
  <div class="cols-2-1_3 h-100 z-index-3 pos-relative radius-big gap-thin">
@@ -67,7 +68,7 @@
67
68
  }"
68
69
  :options="{
69
70
  limit: 15,
70
- organization: route.params._id,
71
+ owner: route.params._id,
71
72
  categories: route.query.categories,
72
73
  prices: route.query.prices,
73
74
  delivery: route.query.delivery,
@@ -78,23 +79,22 @@
78
79
  v-slot="{
79
80
  items
80
81
  }"
81
- class="cols-4 pd-thin gap-thin"
82
+ class="cols-4 rows-1 pd-t-zero pd-thin gap-thin"
82
83
  >
83
- <CardProduct
84
- v-for="product in items"
85
- :key="product._id"
86
- :product="product"
87
- :user="auth.state.access"
88
- class="h-max bg-white"
89
- @click.capture="$router.push({
90
- name: 'Organization_Product',
91
- params: {
92
- _id: route.params._id,
93
- product: product._id
94
- }
95
- })"
96
- />
84
+ <router-link
85
+ v-for="product in items"
86
+ :to="route.params._id ? { name: 'Organization_Product', params: { _id: route.params._id, product: product._id } } : { name: 'Product', params: { product: product._id } }">
87
+ <CardProduct
88
+ :key="product._id"
89
+ :product="product"
90
+ :user="auth.state.access"
91
+ :organization="route.params._id"
92
+ :access="hasAccess(route.params._id, 'products', 'edit', auth.state.accesses)"
93
+ class="h-max bg-light"
94
+ />
95
+ </router-link>
97
96
  </Feed>
97
+
98
98
  </div>
99
99
  </div>
100
100
  </div>
@@ -103,7 +103,7 @@
103
103
 
104
104
  <script setup="props">
105
105
  // Import libs
106
- import { computed, watch, onMounted, ref } from 'vue'
106
+ import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
107
107
  import { useRoute, useRouter } from 'vue-router'
108
108
 
109
109
  // Import components
@@ -116,8 +116,11 @@
116
116
 
117
117
  import CardProduct from '@pf/src/modules/products/components/blocks/CardProduct.vue'
118
118
 
119
+ import IconPlus from '@pf/src/modules/icons/navigation/IconPlus.vue'
120
+
119
121
  // Accessing router and store
120
122
  import * as auth from '@pf/src/modules/auth/views/store/auth';
123
+ import * as globals from '@pf/src/modules/globals/views/store/globals';
121
124
  import * as products from '@pf/src/modules/products/store/products';
122
125
  import * as marketplace from '@pf/src/modules/products/store/marketplace';
123
126
  import * as categories from '@pf/src/modules/products/store/categories';
@@ -138,11 +141,19 @@
138
141
  marketplace.state.filter.selected.delivery = query.delivery ? query.delivery.split(',') : [];
139
142
  }
140
143
 
141
-
142
144
  watch(tabProducts, (newValue) => {
143
145
  if (route.name !== 'Organization') router.replace({ query: { ...route.query, tabProducts: newValue } });
144
146
  });
145
147
 
148
+ globals.state.navigation_bar.actions = [{
149
+ component: IconPlus,
150
+ props: {
151
+ fill: "rgb(var(--main))"
152
+ },
153
+ condition: () => auth.state.user && auth.state.user._id,
154
+ action: () => route.params._id ? router.push({ name: 'Organization_ProductAdd', params: { _id: route.params._id} }) : router.push({ name: 'ProductAdd' })
155
+ }],
156
+
146
157
  onMounted(async () => {
147
158
  let categoriesFilter = await categories.actions.fetchCategories();
148
159
 
@@ -166,6 +177,10 @@
166
177
  }
167
178
  })
168
179
 
180
+ onUnmounted(() => {
181
+ globals.state.navigation_bar.actions = [];
182
+ });
183
+
169
184
  watch(() => marketplace.state.sort, (newSortValue, oldSortValue) => {
170
185
  let query = { ...route.query}
171
186
 
@@ -0,0 +1,102 @@
1
+ <template>
2
+ <VueDraggableNext
3
+ v-bind="dragOptions"
4
+ class="dragArea list-group w-full"
5
+ :list="items"
6
+ @change="handleChange"
7
+ >
8
+ <div v-for="category in items" :key="category._id" class="pd-medium bg-light radius-medium mn-b-thin">
9
+ <CardCategory
10
+ :category="category"
11
+ @delete="deleteCategory"
12
+ />
13
+ <div
14
+ >
15
+ <!-- Subcategories: -->
16
+ <CategoryList
17
+ :items="category.children"
18
+ :state="items"
19
+ @update="emitChange"
20
+ />
21
+ </div>
22
+ </div>
23
+ </VueDraggableNext>
24
+ </template>
25
+
26
+ <script setup>
27
+ import { VueDraggableNext } from 'vue-draggable-next';
28
+ import CardCategory from '@pf/src/modules/products/components/blocks/CardCategory.vue';
29
+ import CategoryList from '@pf/src/modules/products/components/sections/CategoriesTree.vue';
30
+ import * as categories from '@pf/src/modules/products/store/categories';
31
+
32
+ const props = defineProps({
33
+ items: Array,
34
+ state: Array
35
+ });
36
+
37
+ const emits = defineEmits(['update']);
38
+
39
+ const dragOptions = {
40
+ animation: 200,
41
+ group: 'category',
42
+ ghostClass: 'ghost'
43
+ };
44
+
45
+ async function deleteCategory(category) {
46
+ if (confirm(`Are you sure you want to delete the category "${category.name}"?`)) {
47
+ await categories.actions.deleteCategory(category.url);
48
+ }
49
+ }
50
+
51
+ function findCategoryAndUpdateParent(items, targetId, parentId = null) {
52
+ for (const item of items) {
53
+ if (item._id === targetId) {
54
+ item.parent = parentId;
55
+ return item;
56
+ }
57
+
58
+ if (item.children) {
59
+ const found = findCategoryAndUpdateParent(item.children, targetId, item._id);
60
+ if (found) {
61
+ return found;
62
+ }
63
+ }
64
+ }
65
+ return null;
66
+ }
67
+
68
+ function updateOrders(items, startOrder = 0) {
69
+ let currentOrder = startOrder;
70
+
71
+ items.forEach(item => {
72
+ item.order = currentOrder++;
73
+
74
+ if (item.children?.length) {
75
+ currentOrder = updateOrders(item.children, currentOrder);
76
+ }
77
+ });
78
+
79
+ return currentOrder;
80
+ }
81
+
82
+ function handleChange(event) {
83
+ if (!event.added && !event.moved) return;
84
+
85
+ const targetId = event.added ?
86
+ event.added.element._id :
87
+ props.items[event.moved.newIndex]._id;
88
+
89
+ const updatedCategory = findCategoryAndUpdateParent(props.state, targetId);
90
+ if (!updatedCategory) return;
91
+
92
+ // Обновляем order для всего дерева категорий
93
+ updateOrders(props.state);
94
+
95
+ // Отправляем обновленную категорию
96
+ emits('update', updatedCategory);
97
+ }
98
+
99
+ function emitChange(event) {
100
+ emits('update', event);
101
+ }
102
+ </script>
@@ -1,48 +1,62 @@
1
1
  <template>
2
+ <Select
3
+ v-model:select="product.status"
4
+ label="Status"
5
+ :options="[
6
+ 'unpublished',
7
+ 'published',
8
+ 'archivied'
9
+ ]"
10
+
11
+ placeholder="Display product"
12
+ class="pos-relative w-100 mn-b-small bg-white radius-small pd-medium"
13
+ />
14
+ <Select
15
+ v-model:select="product.listing"
16
+ label="Type"
17
+ :options="[
18
+ 'sale',
19
+ 'rent',
20
+ ]"
21
+ placeholder="Type of listing"
22
+ class="pos-relative w-100 mn-b-small bg-white radius-small pd-medium"
23
+ />
24
+
25
+
26
+ <Field
27
+ v-model:field="product.name"
28
+ label="Name"
29
+ placeholder="Enter product name"
30
+ class="w-100 mn-b-small bg-white radius-small pd-medium"
31
+ />
32
+ <Field
33
+ v-model:field="product.price"
34
+ label="Price"
35
+ placeholder="Enter product price"
36
+ class="w-100 mn-b-small bg-white radius-small pd-medium"
37
+ type="number"
38
+ >
2
39
  <Select
3
- v-model:select="product.status"
4
- label="Status"
40
+ v-model:select="product.price_currency"
41
+ placeholder="$"
5
42
  :options="[
6
- 'unpublished',
7
- 'published',
8
- 'archivied'
43
+ '$',
44
+ '£',
45
+ '',
46
+ '฿',
9
47
  ]"
10
-
11
- placeholder="Display product"
12
- class="pos-relative w-100 mn-b-small bg-white radius-small pd-medium"
48
+ class="pos-relative bg-light pd-thin radius-thin"
13
49
  />
50
+ </Field>
14
51
 
15
- <Field
16
- v-model:field="product.name"
17
- label="Name"
18
- placeholder="Enter product name"
19
- class="w-100 mn-b-small bg-white radius-small pd-medium"
20
- />
21
- <Field
22
- v-model:field="product.price"
23
- label="Price"
24
- placeholder="Enter product price"
25
- class="w-100 mn-b-small bg-white radius-small pd-medium"
26
- type="number"
27
- >
28
- <Select
29
- v-model:select="product.price.currency"
30
- placeholder="฿"
31
- :options="[
32
- '฿'
33
- ]"
34
- class="pos-relative bg-light pd-thin radius-thin"
35
- />
36
- </Field>
37
-
38
-
39
- <Field
40
- v-model:field="product.description"
41
- label="Description"
42
- placeholder="Enter product description"
43
- class="w-100 bg-white radius-small pd-medium"
44
- type="textarea"
45
- />
52
+
53
+ <Field
54
+ v-model:field="product.description"
55
+ label="Description"
56
+ placeholder="Enter product description"
57
+ class="w-100 bg-white radius-small pd-medium"
58
+ type="textarea"
59
+ />
46
60
  </template>
47
61
 
48
62
  <script setup>
@@ -51,7 +65,6 @@ import Button from '@pf/src/components/Button/Button.vue'
51
65
  import Field from "@pf/src/components/Field/Field.vue";
52
66
  import Select from "@pf/src/components/Select/Select.vue";
53
67
 
54
-
55
68
  const props = defineProps({
56
69
  product: Object,
57
70
  });
@@ -1,120 +1,198 @@
1
1
  const controllerFactory = (db) => {
2
- const Category = db.category;
2
+ const Category = db.category;
3
3
 
4
- const getCategories = async (req, res) => {
5
- console.log(Category)
4
+ return {
5
+ async read(req, res) {
6
6
  try {
7
-
8
- let query = {};
9
- let options = {};
7
+ const {
8
+ parent,
9
+ url,
10
+ search,
11
+ sort = 'order',
12
+ order = 1,
13
+ page = 1,
14
+ limit = 10,
15
+ excludeChildren = false,
16
+ rootOnly = false
17
+ } = req.query;
10
18
 
11
- // Проверка наличия req.query.organization
12
- if (req.query.status) {
13
- // Создание ObjectId из строки
14
- query.status = req.query.status;
15
- }
19
+ const matchStage = {
20
+ ...(req.query.status && { status: req.query.status }),
21
+ ...(req.query.url && { url: req.query.url }),
22
+ ...(search && { name: { $regex: search, $options: 'i' } }),
23
+ ...(parent ? { parent: new db.mongoose.Types.ObjectId(parent) } : {}),
24
+ ...(rootOnly ? { parent: null } : {})
25
+ };
16
26
 
17
- const categories = await Category.find(query, null, options).sort({'order': 'asc'}).exec();
27
+ const pipeline = [
28
+ { $match: matchStage },
29
+ {
30
+ $graphLookup: {
31
+ from: 'categories',
32
+ startWith: '$_id',
33
+ connectFromField: '_id',
34
+ connectToField: 'parent',
35
+ as: 'allDescendants',
36
+ maxDepth: 10
37
+ }
38
+ },
39
+ { $sort: { [sort]: order === 'asc' ? 1 : -1 } },
40
+ { $skip: (page - 1) * limit },
41
+ { $limit: Number(limit) },
42
+ ];
43
+
44
+ const flatResults = await Category.aggregate(pipeline);
18
45
 
19
- if (!categories) {
20
- return res.status(404).send({ message: "Categories not found." });
21
- }
22
- res.status(200).send(categories);
23
- } catch (err) {
24
- console.log(err)
25
- res.status(500).send({ message: err });
26
- }
27
- };
46
+ function buildTree(items) {
47
+ const itemMap = {};
48
+ const roots = [];
49
+
50
+ // First pass: Create map of items by ID
51
+ items.forEach(item => {
52
+ itemMap[item._id.toString()] = {
53
+ ...item,
54
+ children: []
55
+ };
56
+ });
28
57
 
29
- const updateCategories = async (req, res) => {
30
- console.log(req.body);
31
- try {
32
- const bulkOps = req.body.map((categoryUpdated) => ({
33
- updateOne: {
34
- filter: { url: categoryUpdated.url },
35
- update: { $set: categoryUpdated },
36
- upsert: false
37
- }
38
- }));
39
-
40
- // Выполнение пакетного обновления
41
- const result = await Category.bulkWrite(bulkOps, { ordered: false });
42
- console.log('Success', result);
43
- res.status(200).send({ message: "Categories updated successfully." });
58
+ // Second pass: Build tree structure
59
+ items.forEach(item => {
60
+ const itemId = item._id.toString();
61
+ const parentId = item.parent?._id?.toString();
62
+ if (parentId && itemMap[parentId]) {
63
+ itemMap[parentId].children.push(itemMap[itemId]);
64
+ } else {
65
+ roots.push(itemMap[itemId]);
66
+ }
67
+ });
68
+
69
+ // Sort children arrays by order property
70
+ const sortByOrder = (a, b) => {
71
+ const orderA = a.order ?? Number.MAX_SAFE_INTEGER;
72
+ const orderB = b.order ?? Number.MAX_SAFE_INTEGER;
73
+ return orderA - orderB;
74
+ };
75
+
76
+ // Recursive function to sort children at all levels
77
+ const sortChildren = (node) => {
78
+ if (node.children && node.children.length > 0) {
79
+ node.children.sort(sortByOrder);
80
+ node.children.forEach(sortChildren);
81
+ }
82
+ };
83
+
84
+ // Sort roots and all children
85
+ roots.sort(sortByOrder);
86
+ roots.forEach(sortChildren);
87
+
88
+ return roots;
89
+ }
90
+
91
+ const treeResults = flatResults.map(doc => {
92
+ const descendants = doc.allDescendants || [];
93
+ const allItems = [doc, ...descendants];
94
+ const tree = buildTree(allItems);
95
+
96
+ // Find and return only the root node (original document)
97
+ return tree.find(node => node._id.toString() === doc._id.toString());
98
+ });
99
+
100
+ // Sort root categories
101
+ treeResults.sort((a, b) => {
102
+ const orderA = a.order ?? Number.MAX_SAFE_INTEGER;
103
+ const orderB = b.order ?? Number.MAX_SAFE_INTEGER;
104
+ return orderA - orderB;
105
+ });
106
+
107
+ res.json(treeResults);
44
108
  } catch (err) {
45
- console.error('Error processing bulk update', err);
46
- res.status(500).send({ message: err.message });
109
+ res.status(500).json({ message: err.message });
47
110
  }
48
- };
111
+ },
49
112
 
113
+ async create(req, res) {
114
+ try {
115
+ const highestOrder = await Category.findOne().sort('-order');
116
+ const order = highestOrder ? highestOrder.order + 1 : 1;
117
+ const category = new Category({ ...req.body, order });
50
118
 
51
- const getCategory = async (req, res) => {
52
- try {
53
- const category = await Category.findOne({ url: req.params.url }).exec();
54
- if (!category) {
55
- return res.status(404).send({ message: "Category not found." });
56
- }
57
- res.status(200).send(category);
58
- } catch (err) {
59
- res.status(500).send({ message: err });
119
+ if (req.body.parent) {
120
+ const parent = await Category.findByIdAndUpdate(
121
+ req.body.parent,
122
+ { $push: { children: category._id } },
123
+ { new: true }
124
+ );
125
+ if (!parent) throw new Error('Parent category not found');
126
+ category.parent = parent._id;
60
127
  }
61
- };
62
128
 
63
- const addCategory = async (req, res) => {
64
- try {
129
+ if (req.body.children && req.body.children.length > 0) {
130
+ await Category.updateMany(
131
+ { _id: { $in: req.body.children } },
132
+ { $set: { parent: category._id } }
133
+ );
134
+ }
65
135
 
66
- const highestOrderDoc = await Category.findOne().sort('-order');
67
- req.body.order = highestOrderDoc ? highestOrderDoc.order + 1 : 1;
136
+ await category.save();
137
+ res.status(201).json(category);
138
+ } catch (err) {
139
+ res.status(err.message === 'Parent category not found' ? 404 : 500).json({ message: err.message });
140
+ }
141
+ },
68
142
 
69
- const category = await Category.create(req.body);
143
+ async update(req, res) {
70
144
 
71
- if (!category) {
72
- return res.status(404).send({ message: "Category is not created." });
145
+ try {
146
+ const { categories } = req.body;
147
+
148
+ const bulkOps = categories.map(category => ({
149
+ updateOne: {
150
+ filter: { _id: category._id },
151
+ update: {
152
+ $set: {
153
+ order: category.order,
154
+ parent: category.parent ? new db.mongoose.Types.ObjectId(category.parent) : null
155
+ }
73
156
  }
74
- res.status(200).send(category);
75
- } catch (err) {
76
- console.log(req.body);
77
- console.log(req.category);
78
- res.status(500).send({ message: err });
79
- }
80
- };
157
+ }
158
+ }));
81
159
 
82
- const updateCategory = async (req, res) => {
83
- try {
84
- const category = await Category.findOneAndUpdate(
85
- { url: req.params.url },
86
- { $set: req.body },
87
- { new: true }
88
- ).exec();
89
- if (!category) {
90
- return res.status(404).send({ message: "Something wrong when updating category." });
91
- }
92
- res.status(200).send(category);
93
- } catch (err) {
94
- res.status(500).send({ message: err });
95
- }
96
- };
160
+ await Category.bulkWrite(bulkOps);
161
+ const updatedCategories = await Category.find().sort({ order: 'asc' }).lean();
162
+ res.status(200).json(updatedCategories);
97
163
 
98
- const deleteCategory = async (req, res) => {
99
- try {
100
- const category = await Category.findOneAndDelete({ url: req.params.url }).exec();
101
- if (!category) {
102
- return res.status(404).send({ message: "Category is not deleted." });
164
+ } catch (err) {
165
+ console.error('Category update error:', err);
166
+ res.status(500).json({ message: 'Failed to update categories' });
167
+ }
168
+ },
169
+
170
+ async delete(req, res) {
171
+ try {
172
+ const category = await Category.findOne({ url: req.body.url });
173
+ if (!category) throw new Error('Category not found');
174
+
175
+ const deleteSubcategories = async (categoryId) => {
176
+ const cat = await Category.findById(categoryId);
177
+ if (cat) {
178
+ for (const childId of cat.children) {
179
+ await deleteSubcategories(childId);
103
180
  }
104
- res.status(200).send(category);
105
- } catch (err) {
106
- res.status(500).send({ message: err });
181
+ await Category.findByIdAndDelete(categoryId);
182
+ }
183
+ };
184
+
185
+ if (category.parent) {
186
+ await Category.findByIdAndUpdate(category.parent, { $pull: { children: category._id } });
107
187
  }
108
- };
109
-
110
- return {
111
- getCategories,
112
- updateCategories,
113
- getCategory,
114
- addCategory,
115
- updateCategory,
116
- deleteCategory
117
- };
188
+
189
+ await deleteSubcategories(category._id);
190
+ res.status(200).json({ message: 'Category deleted successfully' });
191
+ } catch (err) {
192
+ res.status(err.message === 'Category not found' ? 404 : 500).json({ message: err.message });
193
+ }
194
+ }
195
+ };
118
196
  };
119
197
 
120
- module.exports = controllerFactory;
198
+ module.exports = controllerFactory;
@@ -35,8 +35,8 @@ const controllerFactory = (db) => {
35
35
  try {
36
36
  const query = {};
37
37
 
38
- if (req.query.organization) {
39
- query.organization = new ObjectId(req.query.organization);
38
+ if (req.query.owner) {
39
+ query['owner.target'] = new ObjectId(req.query.owner);
40
40
  }
41
41
 
42
42
  if (req.query._id) {
@@ -263,8 +263,10 @@ const controllerFactory = (db) => {
263
263
  {
264
264
  name: req.body.name,
265
265
  status: req.body.status,
266
+ listing: req.body.listing,
266
267
  description: req.body.description,
267
268
  price: req.body.price,
269
+ price_currency: req.body.price_currency,
268
270
  sale: req.body.sale,
269
271
  category: req.body.category,
270
272
  images: req.body.images,