@ozdao/martyrs 0.2.489 → 0.2.491

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 (366) hide show
  1. package/dist/_virtual/index.cjs +4 -4
  2. package/dist/_virtual/index.js +4 -4
  3. package/dist/_virtual/index2.cjs +4 -4
  4. package/dist/_virtual/index2.js +4 -4
  5. package/dist/auth.server.cjs +2 -51
  6. package/dist/auth.server.js +1 -50
  7. package/dist/builder.cjs +90 -4
  8. package/dist/builder.js +90 -4
  9. package/dist/main-BhCqlPMQ.cjs +11 -0
  10. package/dist/{main-IVRL6IjM.js → main-YBlKbx0g.js} +1308 -1285
  11. package/dist/martyrs/src/components/Block/Block.vue.cjs +1 -1
  12. package/dist/martyrs/src/components/Block/Block.vue.js +1 -1
  13. package/dist/martyrs/src/components/Button/Button.vue2.cjs +48 -21
  14. package/dist/martyrs/src/components/Button/Button.vue2.cjs.map +1 -1
  15. package/dist/martyrs/src/components/Button/Button.vue2.js +49 -22
  16. package/dist/martyrs/src/components/Button/Button.vue2.js.map +1 -1
  17. package/dist/martyrs/src/components/Chips/{Chips.vue2.cjs → Chips.vue.cjs} +2 -2
  18. package/dist/martyrs/src/components/Chips/Chips.vue.cjs.map +1 -0
  19. package/dist/martyrs/src/components/Chips/{Chips.vue2.js → Chips.vue.js} +2 -2
  20. package/dist/martyrs/src/components/Chips/Chips.vue.js.map +1 -0
  21. package/dist/martyrs/src/components/Dropdown/{Dropdown.vue.cjs → Dropdown.vue2.cjs} +2 -2
  22. package/dist/martyrs/src/components/Dropdown/Dropdown.vue2.cjs.map +1 -0
  23. package/dist/martyrs/src/components/Dropdown/{Dropdown.vue.js → Dropdown.vue2.js} +2 -2
  24. package/dist/martyrs/src/components/Dropdown/{Dropdown.vue.cjs.map → Dropdown.vue2.js.map} +1 -1
  25. package/dist/martyrs/src/components/Feed/Carousel.vue.cjs +1 -1
  26. package/dist/martyrs/src/components/Feed/Carousel.vue.js +1 -1
  27. package/dist/martyrs/src/components/Feed/Feed.vue.cjs +2 -2
  28. package/dist/martyrs/src/components/Feed/Feed.vue.js +2 -2
  29. package/dist/martyrs/src/components/FieldTags/FieldTags.vue.cjs +1 -1
  30. package/dist/martyrs/src/components/FieldTags/FieldTags.vue.js +1 -1
  31. package/dist/martyrs/src/components/Loader/{Loader.vue2.cjs → Loader.vue.cjs} +3 -3
  32. package/dist/martyrs/src/components/Loader/Loader.vue.cjs.map +1 -0
  33. package/dist/martyrs/src/components/Loader/{Loader.vue2.js → Loader.vue.js} +3 -3
  34. package/dist/martyrs/src/components/Loader/Loader.vue.js.map +1 -0
  35. package/dist/martyrs/src/components/LocationMarker/LocationMarker.vue2.cjs +1 -1
  36. package/dist/martyrs/src/components/LocationMarker/LocationMarker.vue2.js +1 -1
  37. package/dist/martyrs/src/components/Tooltip/{Tooltip.vue2.cjs → Tooltip.vue.cjs} +2 -2
  38. package/dist/martyrs/src/components/Tooltip/{Tooltip.vue2.js.map → Tooltip.vue.cjs.map} +1 -1
  39. package/dist/martyrs/src/components/Tooltip/{Tooltip.vue2.js → Tooltip.vue.js} +2 -2
  40. package/dist/martyrs/src/components/Tooltip/Tooltip.vue.js.map +1 -0
  41. package/dist/martyrs/src/components/UploadImageMultiple/UploadImageMultiple.vue.cjs +1 -1
  42. package/dist/martyrs/src/components/UploadImageMultiple/UploadImageMultiple.vue.js +1 -1
  43. package/dist/martyrs/src/modules/auth/views/components/pages/Profile.vue.cjs +2 -2
  44. package/dist/martyrs/src/modules/auth/views/components/pages/Profile.vue.js +2 -2
  45. package/dist/martyrs/src/modules/community/components/blocks/CardBlogpost.vue.cjs +1 -1
  46. package/dist/martyrs/src/modules/community/components/blocks/CardBlogpost.vue.js +1 -1
  47. package/dist/martyrs/src/modules/community/components/pages/BlogPost.vue.cjs +2 -2
  48. package/dist/martyrs/src/modules/community/components/pages/BlogPost.vue.js +2 -2
  49. package/dist/martyrs/src/modules/community/components/pages/CreateBlogPost.vue.cjs +1 -1
  50. package/dist/martyrs/src/modules/community/components/pages/CreateBlogPost.vue.js +1 -1
  51. package/dist/martyrs/src/modules/events/components/blocks/CardEvent.vue.cjs +1 -1
  52. package/dist/martyrs/src/modules/events/components/blocks/CardEvent.vue.js +1 -1
  53. package/dist/martyrs/src/modules/events/components/pages/EditEvent.vue.cjs +1 -1
  54. package/dist/martyrs/src/modules/events/components/pages/EditEvent.vue.js +1 -1
  55. package/dist/martyrs/src/modules/events/components/pages/Event.vue.cjs +3 -3
  56. package/dist/martyrs/src/modules/events/components/pages/Event.vue.js +3 -3
  57. package/dist/martyrs/src/modules/events/components/sections/Feed.vue.cjs +1 -1
  58. package/dist/martyrs/src/modules/events/components/sections/Feed.vue.js +1 -1
  59. package/dist/martyrs/src/modules/events/components/sections/List.vue.cjs +1 -1
  60. package/dist/martyrs/src/modules/events/components/sections/List.vue.js +1 -1
  61. package/dist/martyrs/src/modules/gallery/components/sections/BackofficeGallery.vue.cjs +1 -1
  62. package/dist/martyrs/src/modules/gallery/components/sections/BackofficeGallery.vue.js +1 -1
  63. package/dist/martyrs/src/modules/globals/globals.client.cjs +1 -2
  64. package/dist/martyrs/src/modules/globals/globals.client.cjs.map +1 -1
  65. package/dist/martyrs/src/modules/globals/globals.client.js +1 -2
  66. package/dist/martyrs/src/modules/globals/globals.client.js.map +1 -1
  67. package/dist/martyrs/src/modules/globals/views/classes/globals.i18n.cjs +1 -1
  68. package/dist/martyrs/src/modules/globals/views/classes/globals.i18n.js +1 -1
  69. package/dist/martyrs/src/modules/globals/views/components/blocks/CardHeader.vue.cjs +3 -3
  70. package/dist/martyrs/src/modules/globals/views/components/blocks/CardHeader.vue.js +3 -3
  71. package/dist/martyrs/src/modules/globals/views/components/blocks/PopupDateSelector.vue.cjs +1 -1
  72. package/dist/martyrs/src/modules/globals/views/components/blocks/PopupDateSelector.vue.js +1 -1
  73. package/dist/martyrs/src/modules/globals/views/components/layouts/Client.vue.cjs +10 -1
  74. package/dist/martyrs/src/modules/globals/views/components/layouts/Client.vue.cjs.map +1 -1
  75. package/dist/martyrs/src/modules/globals/views/components/layouts/Client.vue.js +10 -1
  76. package/dist/martyrs/src/modules/globals/views/components/layouts/Client.vue.js.map +1 -1
  77. package/dist/martyrs/src/modules/globals/views/components/partials/Navigation.vue.cjs +1 -1
  78. package/dist/martyrs/src/modules/globals/views/components/partials/Navigation.vue.js +1 -1
  79. package/dist/martyrs/src/modules/marketplace/views/components/sections/SectionMenu.vue.cjs +1 -1
  80. package/dist/martyrs/src/modules/marketplace/views/components/sections/SectionMenu.vue.js +1 -1
  81. package/dist/martyrs/src/modules/music/components/forms/ArtistForm.vue.cjs +1 -1
  82. package/dist/martyrs/src/modules/music/components/forms/ArtistForm.vue.js +1 -1
  83. package/dist/martyrs/src/modules/music/components/layouts/MusicLayout.vue.cjs +2 -2
  84. package/dist/martyrs/src/modules/music/components/layouts/MusicLayout.vue.js +2 -2
  85. package/dist/martyrs/src/modules/music/components/pages/Album.vue.cjs +2 -2
  86. package/dist/martyrs/src/modules/music/components/pages/Album.vue.js +2 -2
  87. package/dist/martyrs/src/modules/music/components/pages/Artist.vue.cjs +1 -1
  88. package/dist/martyrs/src/modules/music/components/pages/Artist.vue.js +1 -1
  89. package/dist/martyrs/src/modules/music/components/pages/Playlist.vue.cjs +2 -2
  90. package/dist/martyrs/src/modules/music/components/pages/Playlist.vue.js +2 -2
  91. package/dist/martyrs/src/modules/music/components/pages/SearchResults.vue.cjs +1 -1
  92. package/dist/martyrs/src/modules/music/components/pages/SearchResults.vue.js +1 -1
  93. package/dist/martyrs/src/modules/music/components/pages/Track.vue.cjs +2 -2
  94. package/dist/martyrs/src/modules/music/components/pages/Track.vue.js +2 -2
  95. package/dist/martyrs/src/modules/music/components/pages/TrackCreate.vue.cjs +1 -1
  96. package/dist/martyrs/src/modules/music/components/pages/TrackCreate.vue.js +1 -1
  97. package/dist/martyrs/src/modules/notifications/components/layouts/NotificationsLayout.vue.cjs +22 -8
  98. package/dist/martyrs/src/modules/notifications/components/layouts/NotificationsLayout.vue.cjs.map +1 -1
  99. package/dist/martyrs/src/modules/notifications/components/layouts/NotificationsLayout.vue.js +23 -9
  100. package/dist/martyrs/src/modules/notifications/components/layouts/NotificationsLayout.vue.js.map +1 -1
  101. package/dist/martyrs/src/modules/notifications/components/pages/Notifications.vue.cjs +13 -15
  102. package/dist/martyrs/src/modules/notifications/components/pages/Notifications.vue.cjs.map +1 -1
  103. package/dist/martyrs/src/modules/notifications/components/pages/Notifications.vue.js +14 -16
  104. package/dist/martyrs/src/modules/notifications/components/pages/Notifications.vue.js.map +1 -1
  105. package/dist/martyrs/src/modules/notifications/components/sections/NotificationPreferences.vue.cjs +2 -2
  106. package/dist/martyrs/src/modules/notifications/components/sections/NotificationPreferences.vue.cjs.map +1 -1
  107. package/dist/martyrs/src/modules/notifications/components/sections/NotificationPreferences.vue.js +2 -2
  108. package/dist/martyrs/src/modules/notifications/components/sections/NotificationPreferences.vue.js.map +1 -1
  109. package/dist/martyrs/src/modules/notifications/components/sections/NotificationsList.vue.cjs +2 -2
  110. package/dist/martyrs/src/modules/notifications/components/sections/NotificationsList.vue.cjs.map +1 -1
  111. package/dist/martyrs/src/modules/notifications/components/sections/NotificationsList.vue.js +2 -2
  112. package/dist/martyrs/src/modules/notifications/components/sections/NotificationsList.vue.js.map +1 -1
  113. package/dist/martyrs/src/modules/notifications/notifications.client.cjs +1 -1
  114. package/dist/martyrs/src/modules/notifications/notifications.client.cjs.map +1 -1
  115. package/dist/martyrs/src/modules/notifications/notifications.client.js +7 -7
  116. package/dist/martyrs/src/modules/notifications/notifications.client.js.map +1 -1
  117. package/dist/martyrs/src/modules/notifications/router/notifications.router.js +4 -4
  118. package/dist/martyrs/src/modules/notifications/router/notifications.router.js.map +1 -1
  119. package/dist/martyrs/src/modules/notifications/store/notifications.store.cjs +7 -10
  120. package/dist/martyrs/src/modules/notifications/store/notifications.store.cjs.map +1 -1
  121. package/dist/martyrs/src/modules/notifications/store/notifications.store.js +7 -10
  122. package/dist/martyrs/src/modules/notifications/store/notifications.store.js.map +1 -1
  123. package/dist/martyrs/src/modules/orders/components/blocks/CardOrderUser.vue.cjs +1 -1
  124. package/dist/martyrs/src/modules/orders/components/blocks/CardOrderUser.vue.js +1 -1
  125. package/dist/martyrs/src/modules/orders/components/pages/OrderBackoffice.vue.cjs +1 -1
  126. package/dist/martyrs/src/modules/orders/components/pages/OrderBackoffice.vue.js +1 -1
  127. package/dist/martyrs/src/modules/orders/components/partials/ShopCart.vue.cjs +0 -1
  128. package/dist/martyrs/src/modules/orders/components/partials/ShopCart.vue.cjs.map +1 -1
  129. package/dist/martyrs/src/modules/orders/components/partials/ShopCart.vue.js +0 -1
  130. package/dist/martyrs/src/modules/orders/components/partials/ShopCart.vue.js.map +1 -1
  131. package/dist/martyrs/src/modules/orders/components/sections/FormDelivery.vue.cjs +2 -2
  132. package/dist/martyrs/src/modules/orders/components/sections/FormDelivery.vue.js +2 -2
  133. package/dist/martyrs/src/modules/organizations/components/blocks/CardOrganization.vue.cjs +1 -1
  134. package/dist/martyrs/src/modules/organizations/components/blocks/CardOrganization.vue.js +1 -1
  135. package/dist/martyrs/src/modules/organizations/components/pages/DepartmentEdit.vue.cjs +1 -1
  136. package/dist/martyrs/src/modules/organizations/components/pages/DepartmentEdit.vue.js +1 -1
  137. package/dist/martyrs/src/modules/organizations/components/pages/Members.vue.cjs +1 -1
  138. package/dist/martyrs/src/modules/organizations/components/pages/Members.vue.js +1 -1
  139. package/dist/martyrs/src/modules/organizations/components/sections/DetailsTabSection.vue.cjs +2 -2
  140. package/dist/martyrs/src/modules/organizations/components/sections/DetailsTabSection.vue.js +2 -2
  141. package/dist/martyrs/src/modules/organizations/components/sections/Documents.vue.cjs +1 -1
  142. package/dist/martyrs/src/modules/organizations/components/sections/Documents.vue.js +1 -1
  143. package/dist/martyrs/src/modules/organizations/components/sections/Organizations.vue.cjs +1 -1
  144. package/dist/martyrs/src/modules/organizations/components/sections/Organizations.vue.js +1 -1
  145. package/dist/martyrs/src/modules/pages/views/components/blocks/CardPage.vue.cjs +1 -1
  146. package/dist/martyrs/src/modules/pages/views/components/blocks/CardPage.vue.js +1 -1
  147. package/dist/martyrs/src/modules/pages/views/components/pages/PageEdit.vue.cjs +1 -1
  148. package/dist/martyrs/src/modules/pages/views/components/pages/PageEdit.vue.js +1 -1
  149. package/dist/martyrs/src/modules/products/components/blocks/ProductDiscounts.vue.cjs +2 -2
  150. package/dist/martyrs/src/modules/products/components/blocks/ProductDiscounts.vue.js +2 -2
  151. package/dist/martyrs/src/modules/products/components/elements/Image360.vue.cjs +1 -1
  152. package/dist/martyrs/src/modules/products/components/elements/Image360.vue.js +1 -1
  153. package/dist/martyrs/src/modules/products/components/pages/Categories.vue.cjs +1 -1
  154. package/dist/martyrs/src/modules/products/components/pages/Categories.vue.js +1 -1
  155. package/dist/martyrs/src/modules/products/components/pages/CategoryEdit.vue.cjs +2 -2
  156. package/dist/martyrs/src/modules/products/components/pages/CategoryEdit.vue.js +2 -2
  157. package/dist/martyrs/src/modules/products/components/pages/Product.vue.cjs +1 -1
  158. package/dist/martyrs/src/modules/products/components/pages/Product.vue.js +1 -1
  159. package/dist/martyrs/src/modules/products/components/pages/ProductRecommmendation.vue.cjs +1 -1
  160. package/dist/martyrs/src/modules/products/components/pages/ProductRecommmendation.vue.js +1 -1
  161. package/dist/martyrs/src/modules/spots/components/blocks/CardSpot.vue.cjs +1 -1
  162. package/dist/martyrs/src/modules/spots/components/blocks/CardSpot.vue.js +1 -1
  163. package/dist/martyrs/src/modules/spots/components/layouts/Spots.vue.cjs +1 -1
  164. package/dist/martyrs/src/modules/spots/components/layouts/Spots.vue.js +1 -1
  165. package/dist/martyrs/src/modules/wallet/views/components/pages/Wallet.vue.cjs +3 -3
  166. package/dist/martyrs/src/modules/wallet/views/components/pages/Wallet.vue.js +3 -3
  167. package/dist/martyrs.cjs.js +1 -1
  168. package/dist/martyrs.css +1 -1
  169. package/dist/martyrs.es.js +1 -1
  170. package/dist/notifications.server.cjs +142 -44
  171. package/dist/notifications.server.js +142 -44
  172. package/dist/orders.server.cjs +155 -102
  173. package/dist/orders.server.js +155 -102
  174. package/dist/products.server.cjs +4 -0
  175. package/dist/products.server.js +4 -0
  176. package/dist/profile.schema-BGAe5VN5.js +92 -0
  177. package/dist/profile.schema-pidHrksV.cjs +91 -0
  178. package/dist/style.css +65 -247
  179. package/dist/{web-BXhlxo6M.cjs → web-BBmMBRv-.cjs} +1 -1
  180. package/dist/{web-Czi05iGG.js → web-Dqu-aCL5.js} +1 -1
  181. package/package.json +1 -1
  182. package/src/builder/rspack/rspack.config.spa.client.js +46 -1
  183. package/src/builder/rspack/rspack.config.ssr.client.js +43 -0
  184. package/src/builder/templates/page.js +1 -1
  185. package/src/components/Button/Button.vue +230 -196
  186. package/src/components/Loader/Loader.vue +1 -1
  187. package/src/modules/auth/controllers/middlewares/visitor.logger.js +22 -0
  188. package/src/modules/globals/globals.client.js +1 -1
  189. package/src/modules/globals/views/components/layouts/Client.vue +10 -9
  190. package/src/modules/notifications/FIXES.md +4 -0
  191. package/src/modules/notifications/components/layouts/NotificationsLayout.vue +33 -32
  192. package/src/modules/notifications/components/pages/Notifications.vue +10 -51
  193. package/src/modules/notifications/components/sections/NotificationPreferences.vue +1 -11
  194. package/src/modules/notifications/components/sections/NotificationsList.vue +1 -1
  195. package/src/modules/notifications/controllers/notifications.controller.js +50 -4
  196. package/src/modules/notifications/notifications.client.js +1 -1
  197. package/src/modules/notifications/notifications.server.js +18 -7
  198. package/src/modules/notifications/routes/notifications.routes.js +4 -2
  199. package/src/modules/notifications/services/notification.service.js +109 -38
  200. package/src/modules/notifications/services/telegram.service.js +1 -0
  201. package/src/modules/notifications/services/whatsapp.service.js +1 -0
  202. package/src/modules/notifications/store/notifications.store.js +25 -16
  203. package/src/modules/orders/components/partials/ShopCart.vue +0 -1
  204. package/src/modules/orders/controllers/orders.controller.js +195 -85
  205. package/src/modules/products/controllers/products.controller.js +4 -0
  206. package/dist/main-CmuUC0tl.cjs +0 -11
  207. package/dist/martyrs/src/components/Chips/Chips.vue2.cjs.map +0 -1
  208. package/dist/martyrs/src/components/Chips/Chips.vue2.js.map +0 -1
  209. package/dist/martyrs/src/components/Dropdown/Dropdown.vue.js.map +0 -1
  210. package/dist/martyrs/src/components/Loader/Loader.vue2.cjs.map +0 -1
  211. package/dist/martyrs/src/components/Loader/Loader.vue2.js.map +0 -1
  212. package/dist/martyrs/src/components/Tooltip/Tooltip.vue2.cjs.map +0 -1
  213. package/dist/martyrs/src/modules/globals/views/plugins/store-debugger/StoreDebugger.vue.cjs +0 -200
  214. package/dist/martyrs/src/modules/globals/views/plugins/store-debugger/StoreDebugger.vue.cjs.map +0 -1
  215. package/dist/martyrs/src/modules/globals/views/plugins/store-debugger/StoreDebugger.vue.js +0 -200
  216. package/dist/martyrs/src/modules/globals/views/plugins/store-debugger/StoreDebugger.vue.js.map +0 -1
  217. package/dist/martyrs/src/modules/globals/views/plugins/store-debugger/store-debugger.plugin.cjs +0 -21
  218. package/dist/martyrs/src/modules/globals/views/plugins/store-debugger/store-debugger.plugin.cjs.map +0 -1
  219. package/dist/martyrs/src/modules/globals/views/plugins/store-debugger/store-debugger.plugin.js +0 -21
  220. package/dist/martyrs/src/modules/globals/views/plugins/store-debugger/store-debugger.plugin.js.map +0 -1
  221. package/dist/node_modules/date-fns/_lib/addLeadingZeros.cjs +0 -9
  222. package/dist/node_modules/date-fns/_lib/addLeadingZeros.cjs.map +0 -1
  223. package/dist/node_modules/date-fns/_lib/addLeadingZeros.js +0 -9
  224. package/dist/node_modules/date-fns/_lib/addLeadingZeros.js.map +0 -1
  225. package/dist/node_modules/date-fns/_lib/defaultOptions.cjs +0 -8
  226. package/dist/node_modules/date-fns/_lib/defaultOptions.cjs.map +0 -1
  227. package/dist/node_modules/date-fns/_lib/defaultOptions.js +0 -8
  228. package/dist/node_modules/date-fns/_lib/defaultOptions.js.map +0 -1
  229. package/dist/node_modules/date-fns/_lib/format/formatters.cjs +0 -653
  230. package/dist/node_modules/date-fns/_lib/format/formatters.cjs.map +0 -1
  231. package/dist/node_modules/date-fns/_lib/format/formatters.js +0 -653
  232. package/dist/node_modules/date-fns/_lib/format/formatters.js.map +0 -1
  233. package/dist/node_modules/date-fns/_lib/format/lightFormatters.cjs +0 -63
  234. package/dist/node_modules/date-fns/_lib/format/lightFormatters.cjs.map +0 -1
  235. package/dist/node_modules/date-fns/_lib/format/lightFormatters.js +0 -63
  236. package/dist/node_modules/date-fns/_lib/format/lightFormatters.js.map +0 -1
  237. package/dist/node_modules/date-fns/_lib/format/longFormatters.cjs +0 -59
  238. package/dist/node_modules/date-fns/_lib/format/longFormatters.cjs.map +0 -1
  239. package/dist/node_modules/date-fns/_lib/format/longFormatters.js +0 -59
  240. package/dist/node_modules/date-fns/_lib/format/longFormatters.js.map +0 -1
  241. package/dist/node_modules/date-fns/_lib/getTimezoneOffsetInMilliseconds.cjs +0 -21
  242. package/dist/node_modules/date-fns/_lib/getTimezoneOffsetInMilliseconds.cjs.map +0 -1
  243. package/dist/node_modules/date-fns/_lib/getTimezoneOffsetInMilliseconds.js +0 -21
  244. package/dist/node_modules/date-fns/_lib/getTimezoneOffsetInMilliseconds.js.map +0 -1
  245. package/dist/node_modules/date-fns/_lib/normalizeDates.cjs +0 -12
  246. package/dist/node_modules/date-fns/_lib/normalizeDates.cjs.map +0 -1
  247. package/dist/node_modules/date-fns/_lib/normalizeDates.js +0 -12
  248. package/dist/node_modules/date-fns/_lib/normalizeDates.js.map +0 -1
  249. package/dist/node_modules/date-fns/_lib/protectedTokens.cjs +0 -24
  250. package/dist/node_modules/date-fns/_lib/protectedTokens.cjs.map +0 -1
  251. package/dist/node_modules/date-fns/_lib/protectedTokens.js +0 -24
  252. package/dist/node_modules/date-fns/_lib/protectedTokens.js.map +0 -1
  253. package/dist/node_modules/date-fns/constants.cjs +0 -9
  254. package/dist/node_modules/date-fns/constants.cjs.map +0 -1
  255. package/dist/node_modules/date-fns/constants.js +0 -9
  256. package/dist/node_modules/date-fns/constants.js.map +0 -1
  257. package/dist/node_modules/date-fns/constructFrom.cjs +0 -13
  258. package/dist/node_modules/date-fns/constructFrom.cjs.map +0 -1
  259. package/dist/node_modules/date-fns/constructFrom.js +0 -13
  260. package/dist/node_modules/date-fns/constructFrom.js.map +0 -1
  261. package/dist/node_modules/date-fns/differenceInCalendarDays.cjs +0 -21
  262. package/dist/node_modules/date-fns/differenceInCalendarDays.cjs.map +0 -1
  263. package/dist/node_modules/date-fns/differenceInCalendarDays.js +0 -21
  264. package/dist/node_modules/date-fns/differenceInCalendarDays.js.map +0 -1
  265. package/dist/node_modules/date-fns/format.cjs +0 -80
  266. package/dist/node_modules/date-fns/format.cjs.map +0 -1
  267. package/dist/node_modules/date-fns/format.js +0 -80
  268. package/dist/node_modules/date-fns/format.js.map +0 -1
  269. package/dist/node_modules/date-fns/getDayOfYear.cjs +0 -14
  270. package/dist/node_modules/date-fns/getDayOfYear.cjs.map +0 -1
  271. package/dist/node_modules/date-fns/getDayOfYear.js +0 -14
  272. package/dist/node_modules/date-fns/getDayOfYear.js.map +0 -1
  273. package/dist/node_modules/date-fns/getISOWeek.cjs +0 -14
  274. package/dist/node_modules/date-fns/getISOWeek.cjs.map +0 -1
  275. package/dist/node_modules/date-fns/getISOWeek.js +0 -14
  276. package/dist/node_modules/date-fns/getISOWeek.js.map +0 -1
  277. package/dist/node_modules/date-fns/getISOWeekYear.cjs +0 -27
  278. package/dist/node_modules/date-fns/getISOWeekYear.cjs.map +0 -1
  279. package/dist/node_modules/date-fns/getISOWeekYear.js +0 -27
  280. package/dist/node_modules/date-fns/getISOWeekYear.js.map +0 -1
  281. package/dist/node_modules/date-fns/getWeek.cjs +0 -14
  282. package/dist/node_modules/date-fns/getWeek.cjs.map +0 -1
  283. package/dist/node_modules/date-fns/getWeek.js +0 -14
  284. package/dist/node_modules/date-fns/getWeek.js.map +0 -1
  285. package/dist/node_modules/date-fns/getWeekYear.cjs +0 -31
  286. package/dist/node_modules/date-fns/getWeekYear.cjs.map +0 -1
  287. package/dist/node_modules/date-fns/getWeekYear.js +0 -31
  288. package/dist/node_modules/date-fns/getWeekYear.js.map +0 -1
  289. package/dist/node_modules/date-fns/isDate.cjs +0 -8
  290. package/dist/node_modules/date-fns/isDate.cjs.map +0 -1
  291. package/dist/node_modules/date-fns/isDate.js +0 -8
  292. package/dist/node_modules/date-fns/isDate.js.map +0 -1
  293. package/dist/node_modules/date-fns/isValid.cjs +0 -10
  294. package/dist/node_modules/date-fns/isValid.cjs.map +0 -1
  295. package/dist/node_modules/date-fns/isValid.js +0 -10
  296. package/dist/node_modules/date-fns/isValid.js.map +0 -1
  297. package/dist/node_modules/date-fns/locale/_lib/buildFormatLongFn.cjs +0 -11
  298. package/dist/node_modules/date-fns/locale/_lib/buildFormatLongFn.cjs.map +0 -1
  299. package/dist/node_modules/date-fns/locale/_lib/buildFormatLongFn.js +0 -11
  300. package/dist/node_modules/date-fns/locale/_lib/buildFormatLongFn.js.map +0 -1
  301. package/dist/node_modules/date-fns/locale/_lib/buildLocalizeFn.cjs +0 -21
  302. package/dist/node_modules/date-fns/locale/_lib/buildLocalizeFn.cjs.map +0 -1
  303. package/dist/node_modules/date-fns/locale/_lib/buildLocalizeFn.js +0 -21
  304. package/dist/node_modules/date-fns/locale/_lib/buildLocalizeFn.js.map +0 -1
  305. package/dist/node_modules/date-fns/locale/_lib/buildMatchFn.cjs +0 -44
  306. package/dist/node_modules/date-fns/locale/_lib/buildMatchFn.cjs.map +0 -1
  307. package/dist/node_modules/date-fns/locale/_lib/buildMatchFn.js +0 -44
  308. package/dist/node_modules/date-fns/locale/_lib/buildMatchFn.js.map +0 -1
  309. package/dist/node_modules/date-fns/locale/_lib/buildMatchPatternFn.cjs +0 -17
  310. package/dist/node_modules/date-fns/locale/_lib/buildMatchPatternFn.cjs.map +0 -1
  311. package/dist/node_modules/date-fns/locale/_lib/buildMatchPatternFn.js +0 -17
  312. package/dist/node_modules/date-fns/locale/_lib/buildMatchPatternFn.js.map +0 -1
  313. package/dist/node_modules/date-fns/locale/en-US/_lib/formatDistance.cjs +0 -86
  314. package/dist/node_modules/date-fns/locale/en-US/_lib/formatDistance.cjs.map +0 -1
  315. package/dist/node_modules/date-fns/locale/en-US/_lib/formatDistance.js +0 -86
  316. package/dist/node_modules/date-fns/locale/en-US/_lib/formatDistance.js.map +0 -1
  317. package/dist/node_modules/date-fns/locale/en-US/_lib/formatLong.cjs +0 -37
  318. package/dist/node_modules/date-fns/locale/en-US/_lib/formatLong.cjs.map +0 -1
  319. package/dist/node_modules/date-fns/locale/en-US/_lib/formatLong.js +0 -37
  320. package/dist/node_modules/date-fns/locale/en-US/_lib/formatLong.js.map +0 -1
  321. package/dist/node_modules/date-fns/locale/en-US/_lib/formatRelative.cjs +0 -13
  322. package/dist/node_modules/date-fns/locale/en-US/_lib/formatRelative.cjs.map +0 -1
  323. package/dist/node_modules/date-fns/locale/en-US/_lib/formatRelative.js +0 -13
  324. package/dist/node_modules/date-fns/locale/en-US/_lib/formatRelative.js.map +0 -1
  325. package/dist/node_modules/date-fns/locale/en-US/_lib/localize.cjs +0 -165
  326. package/dist/node_modules/date-fns/locale/en-US/_lib/localize.cjs.map +0 -1
  327. package/dist/node_modules/date-fns/locale/en-US/_lib/localize.js +0 -165
  328. package/dist/node_modules/date-fns/locale/en-US/_lib/localize.js.map +0 -1
  329. package/dist/node_modules/date-fns/locale/en-US/_lib/match.cjs +0 -123
  330. package/dist/node_modules/date-fns/locale/en-US/_lib/match.cjs.map +0 -1
  331. package/dist/node_modules/date-fns/locale/en-US/_lib/match.js +0 -123
  332. package/dist/node_modules/date-fns/locale/en-US/_lib/match.js.map +0 -1
  333. package/dist/node_modules/date-fns/locale/en-US.cjs +0 -22
  334. package/dist/node_modules/date-fns/locale/en-US.cjs.map +0 -1
  335. package/dist/node_modules/date-fns/locale/en-US.js +0 -22
  336. package/dist/node_modules/date-fns/locale/en-US.js.map +0 -1
  337. package/dist/node_modules/date-fns/startOfDay.cjs +0 -11
  338. package/dist/node_modules/date-fns/startOfDay.cjs.map +0 -1
  339. package/dist/node_modules/date-fns/startOfDay.js +0 -11
  340. package/dist/node_modules/date-fns/startOfDay.js.map +0 -1
  341. package/dist/node_modules/date-fns/startOfISOWeek.cjs +0 -9
  342. package/dist/node_modules/date-fns/startOfISOWeek.cjs.map +0 -1
  343. package/dist/node_modules/date-fns/startOfISOWeek.js +0 -9
  344. package/dist/node_modules/date-fns/startOfISOWeek.js.map +0 -1
  345. package/dist/node_modules/date-fns/startOfISOWeekYear.cjs +0 -15
  346. package/dist/node_modules/date-fns/startOfISOWeekYear.cjs.map +0 -1
  347. package/dist/node_modules/date-fns/startOfISOWeekYear.js +0 -15
  348. package/dist/node_modules/date-fns/startOfISOWeekYear.js.map +0 -1
  349. package/dist/node_modules/date-fns/startOfWeek.cjs +0 -18
  350. package/dist/node_modules/date-fns/startOfWeek.cjs.map +0 -1
  351. package/dist/node_modules/date-fns/startOfWeek.js +0 -18
  352. package/dist/node_modules/date-fns/startOfWeek.js.map +0 -1
  353. package/dist/node_modules/date-fns/startOfWeekYear.cjs +0 -20
  354. package/dist/node_modules/date-fns/startOfWeekYear.cjs.map +0 -1
  355. package/dist/node_modules/date-fns/startOfWeekYear.js +0 -20
  356. package/dist/node_modules/date-fns/startOfWeekYear.js.map +0 -1
  357. package/dist/node_modules/date-fns/startOfYear.cjs +0 -12
  358. package/dist/node_modules/date-fns/startOfYear.cjs.map +0 -1
  359. package/dist/node_modules/date-fns/startOfYear.js +0 -12
  360. package/dist/node_modules/date-fns/startOfYear.js.map +0 -1
  361. package/dist/node_modules/date-fns/toDate.cjs +0 -9
  362. package/dist/node_modules/date-fns/toDate.cjs.map +0 -1
  363. package/dist/node_modules/date-fns/toDate.js +0 -9
  364. package/dist/node_modules/date-fns/toDate.js.map +0 -1
  365. package/dist/profile.schema-DchVS-Jr.js +0 -21
  366. package/dist/profile.schema-yQuIzngl.cjs +0 -20
