@shophost/rest-api 2.0.30 → 2.0.31

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 (352) hide show
  1. package/package.json +18 -13
  2. package/scripts/minify.mjs +110 -0
  3. package/src/app.js +1 -53
  4. package/src/core/auth/auth.schema.js +1 -41
  5. package/src/core/auth/auth.util.js +1 -44
  6. package/src/core/auth/better-auth.lib.js +1 -100
  7. package/src/core/auth/generate-password-hash.util.d.ts +0 -3
  8. package/src/core/auth/generate-password-hash.util.js +1 -30
  9. package/src/core/auth/headers.schema.js +1 -22
  10. package/src/core/auth/user.schema.js +1 -30
  11. package/src/core/db/__generated__/client/browser.d.ts +0 -128
  12. package/src/core/db/__generated__/client/browser.js +1 -18
  13. package/src/core/db/__generated__/client/client.d.ts +0 -143
  14. package/src/core/db/__generated__/client/client.js +1 -35
  15. package/src/core/db/__generated__/client/commonInputTypes.js +1 -11
  16. package/src/core/db/__generated__/client/enums.js +1 -200
  17. package/src/core/db/__generated__/client/internal/class.d.ts +0 -343
  18. package/src/core/db/__generated__/client/internal/class.js +1 -55
  19. package/src/core/db/__generated__/client/internal/prismaNamespace.d.ts +0 -234
  20. package/src/core/db/__generated__/client/internal/prismaNamespace.js +1 -541
  21. package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.d.ts +0 -15
  22. package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js +1 -512
  23. package/src/core/db/__generated__/client/models/Account.d.ts +0 -628
  24. package/src/core/db/__generated__/client/models/Account.js +1 -2
  25. package/src/core/db/__generated__/client/models/Address.d.ts +0 -701
  26. package/src/core/db/__generated__/client/models/Address.js +1 -2
  27. package/src/core/db/__generated__/client/models/Campaign.d.ts +0 -638
  28. package/src/core/db/__generated__/client/models/Campaign.js +1 -2
  29. package/src/core/db/__generated__/client/models/ClosingTimes.d.ts +0 -634
  30. package/src/core/db/__generated__/client/models/ClosingTimes.js +1 -2
  31. package/src/core/db/__generated__/client/models/File.d.ts +0 -752
  32. package/src/core/db/__generated__/client/models/File.js +1 -2
  33. package/src/core/db/__generated__/client/models/Invitation.d.ts +0 -628
  34. package/src/core/db/__generated__/client/models/Invitation.js +1 -2
  35. package/src/core/db/__generated__/client/models/LegalEntity.d.ts +0 -652
  36. package/src/core/db/__generated__/client/models/LegalEntity.js +1 -2
  37. package/src/core/db/__generated__/client/models/Manufacturer.d.ts +0 -679
  38. package/src/core/db/__generated__/client/models/Manufacturer.js +1 -2
  39. package/src/core/db/__generated__/client/models/ManufacturerTranslation.d.ts +0 -628
  40. package/src/core/db/__generated__/client/models/ManufacturerTranslation.js +1 -2
  41. package/src/core/db/__generated__/client/models/Member.d.ts +0 -628
  42. package/src/core/db/__generated__/client/models/Member.js +1 -2
  43. package/src/core/db/__generated__/client/models/Modifier.d.ts +0 -662
  44. package/src/core/db/__generated__/client/models/Modifier.js +1 -2
  45. package/src/core/db/__generated__/client/models/ModifierGroup.d.ts +0 -686
  46. package/src/core/db/__generated__/client/models/ModifierGroup.js +1 -2
  47. package/src/core/db/__generated__/client/models/ModifierGroupTranslation.d.ts +0 -628
  48. package/src/core/db/__generated__/client/models/ModifierGroupTranslation.js +1 -2
  49. package/src/core/db/__generated__/client/models/OpeningTimes.d.ts +0 -634
  50. package/src/core/db/__generated__/client/models/OpeningTimes.js +1 -2
  51. package/src/core/db/__generated__/client/models/Order.d.ts +0 -700
  52. package/src/core/db/__generated__/client/models/Order.js +1 -2
  53. package/src/core/db/__generated__/client/models/OrderItem.d.ts +0 -686
  54. package/src/core/db/__generated__/client/models/OrderItem.js +1 -2
  55. package/src/core/db/__generated__/client/models/OrderItemTranslation.d.ts +0 -628
  56. package/src/core/db/__generated__/client/models/OrderItemTranslation.js +1 -2
  57. package/src/core/db/__generated__/client/models/Organization.d.ts +0 -811
  58. package/src/core/db/__generated__/client/models/Organization.js +1 -2
  59. package/src/core/db/__generated__/client/models/OrganizationConfiguration.d.ts +0 -676
  60. package/src/core/db/__generated__/client/models/OrganizationConfiguration.js +1 -2
  61. package/src/core/db/__generated__/client/models/Payment.d.ts +0 -668
  62. package/src/core/db/__generated__/client/models/Payment.js +1 -2
  63. package/src/core/db/__generated__/client/models/PaymentSession.d.ts +0 -638
  64. package/src/core/db/__generated__/client/models/PaymentSession.js +1 -2
  65. package/src/core/db/__generated__/client/models/Product.d.ts +0 -746
  66. package/src/core/db/__generated__/client/models/Product.js +1 -2
  67. package/src/core/db/__generated__/client/models/ProductCategory.d.ts +0 -689
  68. package/src/core/db/__generated__/client/models/ProductCategory.js +1 -2
  69. package/src/core/db/__generated__/client/models/ProductCategoryTranslation.d.ts +0 -628
  70. package/src/core/db/__generated__/client/models/ProductCategoryTranslation.js +1 -2
  71. package/src/core/db/__generated__/client/models/ProductSnapshot.d.ts +0 -664
  72. package/src/core/db/__generated__/client/models/ProductSnapshot.js +1 -2
  73. package/src/core/db/__generated__/client/models/ProductTranslation.d.ts +0 -628
  74. package/src/core/db/__generated__/client/models/ProductTranslation.js +1 -2
  75. package/src/core/db/__generated__/client/models/Reservation.d.ts +0 -650
  76. package/src/core/db/__generated__/client/models/Reservation.js +1 -2
  77. package/src/core/db/__generated__/client/models/Session.d.ts +0 -628
  78. package/src/core/db/__generated__/client/models/Session.js +1 -2
  79. package/src/core/db/__generated__/client/models/ShippingMethod.d.ts +0 -679
  80. package/src/core/db/__generated__/client/models/ShippingMethod.js +1 -2
  81. package/src/core/db/__generated__/client/models/ShippingZone.d.ts +0 -638
  82. package/src/core/db/__generated__/client/models/ShippingZone.js +1 -2
  83. package/src/core/db/__generated__/client/models/User.d.ts +0 -736
  84. package/src/core/db/__generated__/client/models/User.js +1 -2
  85. package/src/core/db/__generated__/client/models/Verification.d.ts +0 -592
  86. package/src/core/db/__generated__/client/models/Verification.js +1 -2
  87. package/src/core/db/__generated__/client/models.js +1 -2
  88. package/src/core/db/index.js +1 -2
  89. package/src/core/exceptions/http-exception.js +1 -9
  90. package/src/core/hono/hono.js +1 -123
  91. package/src/core/lib/prisma.d.ts +9 -1
  92. package/src/core/lib/prisma.js +1 -11
  93. package/src/core/logging/pino.js +1 -5
  94. package/src/core/notifications/email.service.d.ts +0 -15
  95. package/src/core/notifications/email.service.js +1 -116
  96. package/src/core/openapi/openapi.lib.js +1 -26
  97. package/src/core/types/google-maps.types.js +1 -2
  98. package/src/core/utils/currency.util.js +1 -11
  99. package/src/core/utils/env.util.js +1 -8
  100. package/src/core/utils/object.util.d.ts +0 -10
  101. package/src/core/utils/object.util.js +1 -39
  102. package/src/core/utils/translations.util.js +0 -2
  103. package/src/core/utils/zod.util.d.ts +0 -12
  104. package/src/core/utils/zod.util.js +1 -85
  105. package/src/db.js +1 -3
  106. package/src/features/access/access.handler.js +1 -91
  107. package/src/features/access/access.route.js +1 -220
  108. package/src/features/access/access.schema.js +1 -108
  109. package/src/features/access/access.service.js +1 -294
  110. package/src/features/cart/cart.handler.js +1 -17
  111. package/src/features/cart/cart.route.js +1 -32
  112. package/src/features/cart/cart.schema.js +1 -39
  113. package/src/features/cart/cart.service.d.ts +0 -7
  114. package/src/features/cart/cart.service.js +1 -97
  115. package/src/features/cart/cart.util.js +1 -76
  116. package/src/features/file/file.handler.js +1 -23
  117. package/src/features/file/file.route.js +1 -34
  118. package/src/features/file/file.schema.js +1 -77
  119. package/src/features/file/file.service.d.ts +0 -6
  120. package/src/features/file/file.service.js +1 -66
  121. package/src/features/health/health.handler.js +1 -10
  122. package/src/features/health/health.route.js +1 -25
  123. package/src/features/index.js +1 -16
  124. package/src/features/location/location.handler.js +1 -25
  125. package/src/features/location/location.route.js +1 -56
  126. package/src/features/location/location.schema.js +1 -50
  127. package/src/features/location/location.service.d.ts +0 -3
  128. package/src/features/location/location.service.js +1 -141
  129. package/src/features/manufacturer/manufacturer.handler.js +1 -53
  130. package/src/features/manufacturer/manufacturer.route.js +1 -97
  131. package/src/features/manufacturer/manufacturer.schema.js +1 -125
  132. package/src/features/manufacturer/manufacturer.service.d.ts +0 -19
  133. package/src/features/manufacturer/manufacturer.service.js +1 -190
  134. package/src/features/order/emails/order-confirmation.email.js +1 -229
  135. package/src/features/order/emails/order-notification.email.js +1 -229
  136. package/src/features/order/fulfilment.schema.js +1 -3
  137. package/src/features/order/order.handler.js +1 -54
  138. package/src/features/order/order.route.js +1 -111
  139. package/src/features/order/order.schema.js +1 -158
  140. package/src/features/order/order.service.d.ts +0 -15
  141. package/src/features/order/order.service.js +1 -306
  142. package/src/features/order/recipient.schema.js +1 -38
  143. package/src/features/organization/legal-entity.schema.js +1 -83
  144. package/src/features/organization/organization-configuration.schema.js +1 -115
  145. package/src/features/organization/organization.handler.js +1 -48
  146. package/src/features/organization/organization.route.js +1 -84
  147. package/src/features/organization/organization.schema.js +1 -64
  148. package/src/features/organization/organization.service.d.ts +0 -15
  149. package/src/features/organization/organization.service.js +1 -334
  150. package/src/features/payment/payment.handler.js +1 -16
  151. package/src/features/payment/payment.route.js +1 -22
  152. package/src/features/payment/payment.schema.js +1 -46
  153. package/src/features/payment/payment.service.js +1 -100
  154. package/src/features/payment/stripe.service.js +1 -164
  155. package/src/features/product/product-modifier.schema.js +1 -84
  156. package/src/features/product/product.handler.js +1 -87
  157. package/src/features/product/product.route.js +1 -179
  158. package/src/features/product/product.schema.js +1 -143
  159. package/src/features/product/product.service.d.ts +0 -25
  160. package/src/features/product/product.service.js +1 -440
  161. package/src/features/product-category/product-category.handler.js +1 -59
  162. package/src/features/product-category/product-category.route.js +1 -139
  163. package/src/features/product-category/product-category.schema.js +1 -86
  164. package/src/features/product-category/product-category.service.d.ts +0 -22
  165. package/src/features/product-category/product-category.service.js +1 -220
  166. package/src/features/reservation/emails/reservation-cancellation.email.js +1 -82
  167. package/src/features/reservation/emails/reservation-confirmation.email.js +1 -82
  168. package/src/features/reservation/emails/reservation-notification.email.js +1 -93
  169. package/src/features/reservation/reservation.handler.js +1 -65
  170. package/src/features/reservation/reservation.route.js +1 -167
  171. package/src/features/reservation/reservation.schema.js +1 -51
  172. package/src/features/reservation/reservation.service.d.ts +0 -18
  173. package/src/features/reservation/reservation.service.js +1 -231
  174. package/src/features/shipping/shipping.handler.js +1 -32
  175. package/src/features/shipping/shipping.route.js +1 -51
  176. package/src/features/shipping/shipping.service.d.ts +0 -7
  177. package/src/features/shipping/shipping.service.js +1 -96
  178. package/src/features/shipping-method/shipping-method.handler.js +1 -60
  179. package/src/features/shipping-method/shipping-method.route.js +1 -144
  180. package/src/features/shipping-method/shipping-method.schema.js +1 -48
  181. package/src/features/shipping-method/shipping-method.service.d.ts +0 -25
  182. package/src/features/shipping-method/shipping-method.service.js +1 -229
  183. package/src/features/shipping-method/shipping-zone.schema.js +1 -31
  184. package/src/features/webhook/webhook.handler.js +1 -50
  185. package/src/features/webhook/webhook.route.js +1 -33
  186. package/src/index.js +1 -6
  187. package/src/integrations/next.js +1 -82
  188. package/src/schemas/address.schema.d.ts +0 -8
  189. package/src/schemas/address.schema.js +1 -112
  190. package/src/schemas/currency.schema.d.ts +0 -42
  191. package/src/schemas/currency.schema.js +1 -118
  192. package/src/schemas/error.schema.js +1 -12
  193. package/src/schemas/index.js +1 -29
  194. package/src/schemas/locales.schema.js +1 -238
  195. package/src/schemas/number.schema.js +1 -29
  196. package/src/schemas/pagination.schema.js +1 -54
  197. package/src/schemas/params.schema.js +1 -20
  198. package/src/schemas/queries.schema.js +1 -6
  199. package/src/test/global-setup.d.ts +1 -0
  200. package/src/test/global-setup.js +1 -0
  201. package/src/test/integration/api-fixtures.d.ts +4 -16
  202. package/src/test/integration/api-fixtures.js +1 -225
  203. package/src/test/integration/seed.d.ts +81 -0
  204. package/src/test/integration/seed.js +1 -0
  205. package/src/test/integration/test-helpers.d.ts +107 -924
  206. package/src/test/integration/test-helpers.js +1 -1100
  207. package/src/test/setup-test-env.d.ts +1 -1
  208. package/src/test/setup-test-env.js +1 -29
  209. package/src/app.js.map +0 -1
  210. package/src/core/auth/auth.schema.js.map +0 -1
  211. package/src/core/auth/auth.util.js.map +0 -1
  212. package/src/core/auth/better-auth.lib.js.map +0 -1
  213. package/src/core/auth/generate-password-hash.util.js.map +0 -1
  214. package/src/core/auth/headers.schema.js.map +0 -1
  215. package/src/core/auth/user.schema.js.map +0 -1
  216. package/src/core/db/__generated__/client/browser.js.map +0 -1
  217. package/src/core/db/__generated__/client/client.js.map +0 -1
  218. package/src/core/db/__generated__/client/commonInputTypes.js.map +0 -1
  219. package/src/core/db/__generated__/client/enums.js.map +0 -1
  220. package/src/core/db/__generated__/client/internal/class.js.map +0 -1
  221. package/src/core/db/__generated__/client/internal/prismaNamespace.js.map +0 -1
  222. package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js.map +0 -1
  223. package/src/core/db/__generated__/client/models/Account.js.map +0 -1
  224. package/src/core/db/__generated__/client/models/Address.js.map +0 -1
  225. package/src/core/db/__generated__/client/models/Campaign.js.map +0 -1
  226. package/src/core/db/__generated__/client/models/ClosingTimes.js.map +0 -1
  227. package/src/core/db/__generated__/client/models/File.js.map +0 -1
  228. package/src/core/db/__generated__/client/models/Invitation.js.map +0 -1
  229. package/src/core/db/__generated__/client/models/LegalEntity.js.map +0 -1
  230. package/src/core/db/__generated__/client/models/Manufacturer.js.map +0 -1
  231. package/src/core/db/__generated__/client/models/ManufacturerTranslation.js.map +0 -1
  232. package/src/core/db/__generated__/client/models/Member.js.map +0 -1
  233. package/src/core/db/__generated__/client/models/Modifier.js.map +0 -1
  234. package/src/core/db/__generated__/client/models/ModifierGroup.js.map +0 -1
  235. package/src/core/db/__generated__/client/models/ModifierGroupTranslation.js.map +0 -1
  236. package/src/core/db/__generated__/client/models/OpeningTimes.js.map +0 -1
  237. package/src/core/db/__generated__/client/models/Order.js.map +0 -1
  238. package/src/core/db/__generated__/client/models/OrderItem.js.map +0 -1
  239. package/src/core/db/__generated__/client/models/OrderItemTranslation.js.map +0 -1
  240. package/src/core/db/__generated__/client/models/Organization.js.map +0 -1
  241. package/src/core/db/__generated__/client/models/OrganizationConfiguration.js.map +0 -1
  242. package/src/core/db/__generated__/client/models/Payment.js.map +0 -1
  243. package/src/core/db/__generated__/client/models/PaymentSession.js.map +0 -1
  244. package/src/core/db/__generated__/client/models/Product.js.map +0 -1
  245. package/src/core/db/__generated__/client/models/ProductCategory.js.map +0 -1
  246. package/src/core/db/__generated__/client/models/ProductCategoryTranslation.js.map +0 -1
  247. package/src/core/db/__generated__/client/models/ProductSnapshot.js.map +0 -1
  248. package/src/core/db/__generated__/client/models/ProductTranslation.js.map +0 -1
  249. package/src/core/db/__generated__/client/models/Reservation.js.map +0 -1
  250. package/src/core/db/__generated__/client/models/Session.js.map +0 -1
  251. package/src/core/db/__generated__/client/models/ShippingMethod.js.map +0 -1
  252. package/src/core/db/__generated__/client/models/ShippingZone.js.map +0 -1
  253. package/src/core/db/__generated__/client/models/User.js.map +0 -1
  254. package/src/core/db/__generated__/client/models/Verification.js.map +0 -1
  255. package/src/core/db/__generated__/client/models.js.map +0 -1
  256. package/src/core/db/index.js.map +0 -1
  257. package/src/core/exceptions/http-exception.js.map +0 -1
  258. package/src/core/hono/hono.js.map +0 -1
  259. package/src/core/lib/prisma.js.map +0 -1
  260. package/src/core/logging/pino.js.map +0 -1
  261. package/src/core/notifications/email.service.js.map +0 -1
  262. package/src/core/openapi/openapi.lib.js.map +0 -1
  263. package/src/core/types/google-maps.types.js.map +0 -1
  264. package/src/core/utils/currency.util.js.map +0 -1
  265. package/src/core/utils/env.util.js.map +0 -1
  266. package/src/core/utils/object.util.js.map +0 -1
  267. package/src/core/utils/translations.util.js.map +0 -1
  268. package/src/core/utils/zod.util.js.map +0 -1
  269. package/src/db.js.map +0 -1
  270. package/src/features/access/access.handler.js.map +0 -1
  271. package/src/features/access/access.route.js.map +0 -1
  272. package/src/features/access/access.schema.js.map +0 -1
  273. package/src/features/access/access.service.js.map +0 -1
  274. package/src/features/cart/cart.handler.js.map +0 -1
  275. package/src/features/cart/cart.route.js.map +0 -1
  276. package/src/features/cart/cart.schema.js.map +0 -1
  277. package/src/features/cart/cart.service.js.map +0 -1
  278. package/src/features/cart/cart.util.js.map +0 -1
  279. package/src/features/file/file.handler.js.map +0 -1
  280. package/src/features/file/file.route.js.map +0 -1
  281. package/src/features/file/file.schema.js.map +0 -1
  282. package/src/features/file/file.service.js.map +0 -1
  283. package/src/features/health/health.handler.js.map +0 -1
  284. package/src/features/health/health.route.js.map +0 -1
  285. package/src/features/index.js.map +0 -1
  286. package/src/features/location/location.handler.js.map +0 -1
  287. package/src/features/location/location.route.js.map +0 -1
  288. package/src/features/location/location.schema.js.map +0 -1
  289. package/src/features/location/location.service.js.map +0 -1
  290. package/src/features/manufacturer/manufacturer.handler.js.map +0 -1
  291. package/src/features/manufacturer/manufacturer.route.js.map +0 -1
  292. package/src/features/manufacturer/manufacturer.schema.js.map +0 -1
  293. package/src/features/manufacturer/manufacturer.service.js.map +0 -1
  294. package/src/features/order/emails/order-confirmation.email.js.map +0 -1
  295. package/src/features/order/emails/order-notification.email.js.map +0 -1
  296. package/src/features/order/fulfilment.schema.js.map +0 -1
  297. package/src/features/order/order.handler.js.map +0 -1
  298. package/src/features/order/order.route.js.map +0 -1
  299. package/src/features/order/order.schema.js.map +0 -1
  300. package/src/features/order/order.service.js.map +0 -1
  301. package/src/features/order/recipient.schema.js.map +0 -1
  302. package/src/features/organization/legal-entity.schema.js.map +0 -1
  303. package/src/features/organization/organization-configuration.schema.js.map +0 -1
  304. package/src/features/organization/organization.handler.js.map +0 -1
  305. package/src/features/organization/organization.route.js.map +0 -1
  306. package/src/features/organization/organization.schema.js.map +0 -1
  307. package/src/features/organization/organization.service.js.map +0 -1
  308. package/src/features/payment/payment.handler.js.map +0 -1
  309. package/src/features/payment/payment.route.js.map +0 -1
  310. package/src/features/payment/payment.schema.js.map +0 -1
  311. package/src/features/payment/payment.service.js.map +0 -1
  312. package/src/features/payment/stripe.service.js.map +0 -1
  313. package/src/features/product/product-modifier.schema.js.map +0 -1
  314. package/src/features/product/product.handler.js.map +0 -1
  315. package/src/features/product/product.route.js.map +0 -1
  316. package/src/features/product/product.schema.js.map +0 -1
  317. package/src/features/product/product.service.js.map +0 -1
  318. package/src/features/product-category/product-category.handler.js.map +0 -1
  319. package/src/features/product-category/product-category.route.js.map +0 -1
  320. package/src/features/product-category/product-category.schema.js.map +0 -1
  321. package/src/features/product-category/product-category.service.js.map +0 -1
  322. package/src/features/reservation/emails/reservation-cancellation.email.js.map +0 -1
  323. package/src/features/reservation/emails/reservation-confirmation.email.js.map +0 -1
  324. package/src/features/reservation/emails/reservation-notification.email.js.map +0 -1
  325. package/src/features/reservation/reservation.handler.js.map +0 -1
  326. package/src/features/reservation/reservation.route.js.map +0 -1
  327. package/src/features/reservation/reservation.schema.js.map +0 -1
  328. package/src/features/reservation/reservation.service.js.map +0 -1
  329. package/src/features/shipping/shipping.handler.js.map +0 -1
  330. package/src/features/shipping/shipping.route.js.map +0 -1
  331. package/src/features/shipping/shipping.service.js.map +0 -1
  332. package/src/features/shipping-method/shipping-method.handler.js.map +0 -1
  333. package/src/features/shipping-method/shipping-method.route.js.map +0 -1
  334. package/src/features/shipping-method/shipping-method.schema.js.map +0 -1
  335. package/src/features/shipping-method/shipping-method.service.js.map +0 -1
  336. package/src/features/shipping-method/shipping-zone.schema.js.map +0 -1
  337. package/src/features/webhook/webhook.handler.js.map +0 -1
  338. package/src/features/webhook/webhook.route.js.map +0 -1
  339. package/src/index.js.map +0 -1
  340. package/src/integrations/next.js.map +0 -1
  341. package/src/schemas/address.schema.js.map +0 -1
  342. package/src/schemas/currency.schema.js.map +0 -1
  343. package/src/schemas/error.schema.js.map +0 -1
  344. package/src/schemas/index.js.map +0 -1
  345. package/src/schemas/locales.schema.js.map +0 -1
  346. package/src/schemas/number.schema.js.map +0 -1
  347. package/src/schemas/pagination.schema.js.map +0 -1
  348. package/src/schemas/params.schema.js.map +0 -1
  349. package/src/schemas/queries.schema.js.map +0 -1
  350. package/src/test/integration/api-fixtures.js.map +0 -1
  351. package/src/test/integration/test-helpers.js.map +0 -1
  352. package/src/test/setup-test-env.js.map +0 -1