@@ -3,9 +3,9 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
3
3
  const globals_logger = require("./globals.logger-CZMgIMlM.cjs");
4
4
  const queryProcessor = require("./queryProcessor-B_X680wC.cjs");
5
5
  const mailing = require("./mailing-q7sR8gCV.cjs");
6
+ const profile_schema = require("./profile.schema-pidHrksV.cjs");
6
7
  const credentials_schema = require("./credentials.schema-DwhGdrwC.cjs");
7
8
  const ownership_schema = require("./ownership.schema-D1p5XSpt.cjs");
8
- const profile_schema = require("./profile.schema-yQuIzngl.cjs");
9
9
  const index = require("./index-BFxqqmgh.cjs");
10
10
  const axios = require("axios");
11
11
  class CRUD {
@@ -93,83 +93,151 @@ class CRUD {
93
93
  }
94
94
  }
95
95
  }
96
- const { sendChatMessageTelegram: sendChatMessageTelegram$1 } = mailing.mailing;
97
- function formatPositions(positions) {
98
- return positions.map((pos) => `🔹 ${pos.name} - Price: $${pos.price}, Quantity: ${pos.quantity}`).join("\n");
99
- }
100
- function formatOrderMessage(order) {
101
- return `
102
- 🆕 New Order Received!
103
- 👤 Customer: ${order.customer?.name} (${order.customer?.phone?.number ? order.customer?.phone?.number : "No phone"})
104
- 💬 Messenger: ${order.customer?.messenger ? order.customer?.messenger?.type + " " + order.customer?.messenger?.value : "None"}
105
- 🏢 Organization: ${order.organization}
106
- 📦 Positions:
107
- ${formatPositions(order.positions)}
108
- 📝 Comment: ${order.comment ? order.comment : "No comment"}
109
- 💳 Payment: ${order.payment?.type}
110
- 🚚 Delivery: ${order.delivery?.type} to ${order.delivery?.address}
111
- 📌 Status: ${order.status}
112
- 🧑 Agent: ${order.referralCode}
113
- `;
114
- }
115
- async function findOrCreateCustomer(Customer, customerInfo, orderOwner, orderCreator) {
116
- let searchCriteria = {};
117
- if (customerInfo.phone) {
118
- searchCriteria.phone = customerInfo.phone;
119
- }
120
- if (customerInfo.email) {
121
- searchCriteria.email = customerInfo.email;
122
- }
123
- let customer = null;
124
- if (Object.keys(searchCriteria).length > 0) {
125
- customer = await Customer.findOne({ $or: [searchCriteria] });
126
- }
127
- if (!customer) {
128
- let creatorType = customerInfo.creator?.type || orderCreator.type;
129
- let creatorTarget = customerInfo.creator?.target || orderCreator.target;
130
- if (!creatorTarget) {
131
- creatorType = orderOwner.type;
132
- creatorTarget = orderOwner.target;
96
+ const controllerFactory = (db) => {
97
+ const Order = db.order;
98
+ const Customer = db.customer;
99
+ const Department = db.department;
100
+ const { findOrCreateVisitor } = profile_schema.modelsFactory(db);
101
+ const getUsersWithOrdersConfirmAccess = async (organizationId) => {
102
+ console.log("=== Getting users with orders.confirm access ===");
103
+ console.log("Organization ID:", organizationId);
104
+ const pipeline = [
105
+ { $match: {
106
+ organization: new db.mongoose.Types.ObjectId(organizationId),
107
+ "accesses.orders.confirm": true
108
+ } },
109
+ { $unwind: "$members" },
110
+ { $group: {
111
+ _id: "$members.user"
112
+ } },
113
+ { $project: { userId: "$_id" } }
114
+ ];
115
+ console.log("Pipeline:", JSON.stringify(pipeline, null, 2));
116
+ const result = await Department.aggregate(pipeline);
117
+ const userIds = result.map((item) => item.userId);
118
+ console.log("Found departments with access:", result.length);
119
+ console.log("User IDs with access:", userIds);
120
+ console.log("=== End getting users ===");
121
+ return userIds;
122
+ };
123
+ const sendOrderNotifications = async (order, type, userIds, extraData = {}) => {
124
+ console.log("=== Sending order notifications ===");
125
+ console.log("Order ID:", order._id);
126
+ console.log("Type:", type);
127
+ console.log("User IDs:", userIds);
128
+ console.log("Extra data:", extraData);
129
+ if (!userIds || userIds.length === 0) {
130
+ console.log("No users to notify, skipping...");
131
+ return;
133
132
  }
134
- const newCustomerData = {
135
- ...customerInfo,
136
- // Ensure we're not passing any null _id that might override MongoDB's auto-generation
137
- _id: void 0,
138
- // Let MongoDB generate this
139
- owner: orderOwner,
140
- creator: {
141
- type: creatorType,
142
- target: creatorTarget
133
+ const notifications = userIds.map((userId) => ({
134
+ title: getNotificationTitle(type, order, extraData),
135
+ body: getNotificationBody(type, order, extraData),
136
+ type,
137
+ metadata: {
138
+ type,
139
+ orderId: order._id,
140
+ context: "organization",
141
+ ...extraData
143
142
  },
144
- identity: {
145
- type: customerInfo.identity?.type || creatorType,
146
- target: customerInfo.identity?.target || creatorTarget
143
+ userId
144
+ }));
145
+ function getNotificationTitle(type2, order2, extraData2 = {}) {
146
+ switch (type2) {
147
+ case "order_created":
148
+ return "New Order";
149
+ case "order_status":
150
+ return "Order Status Updated";
151
+ default:
152
+ return "Order Notification";
147
153
  }
148
- };
154
+ }
155
+ function getNotificationBody(type2, order2, extraData2 = {}) {
156
+ switch (type2) {
157
+ case "order_created":
158
+ return `New order #${order2._id} created`;
159
+ case "order_status":
160
+ return `Order #${order2._id} changed from ${extraData2.oldStatus} to ${extraData2.newStatus}`;
161
+ default:
162
+ return `Order #${order2._id} updated`;
163
+ }
164
+ }
165
+ console.log("Prepared notifications:", JSON.stringify(notifications, null, 2));
166
+ console.log("API URL:", `${process.env.API_URL || ""}/api/notifications/batch`);
149
167
  try {
150
- customer = await Customer.create(newCustomerData);
151
- if (!customer || !customer._id) {
152
- console.error("Customer creation failed to generate _id:", customer);
153
- throw new Error("Customer creation did not generate a valid _id");
168
+ const response = await fetch(`${process.env.API_URL || ""}/api/notifications/batch`, {
169
+ method: "POST",
170
+ headers: {
171
+ "Content-Type": "application/json",
172
+ "X-Service-Key": process.env.SERVICE_KEY
173
+ },
174
+ body: JSON.stringify({ notifications })
175
+ });
176
+ console.log("Notification response status:", response.status);
177
+ if (!response.ok) {
178
+ const errorData = await response.text();
179
+ console.error("Notification API error:", errorData);
180
+ throw new Error(`Notification API failed: ${response.status} - ${errorData}`);
181
+ }
182
+ const result = await response.json();
183
+ console.log("Notification API success:", result);
184
+ console.log("=== End sending notifications ===");
185
+ return result;
186
+ } catch (error) {
187
+ console.error("=== Notification sending failed ===");
188
+ console.error("Error:", error.message);
189
+ console.error("Stack:", error.stack);
190
+ throw error;
191
+ }
192
+ };
193
+ const findOrCreateCustomer = async (customerInfo, orderOwner, orderCreator, req) => {
194
+ let searchCriteria = {};
195
+ if (customerInfo.phone) {
196
+ searchCriteria.phone = customerInfo.phone;
197
+ }
198
+ if (customerInfo.email) {
199
+ searchCriteria.email = customerInfo.email;
200
+ }
201
+ let customer = null;
202
+ if (Object.keys(searchCriteria).length > 0) {
203
+ customer = await Customer.findOne({ $or: [searchCriteria] });
204
+ }
205
+ if (!customer) {
206
+ const visitor = await findOrCreateVisitor(req);
207
+ let creatorType = customerInfo.creator?.type || orderCreator.type;
208
+ let creatorTarget = customerInfo.creator?.target || orderCreator.target;
209
+ if (!creatorTarget) {
210
+ creatorType = orderOwner.type;
211
+ creatorTarget = orderOwner.target;
212
+ }
213
+ const newCustomerData = {
214
+ ...customerInfo,
215
+ // Ensure we're not passing any null _id that might override MongoDB's auto-generation
216
+ _id: void 0,
217
+ // Let MongoDB generate this
218
+ owner: orderOwner,
219
+ creator: {
220
+ type: creatorType,
221
+ target: creatorTarget
222
+ },
223
+ identity: {
224
+ type: "Visitor",
225
+ target: visitor._id
226
+ }
227
+ };
228
+ try {
229
+ customer = await Customer.create(newCustomerData);
230
+ if (!customer || !customer._id) {
231
+ console.error("Customer creation failed to generate _id:", customer);
232
+ throw new Error("Customer creation did not generate a valid _id");
233
+ }
234
+ } catch (err) {
235
+ console.error("Error creating customer:", err);
236
+ throw err;
154
237
  }
155
- } catch (err) {
156
- console.error("Error creating customer:", err);
157
- throw err;
158
238
  }
159
- }
160
- return customer;
161
- }
162
- async function sendOrderMessage(orderData) {
163
- try {
164
- const formattedMessage = formatOrderMessage(orderData);
165
- await sendChatMessageTelegram$1(process.env.TELEGRAM_BOT_USERS.split(","), formattedMessage);
166
- } catch (err) {
167
- console.error(err);
168
- }
169
- }
170
- const controllerFactory = (db) => {
171
- const Order = db.order;
172
- const Customer = db.customer;
239
+ return customer;
240
+ };
173
241
  const create = async (req, res) => {
174
242
  const orderData = req.body;
175
243
  req.userId || req.body.creator?.target;
@@ -184,7 +252,7 @@ const controllerFactory = (db) => {
184
252
  session.startTransaction();
185
253
  try {
186
254
  if (!orderData.customer.target) {
187
- const customer = await findOrCreateCustomer(Customer, orderData.customer, orderData.owner, orderData.creator);
255
+ const customer = await findOrCreateCustomer(orderData.customer, orderData.owner, orderData.creator, req);
188
256
  console.log("customer is", customer);
189
257
  if (!customer || !customer._id) {
190
258
  throw new Error("Failed to create or find a valid customer");
@@ -204,7 +272,12 @@ const controllerFactory = (db) => {
204
272
  const order = await Order.create([orderData], { session });
205
273
  const createdOrder = order[0];
206
274
  await session.commitTransaction();
207
- sendOrderMessage(orderData).catch(console.error);
275
+ try {
276
+ const usersWithAccess = await getUsersWithOrdersConfirmAccess(orderData.owner.target);
277
+ await sendOrderNotifications(createdOrder, "order_created", usersWithAccess);
278
+ } catch (notificationError) {
279
+ console.error("Error sending notification:", notificationError);
280
+ }
208
281
  res.status(201).send(createdOrder);
209
282
  } catch (err) {
210
283
  await session.abortTransaction();
@@ -409,35 +482,15 @@ const controllerFactory = (db) => {
409
482
  if (statusChanged) {
410
483
  console.log("Sending notification for status change...");
411
484
  try {
412
- const notificationData = {
413
- title: `Order Status Updated`,
414
- body: `Order #${order._id} status changed from ${oldStatus} to ${order.status}`,
415
- type: "order_status",
416
- metadata: {
417
- orderId: order._id,
418
- oldStatus,
419
- newStatus: order.status,
420
- positions: order.positions
421
- },
422
- userId: order.creator.target
423
- // Assuming creator.target holds the user ID
424
- };
425
- console.log("Notification data:", JSON.stringify(notificationData));
426
- const notificationResponse = await fetch(`${process.env.API_URL || ""}/api/notifications`, {
427
- method: "POST",
428
- headers: {
429
- "Content-Type": "application/json",
430
- "X-Service-Key": process.env.SERVICE_KEY
431
- },
432
- body: JSON.stringify(notificationData)
485
+ const usersWithAccess = await getUsersWithOrdersConfirmAccess(order.owner.target);
486
+ const filteredUsers = usersWithAccess.filter(
487
+ (userId) => userId.toString() !== order.creator.target.toString()
488
+ );
489
+ await sendOrderNotifications(order, "order_status", filteredUsers, {
490
+ oldStatus,
491
+ newStatus: order.status
433
492
  });
434
- console.log("Notification response status:", notificationResponse.status);
435
- if (!notificationResponse.ok) {
436
- const errorData = await notificationResponse.json();
437
- console.error(`Failed to create notification: ${JSON.stringify(errorData)}`);
438
- } else {
439
- console.log("Notification sent successfully");
440
- }
493
+ console.log("Notification sent successfully");
441
494
  } catch (notificationError) {
442
495
  console.error("Error sending notification:", notificationError);
443
496
  }
@@ -1,9 +1,9 @@
1
1
  import { C as Cache, L as Logger } from "./globals.logger-Bf6rRU7j.js";
2
2
  import { q as queryProcessorGlobals } from "./queryProcessor-CVcLPEnv.js";
3
3
  import { m as mailing } from "./mailing-C11EYWm-.js";
4
+ import { m as modelsFactory, a as applyProfileSchema } from "./profile.schema-BGAe5VN5.js";
4
5
  import { a as applyCredentialsSchema } from "./credentials.schema-C9FB2EyY.js";
5
6
  import { a as applyOwnershipSchema } from "./ownership.schema-BqH4v5vH.js";
6
- import { a as applyProfileSchema } from "./profile.schema-DchVS-Jr.js";
7
7
  import { m as middlewareIndexFactory } from "./index-_Edcmck_.js";
8
8
  import axios from "axios";
9
9
  class CRUD {
@@ -91,83 +91,151 @@ class CRUD {
91
91
  }
92
92
  }
93
93
  }
94
- const { sendChatMessageTelegram: sendChatMessageTelegram$1 } = mailing;
95
- function formatPositions(positions) {
96
- return positions.map((pos) => `🔹 ${pos.name} - Price: $${pos.price}, Quantity: ${pos.quantity}`).join("\n");
97
- }
98
- function formatOrderMessage(order) {
99
- return `
100
- 🆕 New Order Received!
101
- 👤 Customer: ${order.customer?.name} (${order.customer?.phone?.number ? order.customer?.phone?.number : "No phone"})
102
- 💬 Messenger: ${order.customer?.messenger ? order.customer?.messenger?.type + " " + order.customer?.messenger?.value : "None"}
103
- 🏢 Organization: ${order.organization}
104
- 📦 Positions:
105
- ${formatPositions(order.positions)}
106
- 📝 Comment: ${order.comment ? order.comment : "No comment"}
107
- 💳 Payment: ${order.payment?.type}
108
- 🚚 Delivery: ${order.delivery?.type} to ${order.delivery?.address}
109
- 📌 Status: ${order.status}
110
- 🧑 Agent: ${order.referralCode}
111
- `;
112
- }
113
- async function findOrCreateCustomer(Customer, customerInfo, orderOwner, orderCreator) {
114
- let searchCriteria = {};
115
- if (customerInfo.phone) {
116
- searchCriteria.phone = customerInfo.phone;
117
- }
118
- if (customerInfo.email) {
119
- searchCriteria.email = customerInfo.email;
120
- }
121
- let customer = null;
122
- if (Object.keys(searchCriteria).length > 0) {
123
- customer = await Customer.findOne({ $or: [searchCriteria] });
124
- }
125
- if (!customer) {
126
- let creatorType = customerInfo.creator?.type || orderCreator.type;
127
- let creatorTarget = customerInfo.creator?.target || orderCreator.target;
128
- if (!creatorTarget) {
129
- creatorType = orderOwner.type;
130
- creatorTarget = orderOwner.target;
94
+ const controllerFactory = (db) => {
95
+ const Order = db.order;
96
+ const Customer = db.customer;
97
+ const Department = db.department;
98
+ const { findOrCreateVisitor } = modelsFactory(db);
99
+ const getUsersWithOrdersConfirmAccess = async (organizationId) => {
100
+ console.log("=== Getting users with orders.confirm access ===");
101
+ console.log("Organization ID:", organizationId);
102
+ const pipeline = [
103
+ { $match: {
104
+ organization: new db.mongoose.Types.ObjectId(organizationId),
105
+ "accesses.orders.confirm": true
106
+ } },
107
+ { $unwind: "$members" },
108
+ { $group: {
109
+ _id: "$members.user"
110
+ } },
111
+ { $project: { userId: "$_id" } }
112
+ ];
113
+ console.log("Pipeline:", JSON.stringify(pipeline, null, 2));
114
+ const result = await Department.aggregate(pipeline);
115
+ const userIds = result.map((item) => item.userId);
116
+ console.log("Found departments with access:", result.length);
117
+ console.log("User IDs with access:", userIds);
118
+ console.log("=== End getting users ===");
119
+ return userIds;
120
+ };
121
+ const sendOrderNotifications = async (order, type, userIds, extraData = {}) => {
122
+ console.log("=== Sending order notifications ===");
123
+ console.log("Order ID:", order._id);
124
+ console.log("Type:", type);
125
+ console.log("User IDs:", userIds);
126
+ console.log("Extra data:", extraData);
127
+ if (!userIds || userIds.length === 0) {
128
+ console.log("No users to notify, skipping...");
129
+ return;
131
130
  }
132
- const newCustomerData = {
133
- ...customerInfo,
134
- // Ensure we're not passing any null _id that might override MongoDB's auto-generation
135
- _id: void 0,
136
- // Let MongoDB generate this
137
- owner: orderOwner,
138
- creator: {
139
- type: creatorType,
140
- target: creatorTarget
131
+ const notifications = userIds.map((userId) => ({
132
+ title: getNotificationTitle(type, order, extraData),
133
+ body: getNotificationBody(type, order, extraData),
134
+ type,
135
+ metadata: {
136
+ type,
137
+ orderId: order._id,
138
+ context: "organization",
139
+ ...extraData
141
140
  },
142
- identity: {
143
- type: customerInfo.identity?.type || creatorType,
144
- target: customerInfo.identity?.target || creatorTarget
141
+ userId
142
+ }));
143
+ function getNotificationTitle(type2, order2, extraData2 = {}) {
144
+ switch (type2) {
145
+ case "order_created":
146
+ return "New Order";
147
+ case "order_status":
148
+ return "Order Status Updated";
149
+ default:
150
+ return "Order Notification";
145
151
  }
146
- };
152
+ }
153
+ function getNotificationBody(type2, order2, extraData2 = {}) {
154
+ switch (type2) {
155
+ case "order_created":
156
+ return `New order #${order2._id} created`;
157
+ case "order_status":
158
+ return `Order #${order2._id} changed from ${extraData2.oldStatus} to ${extraData2.newStatus}`;
159
+ default:
160
+ return `Order #${order2._id} updated`;
161
+ }
162
+ }
163
+ console.log("Prepared notifications:", JSON.stringify(notifications, null, 2));
164
+ console.log("API URL:", `${process.env.API_URL || ""}/api/notifications/batch`);
147
165
  try {
148
- customer = await Customer.create(newCustomerData);
149
- if (!customer || !customer._id) {
150
- console.error("Customer creation failed to generate _id:", customer);
151
- throw new Error("Customer creation did not generate a valid _id");
166
+ const response = await fetch(`${process.env.API_URL || ""}/api/notifications/batch`, {
167
+ method: "POST",
168
+ headers: {
169
+ "Content-Type": "application/json",
170
+ "X-Service-Key": process.env.SERVICE_KEY
171
+ },
172
+ body: JSON.stringify({ notifications })
173
+ });
174
+ console.log("Notification response status:", response.status);
175
+ if (!response.ok) {
176
+ const errorData = await response.text();
177
+ console.error("Notification API error:", errorData);
178
+ throw new Error(`Notification API failed: ${response.status} - ${errorData}`);
179
+ }
180
+ const result = await response.json();
181
+ console.log("Notification API success:", result);
182
+ console.log("=== End sending notifications ===");
183
+ return result;
184
+ } catch (error) {
185
+ console.error("=== Notification sending failed ===");
186
+ console.error("Error:", error.message);
187
+ console.error("Stack:", error.stack);
188
+ throw error;
189
+ }
190
+ };
191
+ const findOrCreateCustomer = async (customerInfo, orderOwner, orderCreator, req) => {
192
+ let searchCriteria = {};
193
+ if (customerInfo.phone) {
194
+ searchCriteria.phone = customerInfo.phone;
195
+ }
196
+ if (customerInfo.email) {
197
+ searchCriteria.email = customerInfo.email;
198
+ }
199
+ let customer = null;
200
+ if (Object.keys(searchCriteria).length > 0) {
201
+ customer = await Customer.findOne({ $or: [searchCriteria] });
202
+ }
203
+ if (!customer) {
204
+ const visitor = await findOrCreateVisitor(req);
205
+ let creatorType = customerInfo.creator?.type || orderCreator.type;
206
+ let creatorTarget = customerInfo.creator?.target || orderCreator.target;
207
+ if (!creatorTarget) {
208
+ creatorType = orderOwner.type;
209
+ creatorTarget = orderOwner.target;
210
+ }
211
+ const newCustomerData = {
212
+ ...customerInfo,
213
+ // Ensure we're not passing any null _id that might override MongoDB's auto-generation
214
+ _id: void 0,
215
+ // Let MongoDB generate this
216
+ owner: orderOwner,
217
+ creator: {
218
+ type: creatorType,
219
+ target: creatorTarget
220
+ },
221
+ identity: {
222
+ type: "Visitor",
223
+ target: visitor._id
224
+ }
225
+ };
226
+ try {
227
+ customer = await Customer.create(newCustomerData);
228
+ if (!customer || !customer._id) {
229
+ console.error("Customer creation failed to generate _id:", customer);
230
+ throw new Error("Customer creation did not generate a valid _id");
231
+ }
232
+ } catch (err) {
233
+ console.error("Error creating customer:", err);
234
+ throw err;
152
235
  }
153
- } catch (err) {
154
- console.error("Error creating customer:", err);
155
- throw err;
156
236
  }
157
- }
158
- return customer;
159
- }
160
- async function sendOrderMessage(orderData) {
161
- try {
162
- const formattedMessage = formatOrderMessage(orderData);
163
- await sendChatMessageTelegram$1(process.env.TELEGRAM_BOT_USERS.split(","), formattedMessage);
164
- } catch (err) {
165
- console.error(err);
166
- }
167
- }
168
- const controllerFactory = (db) => {
169
- const Order = db.order;
170
- const Customer = db.customer;
237
+ return customer;
238
+ };
171
239
  const create = async (req, res) => {
172
240
  const orderData = req.body;
173
241
  req.userId || req.body.creator?.target;
@@ -182,7 +250,7 @@ const controllerFactory = (db) => {
182
250
  session.startTransaction();
183
251
  try {
184
252
  if (!orderData.customer.target) {
185
- const customer = await findOrCreateCustomer(Customer, orderData.customer, orderData.owner, orderData.creator);
253
+ const customer = await findOrCreateCustomer(orderData.customer, orderData.owner, orderData.creator, req);
186
254
  console.log("customer is", customer);
187
255
  if (!customer || !customer._id) {
188
256
  throw new Error("Failed to create or find a valid customer");
@@ -202,7 +270,12 @@ const controllerFactory = (db) => {
202
270
  const order = await Order.create([orderData], { session });
203
271
  const createdOrder = order[0];
204
272
  await session.commitTransaction();
205
- sendOrderMessage(orderData).catch(console.error);
273
+ try {
274
+ const usersWithAccess = await getUsersWithOrdersConfirmAccess(orderData.owner.target);
275
+ await sendOrderNotifications(createdOrder, "order_created", usersWithAccess);
276
+ } catch (notificationError) {
277
+ console.error("Error sending notification:", notificationError);
278
+ }
206
279
  res.status(201).send(createdOrder);
207
280
  } catch (err) {
208
281
  await session.abortTransaction();
@@ -407,35 +480,15 @@ const controllerFactory = (db) => {
407
480
  if (statusChanged) {
408
481
  console.log("Sending notification for status change...");
409
482
  try {
410
- const notificationData = {
411
- title: `Order Status Updated`,
412
- body: `Order #${order._id} status changed from ${oldStatus} to ${order.status}`,
413
- type: "order_status",
414
- metadata: {
415
- orderId: order._id,
416
- oldStatus,
417
- newStatus: order.status,
418
- positions: order.positions
419
- },
420
- userId: order.creator.target
421
- // Assuming creator.target holds the user ID
422
- };
423
- console.log("Notification data:", JSON.stringify(notificationData));
424
- const notificationResponse = await fetch(`${process.env.API_URL || ""}/api/notifications`, {
425
- method: "POST",
426
- headers: {
427
- "Content-Type": "application/json",
428
- "X-Service-Key": process.env.SERVICE_KEY
429
- },
430
- body: JSON.stringify(notificationData)
483
+ const usersWithAccess = await getUsersWithOrdersConfirmAccess(order.owner.target);
484
+ const filteredUsers = usersWithAccess.filter(
485
+ (userId) => userId.toString() !== order.creator.target.toString()
486
+ );
487
+ await sendOrderNotifications(order, "order_status", filteredUsers, {
488
+ oldStatus,
489
+ newStatus: order.status
431
490
  });
432
- console.log("Notification response status:", notificationResponse.status);
433
- if (!notificationResponse.ok) {
434
- const errorData = await notificationResponse.json();
435
- console.error(`Failed to create notification: ${JSON.stringify(errorData)}`);
436
- } else {
437
- console.log("Notification sent successfully");
438
- }
491
+ console.log("Notification sent successfully");
439
492
  } catch (notificationError) {
440
493
  console.error("Error sending notification:", notificationError);
441
494
  }
@@ -583,6 +583,10 @@ const controllerFactory = (db) => {
583
583
  ...queryProcessor.queryProcessorGlobals.getSearchOptions(req.query.search, {
584
584
  fields: ["name", "description"]
585
585
  }),
586
+ ...queryProcessor.queryProcessorGlobals.getFilterDate(req.query.dateStart, req.query.dateEnd, {
587
+ start: "startDate",
588
+ end: "endDate"
589
+ }),
586
590
  ...queryProcessor.queryProcessorGlobals.getPriceConditions(req.query.prices),
587
591
  ...queryProcessorProducts.getCategoriesFilterStage(req.query.categories),
588
592
  ...queryProcessorProducts.getDeliveryFilterStage(req.query.delivery),
@@ -581,6 +581,10 @@ const controllerFactory = (db) => {
581
581
  ...queryProcessorGlobals.getSearchOptions(req.query.search, {
582
582
  fields: ["name", "description"]
583
583
  }),
584
+ ...queryProcessorGlobals.getFilterDate(req.query.dateStart, req.query.dateEnd, {
585
+ start: "startDate",
586
+ end: "endDate"
587
+ }),
584
588
  ...queryProcessorGlobals.getPriceConditions(req.query.prices),
585
589
  ...queryProcessorProducts.getCategoriesFilterStage(req.query.categories),
586
590
  ...queryProcessorProducts.getDeliveryFilterStage(req.query.delivery),