@@ -1,111 +1 @@
1
- import { z } from "@hono/zod-openapi";
2
- import { createApiRoute } from "../../core/hono/hono";
3
- import { CreateOrderSchema, ErrorSchema, HeaderSchema, OrderSchema, OrderStatusSchema, OrganizationParams, OrganizationWithIdParams, PaginationMetaSchema, PaginationQuerySchema, } from "../../schemas";
4
- const getOrdersRoute = createApiRoute({
5
- description: "Fetches paginated list of orders",
6
- headers: HeaderSchema,
7
- method: "GET",
8
- operationId: "getOrders",
9
- path: "/:organizationId/orders",
10
- pathParams: OrganizationParams,
11
- query: PaginationQuerySchema,
12
- responses: {
13
- 200: z.object({
14
- list: z.array(OrderSchema),
15
- meta: PaginationMetaSchema,
16
- }),
17
- 400: ErrorSchema,
18
- 401: ErrorSchema,
19
- },
20
- summary: "Get Orders",
21
- tags: ["Order"],
22
- });
23
- const createOrderRoute = createApiRoute({
24
- body: CreateOrderSchema,
25
- description: "Creates a new order",
26
- headers: HeaderSchema,
27
- method: "POST",
28
- operationId: "createOrder",
29
- path: "/:organizationId/orders",
30
- pathParams: z.object({
31
- organizationId: z
32
- .string()
33
- .cuid()
34
- .min(1)
35
- .openapi({
36
- description: "The organization ID",
37
- example: "ckel0e8qw00004n5p5w6fznym",
38
- param: {
39
- in: "path",
40
- name: "organizationId",
41
- },
42
- }),
43
- }),
44
- responses: {
45
- 201: z.object({
46
- order: OrderSchema,
47
- redirectUrl: z.string().url().optional(),
48
- }),
49
- 400: ErrorSchema,
50
- 401: ErrorSchema,
51
- 404: ErrorSchema,
52
- },
53
- summary: "Create Order",
54
- tags: ["Order"],
55
- });
56
- const getOrderRoute = createApiRoute({
57
- headers: HeaderSchema,
58
- method: "GET",
59
- operationId: "getOrder",
60
- path: "/:organizationId/orders/:id",
61
- pathParams: OrganizationWithIdParams,
62
- responses: {
63
- 200: OrderSchema,
64
- 401: ErrorSchema,
65
- 404: ErrorSchema,
66
- },
67
- summary: "Get Order",
68
- tags: ["Order"],
69
- });
70
- const updateStatusRoute = createApiRoute({
71
- description: "Changes the status of an existing order based on the operation",
72
- headers: HeaderSchema,
73
- method: "POST",
74
- operationId: "updateOrderStatus",
75
- path: "/:organizationId/orders/:id/status/:operation",
76
- pathParams: OrganizationWithIdParams.extend({
77
- operation: OrderStatusSchema,
78
- }),
79
- responses: {
80
- 200: OrderSchema,
81
- 400: ErrorSchema,
82
- 401: ErrorSchema,
83
- 404: ErrorSchema,
84
- },
85
- summary: "Change Order Status",
86
- tags: ["Order"],
87
- });
88
- const deleteOrderRoute = createApiRoute({
89
- description: "Soft deletes order",
90
- headers: HeaderSchema,
91
- method: "DELETE",
92
- operationId: "deleteOrder",
93
- path: "/:organizationId/orders/:id",
94
- pathParams: OrganizationWithIdParams,
95
- responses: {
96
- 204: null,
97
- 400: ErrorSchema,
98
- 401: ErrorSchema,
99
- 404: ErrorSchema,
100
- },
101
- summary: "Delete Order",
102
- tags: ["Order"],
103
- });
104
- export const orderRoute = {
105
- getOrders: getOrdersRoute,
106
- createOrder: createOrderRoute,
107
- getOrder: getOrderRoute,
108
- updateStatus: updateStatusRoute,
109
- deleteOrder: deleteOrderRoute,
110
- };
111
- //# sourceMappingURL=order.route.js.map
1
+ import{z as e}from"@hono/zod-openapi";import{createApiRoute as r}from"../../core/hono/hono";import{CreateOrderSchema as t,ErrorSchema as a,HeaderSchema as o,OrderSchema as d,OrderStatusSchema as s,OrganizationParams as n,OrganizationWithIdParams as i,PaginationMetaSchema as p,PaginationQuerySchema as m}from"../../schemas";const h=r({description:"Fetches paginated list of orders",headers:o,method:"GET",operationId:"getOrders",path:"/:organizationId/orders",pathParams:n,query:m,responses:{200:e.object({list:e.array(d),meta:p}),400:a,401:a},summary:"Get Orders",tags:["Order"]}),g=r({body:t,description:"Creates a new order",headers:o,method:"POST",operationId:"createOrder",path:"/:organizationId/orders",pathParams:e.object({organizationId:e.string().cuid().min(1).openapi({description:"The organization ID",example:"ckel0e8qw00004n5p5w6fznym",param:{in:"path",name:"organizationId"}})}),responses:{201:e.object({order:d,redirectUrl:e.string().url().optional()}),400:a,401:a,404:a},summary:"Create Order",tags:["Order"]}),O=r({headers:o,method:"GET",operationId:"getOrder",path:"/:organizationId/orders/:id",pathParams:i,responses:{200:d,401:a,404:a},summary:"Get Order",tags:["Order"]}),c=r({description:"Changes the status of an existing order based on the operation",headers:o,method:"POST",operationId:"updateOrderStatus",path:"/:organizationId/orders/:id/status/:operation",pathParams:i.extend({operation:s}),responses:{200:d,400:a,401:a,404:a},summary:"Change Order Status",tags:["Order"]}),u=r({description:"Soft deletes order",headers:o,method:"DELETE",operationId:"deleteOrder",path:"/:organizationId/orders/:id",pathParams:i,responses:{204:null,400:a,401:a,404:a},summary:"Delete Order",tags:["Order"]});export const orderRoute={getOrders:h,createOrder:g,getOrder:O,updateStatus:c,deleteOrder:u};
@@ -1,158 +1 @@
1
- import { z } from "@hono/zod-openapi";
2
- import { AddressSchema } from "../../schemas/address.schema";
3
- import { currency } from "../../schemas/currency.schema";
4
- import { locale } from "../../schemas/locales.schema";
5
- import { CartItemSchema, CartSchema } from "../cart/cart.schema";
6
- import { FileSchema } from "../file/file.schema";
7
- import { PaymentMethodSchema, PaymentProviderSchema, PaymentSchema, } from "../payment/payment.schema";
8
- import { ShippingMethodSchema } from "../shipping-method/shipping-method.schema";
9
- import { fulfilmentMethod } from "./fulfilment.schema";
10
- export const OrderStatusSchema = z
11
- .enum([
12
- "draft",
13
- "pending",
14
- "accepted",
15
- "ready-for-dispatch",
16
- "dispatched",
17
- "completed",
18
- "cancelled",
19
- ])
20
- .openapi({
21
- description: "Status of the order",
22
- example: "accepted",
23
- });
24
- export const OrderItemSchema = z
25
- .object({
26
- translations: z
27
- .array(z.object({
28
- locale: locale.openapi({
29
- description: "Locale of the translation",
30
- example: "en-US",
31
- }),
32
- title: z.string().openapi({
33
- description: "Title of the ordered product",
34
- example: "Premium Watch",
35
- }),
36
- subtitle: z.string().openapi({
37
- description: "Additional details about the ordered item, including modifiers",
38
- example: "Color: Silver, Size: Large",
39
- }),
40
- }))
41
- .openapi({
42
- description: "Translations for the order item",
43
- }),
44
- rawData: CartItemSchema,
45
- unitPrice: z.number().min(0).openapi({
46
- description: "Price per unit of the item",
47
- example: 299.99,
48
- }),
49
- image: FileSchema.nullable().optional(),
50
- totalPrice: z.number().min(0).openapi({
51
- description: "Total price for this item (unitPrice × quantity)",
52
- example: 599.98,
53
- }),
54
- quantity: z.number().min(1).openapi({
55
- description: "Number of units ordered",
56
- example: 2,
57
- }),
58
- productSnapshotId: z.string().cuid(),
59
- })
60
- .openapi("OrderItem");
61
- export const OrderSchema = z
62
- .object({
63
- id: z.string().openapi({
64
- description: "Unique identifier for the order",
65
- example: "clj1234567890abcdef",
66
- }),
67
- referenceId: z.string().openapi({
68
- description: "External reference ID for the order",
69
- example: "ORD-12345",
70
- }),
71
- status: OrderStatusSchema.optional(),
72
- token: z.string().openapi({
73
- description: "Security token for order verification",
74
- example: "a1b2c3d4e5f6g7h8i9j0",
75
- }),
76
- expiresAt: z.date().openapi({
77
- description: "Expiration date for the order",
78
- example: "2023-12-31T23:59:59Z",
79
- }),
80
- items: z.array(OrderItemSchema).min(1).openapi({
81
- description: "Array of items in the order",
82
- }),
83
- shippingMethod: ShippingMethodSchema.nullable().openapi({
84
- description: "Shipping method selected for the order",
85
- }),
86
- acceptedAt: z.date().nullable().optional().openapi({
87
- description: "Date when the order was accepted",
88
- example: "2023-06-15T14:30:00Z",
89
- }),
90
- dispatchedAt: z.date().nullable().optional().openapi({
91
- description: "Date when the order was dispatched",
92
- example: "2023-06-16T09:15:00Z",
93
- }),
94
- readyForDispatchAt: z.date().nullable().optional().openapi({
95
- description: "Date when the order was ready for dispatch",
96
- example: "2023-06-16T09:15:00Z",
97
- }),
98
- createdAt: z.date().openapi({
99
- description: "Date when the order was created",
100
- example: "2023-06-15T14:30:00Z",
101
- }),
102
- completedAt: z.date().nullable().optional().openapi({
103
- description: "Date when the order was completed",
104
- example: "2023-06-18T11:45:00Z",
105
- }),
106
- cancelledAt: z.date().nullable().optional().openapi({
107
- description: "Date when the order was cancelled",
108
- example: "2023-06-14T16:20:00Z",
109
- }),
110
- shippingAddress: AddressSchema.nullable().optional(),
111
- fulfilmentMethod: fulfilmentMethod.openapi({
112
- description: "Method of order fulfilment (pickup or delivery)",
113
- example: "delivery",
114
- }),
115
- currency: currency.openapi({
116
- description: "Currency used for the order",
117
- example: "USD",
118
- }),
119
- payment: PaymentSchema,
120
- })
121
- .transform((order) => {
122
- let status;
123
- if (order.cancelledAt) {
124
- status = "cancelled";
125
- }
126
- else if (order.completedAt) {
127
- status = "completed";
128
- }
129
- else if (order.dispatchedAt) {
130
- status = "dispatched";
131
- }
132
- else if (order.readyForDispatchAt) {
133
- status = "ready-for-dispatch";
134
- }
135
- else if (order.acceptedAt) {
136
- status = "accepted";
137
- }
138
- else {
139
- status = "pending";
140
- }
141
- return Object.assign(Object.assign({}, order), { status });
142
- })
143
- .openapi("Order");
144
- export const CreateOrderSchema = CartSchema.extend({
145
- fulfilmentMethod: fulfilmentMethod.default("delivery"),
146
- payment: z.object({
147
- provider: PaymentProviderSchema,
148
- method: PaymentMethodSchema,
149
- }),
150
- checkoutBaseUrl: z.string().url(),
151
- })
152
- .refine((data) => data.fulfilmentMethod !== "delivery" ||
153
- data.shippingMethodId !== undefined, {
154
- message: "shippingMethodId is required when fulfilmentMethod is 'delivery'",
155
- path: ["shippingMethodId"],
156
- })
157
- .openapi("CreateOrder");
158
- //# sourceMappingURL=order.schema.js.map
1
+ import{z as e}from"@hono/zod-openapi";import{AddressSchema as t}from"../../schemas/address.schema";import{currency as i}from"../../schemas/currency.schema";import{locale as r}from"../../schemas/locales.schema";import{CartItemSchema as a,CartSchema as o}from"../cart/cart.schema";import{FileSchema as p}from"../file/file.schema";import{PaymentMethodSchema as n,PaymentProviderSchema as d,PaymentSchema as c}from"../payment/payment.schema";import{ShippingMethodSchema as l}from"../shipping-method/shipping-method.schema";import{fulfilmentMethod as s}from"./fulfilment.schema";export const OrderStatusSchema=e.enum(["draft","pending","accepted","ready-for-dispatch","dispatched","completed","cancelled"]).openapi({description:"Status of the order",example:"accepted"});export const OrderItemSchema=e.object({translations:e.array(e.object({locale:r.openapi({description:"Locale of the translation",example:"en-US"}),title:e.string().openapi({description:"Title of the ordered product",example:"Premium Watch"}),subtitle:e.string().openapi({description:"Additional details about the ordered item, including modifiers",example:"Color: Silver, Size: Large"})})).openapi({description:"Translations for the order item"}),rawData:a,unitPrice:e.number().min(0).openapi({description:"Price per unit of the item",example:299.99}),image:p.nullable().optional(),totalPrice:e.number().min(0).openapi({description:"Total price for this item (unitPrice × quantity)",example:599.98}),quantity:e.number().min(1).openapi({description:"Number of units ordered",example:2}),productSnapshotId:e.string().cuid()}).openapi("OrderItem");export const OrderSchema=e.object({id:e.string().openapi({description:"Unique identifier for the order",example:"clj1234567890abcdef"}),referenceId:e.string().openapi({description:"External reference ID for the order",example:"ORD-12345"}),status:OrderStatusSchema.optional(),token:e.string().openapi({description:"Security token for order verification",example:"a1b2c3d4e5f6g7h8i9j0"}),expiresAt:e.date().openapi({description:"Expiration date for the order",example:"2023-12-31T23:59:59Z"}),items:e.array(OrderItemSchema).min(1).openapi({description:"Array of items in the order"}),shippingMethod:l.nullable().openapi({description:"Shipping method selected for the order"}),acceptedAt:e.date().nullable().optional().openapi({description:"Date when the order was accepted",example:"2023-06-15T14:30:00Z"}),dispatchedAt:e.date().nullable().optional().openapi({description:"Date when the order was dispatched",example:"2023-06-16T09:15:00Z"}),readyForDispatchAt:e.date().nullable().optional().openapi({description:"Date when the order was ready for dispatch",example:"2023-06-16T09:15:00Z"}),createdAt:e.date().openapi({description:"Date when the order was created",example:"2023-06-15T14:30:00Z"}),completedAt:e.date().nullable().optional().openapi({description:"Date when the order was completed",example:"2023-06-18T11:45:00Z"}),cancelledAt:e.date().nullable().optional().openapi({description:"Date when the order was cancelled",example:"2023-06-14T16:20:00Z"}),shippingAddress:t.nullable().optional(),fulfilmentMethod:s.openapi({description:"Method of order fulfilment (pickup or delivery)",example:"delivery"}),currency:i.openapi({description:"Currency used for the order",example:"USD"}),payment:c}).transform(e=>{let t;return t=e.cancelledAt?"cancelled":e.completedAt?"completed":e.dispatchedAt?"dispatched":e.readyForDispatchAt?"ready-for-dispatch":e.acceptedAt?"accepted":"pending",Object.assign(Object.assign({},e),{status:t})}).openapi("Order");export const CreateOrderSchema=o.extend({fulfilmentMethod:s.default("delivery"),payment:e.object({provider:d,method:n}),checkoutBaseUrl:e.string().url()}).refine(e=>"delivery"!==e.fulfilmentMethod||void 0!==e.shippingMethodId,{message:"shippingMethodId is required when fulfilmentMethod is 'delivery'",path:["shippingMethodId"]}).openapi("CreateOrder");
@@ -7,9 +7,6 @@ declare class OrderService {
7
7
  private readonly paymentOptions;
8
8
  private paymentService;
9
9
  constructor(prisma: PrismaClientType, paymentOptions: PaymentServiceOptions);
10
- /**
11
- * Create a draft order
12
- */
13
10
  createOrder(organizationId: string, user: User, body: z.infer<typeof CreateOrderSchema>): Promise<{
14
11
  redirectUrl: string | undefined;
15
12
  order: {
@@ -113,9 +110,6 @@ declare class OrderService {
113
110
  } | null | undefined;
114
111
  };
115
112
  }>;
116
- /**
117
- * Get a specific order by ID
118
- */
119
113
  getOrder(user: User, organizationId: string, orderId: string): Promise<{
120
114
  status: "pending" | "accepted" | "ready-for-dispatch" | "dispatched" | "completed" | "cancelled";
121
115
  id: string;
@@ -216,9 +210,6 @@ declare class OrderService {
216
210
  deliveryInstructions?: string | null | undefined;
217
211
  } | null | undefined;
218
212
  }>;
219
- /**
220
- * Get a paginated list of orders
221
- */
222
213
  getOrders(organizationId: string, query: {
223
214
  page: number;
224
215
  limit: number;
@@ -333,13 +324,7 @@ declare class OrderService {
333
324
  } | null | undefined;
334
325
  }[];
335
326
  }>;
336
- /**
337
- * Delete an order (soft delete)
338
- */
339
327
  deleteOrder(organizationId: string, orderId: string, userId: string): Promise<void>;
340
- /**
341
- * Update order status
342
- */
343
328
  updateStatus(organizationId: string, orderId: string, operation: OrderStatus): Promise<{
344
329
  status: "pending" | "accepted" | "ready-for-dispatch" | "dispatched" | "completed" | "cancelled";
345
330
  id: string;
@@ -1,306 +1 @@
1
- import { __awaiter } from "tslib";
2
- import { z } from "@hono/zod-openapi";
3
- import { customAlphabet } from "nanoid";
4
- import { HttpException } from "../../core/exceptions/http-exception";
5
- import { OrderSchema, PaginationMetaSchema, } from "../../schemas";
6
- import { transformCartItemToOrderItem } from "../cart/cart.util";
7
- import { PaymentService, } from "../payment/payment.service";
8
- const nanoid = customAlphabet("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ", 6);
9
- class OrderService {
10
- constructor(prisma, paymentOptions) {
11
- this.prisma = prisma;
12
- this.paymentOptions = paymentOptions;
13
- this.paymentService = new PaymentService(prisma, paymentOptions);
14
- }
15
- /**
16
- * Create a draft order
17
- */
18
- createOrder(organizationId, user, body) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- var _a, _b, _c, _d, _e;
21
- const organization = yield this.prisma.organization.findFirst({
22
- where: {
23
- id: organizationId,
24
- },
25
- include: {
26
- configuration: true,
27
- },
28
- });
29
- if (!organization) {
30
- throw new HttpException(404, "Organization not found");
31
- }
32
- const shippingAddress = yield this.prisma.address.findFirst({
33
- where: {
34
- users: {
35
- some: {
36
- id: user.id,
37
- },
38
- },
39
- isDefault: true,
40
- },
41
- });
42
- if (body.fulfilmentMethod === "delivery" && !shippingAddress) {
43
- throw new HttpException(400, "This user does not have a default shipping address");
44
- }
45
- const items = yield Promise.all(body.items.map(transformCartItemToOrderItem(this.prisma)));
46
- const shippingMethod = yield this.prisma.shippingMethod.findFirst({
47
- where: {
48
- id: body.shippingMethodId,
49
- },
50
- include: {
51
- shippingZones: true,
52
- },
53
- });
54
- const shipping = (_b = (_a = shippingMethod === null || shippingMethod === void 0 ? void 0 : shippingMethod.shippingZones[0]) === null || _a === void 0 ? void 0 : _a.price) !== null && _b !== void 0 ? _b : 0;
55
- const subtotal = items.reduce((acc, item) => acc + item.totalPrice, 0);
56
- const total = subtotal + shipping;
57
- // Create the order
58
- const order = yield this.prisma.order.create({
59
- data: Object.assign(Object.assign({
60
- // TODO: add guest order flow
61
- token: nanoid(), referenceId: nanoid(), organization: {
62
- connect: {
63
- id: organizationId,
64
- },
65
- }, fulfilmentMethod: body.fulfilmentMethod, shippingMethod: body.shippingMethodId
66
- ? {
67
- connect: {
68
- id: body.shippingMethodId,
69
- },
70
- }
71
- : undefined, currency: organization.configuration.defaultCurrency,
72
- // TODO: add user IP address
73
- sourceIp: "127.0.0.1", items: {
74
- create: items,
75
- } }, (shippingAddress
76
- ? {
77
- shippingAddress: {
78
- create: Object.assign(Object.assign({}, shippingAddress), { id: undefined }),
79
- },
80
- }
81
- : {})), { user: {
82
- connect: {
83
- id: user.id,
84
- },
85
- }, payment: {
86
- create: {
87
- method: body.payment.method,
88
- provider: body.payment.provider,
89
- shipping: (_d = (_c = shippingMethod === null || shippingMethod === void 0 ? void 0 : shippingMethod.shippingZones[0]) === null || _c === void 0 ? void 0 : _c.price) !== null && _d !== void 0 ? _d : 0,
90
- subtotal,
91
- total,
92
- discount: 0,
93
- currency: organization.configuration.defaultCurrency,
94
- },
95
- } }),
96
- include: {
97
- items: {
98
- include: {
99
- translations: true,
100
- image: true,
101
- },
102
- },
103
- payment: true,
104
- shippingMethod: {
105
- include: {
106
- shippingZones: true,
107
- },
108
- },
109
- },
110
- });
111
- const formattedOrder = OrderSchema.parse(order);
112
- const session = yield this.paymentService.createCheckoutSession(user, formattedOrder, {
113
- locale: "en",
114
- successUrl: `${body.checkoutBaseUrl}/account/orders/${order.id}?clearCart=true`,
115
- cancelUrl: `${body.checkoutBaseUrl}/checkout/shipping-and-payment`,
116
- });
117
- return {
118
- redirectUrl: (_e = session.redirectUrl) !== null && _e !== void 0 ? _e : undefined,
119
- order: OrderSchema.parse(order),
120
- };
121
- });
122
- }
123
- /**
124
- * Get a specific order by ID
125
- */
126
- getOrder(user, organizationId, orderId) {
127
- return __awaiter(this, void 0, void 0, function* () {
128
- const order = yield this.prisma.order.findUnique({
129
- where: {
130
- id: orderId,
131
- organizationId: organizationId,
132
- deletedAt: null,
133
- user: {
134
- id: user.id,
135
- },
136
- },
137
- include: {
138
- items: {
139
- include: {
140
- translations: true,
141
- image: true,
142
- },
143
- },
144
- shippingAddress: true,
145
- shippingMethod: {
146
- include: {
147
- shippingZones: true,
148
- },
149
- },
150
- payment: true,
151
- },
152
- });
153
- if (!order) {
154
- throw new HttpException(404, "Order not found");
155
- }
156
- return OrderSchema.parse(order);
157
- });
158
- }
159
- /**
160
- * Get a paginated list of orders
161
- */
162
- getOrders(organizationId, query) {
163
- return __awaiter(this, void 0, void 0, function* () {
164
- const { page = 1, limit = 10 } = query;
165
- const [list, meta] = yield this.prisma.order
166
- .paginate({
167
- where: {
168
- organizationId: organizationId,
169
- deletedAt: null,
170
- },
171
- include: {
172
- items: {
173
- include: {
174
- translations: true,
175
- image: true,
176
- },
177
- },
178
- shippingAddress: true,
179
- shippingMethod: {
180
- include: {
181
- shippingZones: true,
182
- },
183
- },
184
- payment: true,
185
- },
186
- orderBy: {
187
- createdAt: "desc",
188
- },
189
- })
190
- .withPages({
191
- page,
192
- limit,
193
- });
194
- return {
195
- meta: PaginationMetaSchema.parse(meta),
196
- list: z.array(OrderSchema).parse(list),
197
- };
198
- });
199
- }
200
- /**
201
- * Delete an order (soft delete)
202
- */
203
- deleteOrder(organizationId, orderId, userId) {
204
- return __awaiter(this, void 0, void 0, function* () {
205
- const order = yield this.prisma.order.findUnique({
206
- where: {
207
- id: orderId,
208
- organizationId: organizationId,
209
- deletedAt: null,
210
- },
211
- });
212
- if (!order) {
213
- throw new HttpException(404, "Order not found");
214
- }
215
- yield this.prisma.order.update({
216
- where: {
217
- id: orderId,
218
- organizationId: organizationId,
219
- deletedAt: null,
220
- },
221
- data: {
222
- deletedAt: new Date(),
223
- deletedBy: userId,
224
- },
225
- });
226
- return;
227
- });
228
- }
229
- /**
230
- * Update order status
231
- */
232
- updateStatus(organizationId, orderId, operation) {
233
- return __awaiter(this, void 0, void 0, function* () {
234
- const order = yield this.prisma.order.findUnique({
235
- where: {
236
- id: orderId,
237
- organizationId: organizationId,
238
- deletedAt: null,
239
- },
240
- include: {
241
- items: true,
242
- shippingMethod: {
243
- include: {
244
- shippingZones: true,
245
- },
246
- },
247
- },
248
- });
249
- if (!order) {
250
- throw new HttpException(404, "Order not found");
251
- }
252
- let updateData = {};
253
- switch (operation) {
254
- case "accepted":
255
- updateData = {
256
- acceptedAt: new Date(),
257
- };
258
- break;
259
- case "ready-for-dispatch":
260
- updateData = {
261
- readyForDispatchAt: new Date(),
262
- };
263
- break;
264
- case "dispatched":
265
- updateData = {
266
- dispatchedAt: new Date(),
267
- };
268
- break;
269
- case "completed":
270
- updateData = {
271
- completedAt: new Date(),
272
- };
273
- break;
274
- case "cancelled":
275
- updateData = {
276
- cancelledAt: new Date(),
277
- };
278
- break;
279
- }
280
- const updatedOrder = yield this.prisma.order.update({
281
- where: {
282
- id: orderId,
283
- },
284
- data: updateData,
285
- include: {
286
- items: {
287
- include: {
288
- translations: true,
289
- image: true,
290
- },
291
- },
292
- shippingAddress: true,
293
- shippingMethod: {
294
- include: {
295
- shippingZones: true,
296
- },
297
- },
298
- payment: true,
299
- },
300
- });
301
- return OrderSchema.parse(updatedOrder);
302
- });
303
- }
304
- }
305
- export { OrderService };
306
- //# sourceMappingURL=order.service.js.map
1
+ import{__awaiter as e}from"tslib";import{z as i}from"@hono/zod-openapi";import{customAlphabet as t}from"nanoid";import{HttpException as n}from"../../core/exceptions/http-exception";import{OrderSchema as r,PaginationMetaSchema as d}from"../../schemas";import{transformCartItemToOrderItem as s}from"../cart/cart.util";import{PaymentService as o}from"../payment/payment.service";const a=t("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ",6);class p{constructor(e,i){this.prisma=e,this.paymentOptions=i,this.paymentService=new o(e,i)}createOrder(i,t,d){return e(this,void 0,void 0,function*(){var e,o,p,c,l;const h=yield this.prisma.organization.findFirst({where:{id:i},include:{configuration:!0}});if(!h)throw new n(404,"Organization not found");const u=yield this.prisma.address.findFirst({where:{users:{some:{id:t.id}},isDefault:!0}});if("delivery"===d.fulfilmentMethod&&!u)throw new n(400,"This user does not have a default shipping address");const m=yield Promise.all(d.items.map(s(this.prisma))),g=yield this.prisma.shippingMethod.findFirst({where:{id:d.shippingMethodId},include:{shippingZones:!0}}),f=null!==(o=null===(e=null==g?void 0:g.shippingZones[0])||void 0===e?void 0:e.price)&&void 0!==o?o:0,y=m.reduce((e,i)=>e+i.totalPrice,0),v=y+f,w=yield this.prisma.order.create({data:Object.assign(Object.assign({token:a(),referenceId:a(),organization:{connect:{id:i}},fulfilmentMethod:d.fulfilmentMethod,shippingMethod:d.shippingMethodId?{connect:{id:d.shippingMethodId}}:void 0,currency:h.configuration.defaultCurrency,sourceIp:"127.0.0.1",items:{create:m}},u?{shippingAddress:{create:Object.assign(Object.assign({},u),{id:void 0})}}:{}),{user:{connect:{id:t.id}},payment:{create:{method:d.payment.method,provider:d.payment.provider,shipping:null!==(c=null===(p=null==g?void 0:g.shippingZones[0])||void 0===p?void 0:p.price)&&void 0!==c?c:0,subtotal:y,total:v,discount:0,currency:h.configuration.defaultCurrency}}}),include:{items:{include:{translations:!0,image:!0}},payment:!0,shippingMethod:{include:{shippingZones:!0}}}}),A=r.parse(w);return{redirectUrl:null!==(l=(yield this.paymentService.createCheckoutSession(t,A,{locale:"en",successUrl:`${d.checkoutBaseUrl}/account/orders/${w.id}?clearCart=true`,cancelUrl:`${d.checkoutBaseUrl}/checkout/shipping-and-payment`})).redirectUrl)&&void 0!==l?l:void 0,order:r.parse(w)}})}getOrder(i,t,d){return e(this,void 0,void 0,function*(){const e=yield this.prisma.order.findUnique({where:{id:d,organizationId:t,deletedAt:null,user:{id:i.id}},include:{items:{include:{translations:!0,image:!0}},shippingAddress:!0,shippingMethod:{include:{shippingZones:!0}},payment:!0}});if(!e)throw new n(404,"Order not found");return r.parse(e)})}getOrders(t,n){return e(this,void 0,void 0,function*(){const{page:e=1,limit:s=10}=n,[o,a]=yield this.prisma.order.paginate({where:{organizationId:t,deletedAt:null},include:{items:{include:{translations:!0,image:!0}},shippingAddress:!0,shippingMethod:{include:{shippingZones:!0}},payment:!0},orderBy:{createdAt:"desc"}}).withPages({page:e,limit:s});return{meta:d.parse(a),list:i.array(r).parse(o)}})}deleteOrder(i,t,r){return e(this,void 0,void 0,function*(){if(!(yield this.prisma.order.findUnique({where:{id:t,organizationId:i,deletedAt:null}})))throw new n(404,"Order not found");yield this.prisma.order.update({where:{id:t,organizationId:i,deletedAt:null},data:{deletedAt:new Date,deletedBy:r}})})}updateStatus(i,t,d){return e(this,void 0,void 0,function*(){if(!(yield this.prisma.order.findUnique({where:{id:t,organizationId:i,deletedAt:null},include:{items:!0,shippingMethod:{include:{shippingZones:!0}}}})))throw new n(404,"Order not found");let e={};switch(d){case"accepted":e={acceptedAt:new Date};break;case"ready-for-dispatch":e={readyForDispatchAt:new Date};break;case"dispatched":e={dispatchedAt:new Date};break;case"completed":e={completedAt:new Date};break;case"cancelled":e={cancelledAt:new Date}}const s=yield this.prisma.order.update({where:{id:t},data:e,include:{items:{include:{translations:!0,image:!0}},shippingAddress:!0,shippingMethod:{include:{shippingZones:!0}},payment:!0}});return r.parse(s)})}}export{p as OrderService};
@@ -1,38 +1 @@
1
- import { z } from "@hono/zod-openapi";
2
- import { AddressSchema, CreateAddressSchema, } from "../../schemas/address.schema";
3
- export const RecipientSchema = z
4
- .object({
5
- id: z.string().openapi({
6
- example: "clf9876543210abcdef",
7
- description: "ID of the customer",
8
- }),
9
- firstname: z.string().nullable().optional().openapi({
10
- example: "John Doe",
11
- description: "Name of the customer",
12
- }),
13
- email: z.string().nullable().optional().openapi({
14
- example: "john.doe@example.com",
15
- description: "Email of the customer",
16
- }),
17
- phone: z.string().nullable().optional().openapi({
18
- example: "+1234567890",
19
- description: "Phone number of the customer",
20
- }),
21
- address: AddressSchema.nullable().optional().openapi({
22
- description: "Address of the customer",
23
- }),
24
- createdAt: z.date(),
25
- updatedAt: z.date(),
26
- })
27
- .openapi("Customer");
28
- export const CreateRecipientSchema = RecipientSchema.pick({
29
- firstname: true,
30
- email: true,
31
- phone: true,
32
- })
33
- .extend({
34
- address: CreateAddressSchema,
35
- })
36
- .openapi("Customer");
37
- export const UpdateCustomerSchema = CreateRecipientSchema.partial().openapi("UpdateCustomer");
38
- //# sourceMappingURL=recipient.schema.js.map
1
+ import{z as e}from"@hono/zod-openapi";import{AddressSchema as o,CreateAddressSchema as t}from"../../schemas/address.schema";export const RecipientSchema=e.object({id:e.string().openapi({example:"clf9876543210abcdef",description:"ID of the customer"}),firstname:e.string().nullable().optional().openapi({example:"John Doe",description:"Name of the customer"}),email:e.string().nullable().optional().openapi({example:"john.doe@example.com",description:"Email of the customer"}),phone:e.string().nullable().optional().openapi({example:"+1234567890",description:"Phone number of the customer"}),address:o.nullable().optional().openapi({description:"Address of the customer"}),createdAt:e.date(),updatedAt:e.date()}).openapi("Customer");export const CreateRecipientSchema=RecipientSchema.pick({firstname:!0,email:!0,phone:!0}).extend({address:t}).openapi("Customer");export const UpdateCustomerSchema=CreateRecipientSchema.partial().openapi("UpdateCustomer");