@shophost/rest-api 2.0.34 → 2.0.35

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 (148) hide show
  1. package/package.json +1 -1
  2. package/scripts/minify-dist.mjs +45 -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.js +1 -30
  8. package/src/core/auth/headers.schema.js +1 -22
  9. package/src/core/auth/user.schema.js +1 -30
  10. package/src/core/db/__generated__/client/browser.js +1 -18
  11. package/src/core/db/__generated__/client/client.js +1 -35
  12. package/src/core/db/__generated__/client/commonInputTypes.js +1 -11
  13. package/src/core/db/__generated__/client/enums.js +1 -200
  14. package/src/core/db/__generated__/client/internal/class.js +769 -55
  15. package/src/core/db/__generated__/client/internal/prismaNamespace.js +1 -541
  16. package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js +1 -512
  17. package/src/core/db/__generated__/client/models/Account.js +1 -2
  18. package/src/core/db/__generated__/client/models/Address.js +1 -2
  19. package/src/core/db/__generated__/client/models/Campaign.js +1 -2
  20. package/src/core/db/__generated__/client/models/ClosingTimes.js +1 -2
  21. package/src/core/db/__generated__/client/models/File.js +1 -2
  22. package/src/core/db/__generated__/client/models/Invitation.js +1 -2
  23. package/src/core/db/__generated__/client/models/LegalEntity.js +1 -2
  24. package/src/core/db/__generated__/client/models/Manufacturer.js +1 -2
  25. package/src/core/db/__generated__/client/models/ManufacturerTranslation.js +1 -2
  26. package/src/core/db/__generated__/client/models/Member.js +1 -2
  27. package/src/core/db/__generated__/client/models/Modifier.js +1 -2
  28. package/src/core/db/__generated__/client/models/ModifierGroup.js +1 -2
  29. package/src/core/db/__generated__/client/models/ModifierGroupTranslation.js +1 -2
  30. package/src/core/db/__generated__/client/models/OpeningTimes.js +1 -2
  31. package/src/core/db/__generated__/client/models/Order.js +1 -2
  32. package/src/core/db/__generated__/client/models/OrderItem.js +1 -2
  33. package/src/core/db/__generated__/client/models/OrderItemTranslation.js +1 -2
  34. package/src/core/db/__generated__/client/models/Organization.js +1 -2
  35. package/src/core/db/__generated__/client/models/OrganizationConfiguration.js +1 -2
  36. package/src/core/db/__generated__/client/models/Payment.js +1 -2
  37. package/src/core/db/__generated__/client/models/PaymentSession.js +1 -2
  38. package/src/core/db/__generated__/client/models/Product.js +1 -2
  39. package/src/core/db/__generated__/client/models/ProductCategory.js +1 -2
  40. package/src/core/db/__generated__/client/models/ProductCategoryTranslation.js +1 -2
  41. package/src/core/db/__generated__/client/models/ProductSnapshot.js +1 -2
  42. package/src/core/db/__generated__/client/models/ProductTranslation.js +1 -2
  43. package/src/core/db/__generated__/client/models/Reservation.js +1 -2
  44. package/src/core/db/__generated__/client/models/Session.js +1 -2
  45. package/src/core/db/__generated__/client/models/ShippingMethod.js +1 -2
  46. package/src/core/db/__generated__/client/models/ShippingZone.js +1 -2
  47. package/src/core/db/__generated__/client/models/User.js +1 -2
  48. package/src/core/db/__generated__/client/models/Verification.js +1 -2
  49. package/src/core/db/__generated__/client/models.js +1 -2
  50. package/src/core/db/index.js +1 -2
  51. package/src/core/exceptions/http-exception.js +1 -9
  52. package/src/core/hono/hono.js +1 -123
  53. package/src/core/lib/prisma.js +1 -11
  54. package/src/core/logging/pino.js +1 -5
  55. package/src/core/notifications/email.service.js +1 -116
  56. package/src/core/openapi/openapi.lib.js +1 -26
  57. package/src/core/types/google-maps.types.js +1 -2
  58. package/src/core/utils/currency.util.js +1 -11
  59. package/src/core/utils/env.util.js +1 -8
  60. package/src/core/utils/object.util.js +1 -39
  61. package/src/core/utils/translations.util.js +0 -1
  62. package/src/core/utils/zod.util.js +1 -85
  63. package/src/db.js +1 -3
  64. package/src/features/access/access.handler.js +1 -91
  65. package/src/features/access/access.route.js +1 -220
  66. package/src/features/access/access.schema.js +1 -108
  67. package/src/features/access/access.service.js +1 -294
  68. package/src/features/cart/cart.handler.js +1 -17
  69. package/src/features/cart/cart.route.js +1 -32
  70. package/src/features/cart/cart.schema.js +1 -39
  71. package/src/features/cart/cart.service.js +1 -97
  72. package/src/features/cart/cart.util.js +1 -76
  73. package/src/features/file/file.handler.js +1 -23
  74. package/src/features/file/file.route.js +1 -34
  75. package/src/features/file/file.schema.js +1 -77
  76. package/src/features/file/file.service.js +1 -66
  77. package/src/features/health/health.handler.js +1 -10
  78. package/src/features/health/health.route.js +1 -25
  79. package/src/features/index.js +1 -16
  80. package/src/features/location/location.handler.js +1 -25
  81. package/src/features/location/location.route.js +1 -56
  82. package/src/features/location/location.schema.js +1 -50
  83. package/src/features/location/location.service.js +1 -141
  84. package/src/features/manufacturer/manufacturer.handler.js +1 -53
  85. package/src/features/manufacturer/manufacturer.route.js +1 -97
  86. package/src/features/manufacturer/manufacturer.schema.js +1 -125
  87. package/src/features/manufacturer/manufacturer.service.js +1 -190
  88. package/src/features/order/emails/order-confirmation.email.js +1 -229
  89. package/src/features/order/emails/order-notification.email.js +1 -229
  90. package/src/features/order/fulfilment.schema.js +1 -3
  91. package/src/features/order/order.handler.js +1 -54
  92. package/src/features/order/order.route.js +1 -111
  93. package/src/features/order/order.schema.js +1 -158
  94. package/src/features/order/order.service.js +1 -306
  95. package/src/features/order/recipient.schema.js +1 -38
  96. package/src/features/organization/legal-entity.schema.js +1 -83
  97. package/src/features/organization/organization-configuration.schema.js +1 -115
  98. package/src/features/organization/organization.handler.js +1 -48
  99. package/src/features/organization/organization.route.js +1 -84
  100. package/src/features/organization/organization.schema.js +1 -64
  101. package/src/features/organization/organization.service.js +1 -334
  102. package/src/features/payment/payment.handler.js +1 -16
  103. package/src/features/payment/payment.route.js +1 -22
  104. package/src/features/payment/payment.schema.js +1 -46
  105. package/src/features/payment/payment.service.js +1 -100
  106. package/src/features/payment/stripe.service.js +1 -164
  107. package/src/features/product/product-modifier.schema.js +1 -84
  108. package/src/features/product/product.handler.js +1 -87
  109. package/src/features/product/product.route.js +1 -179
  110. package/src/features/product/product.schema.js +1 -143
  111. package/src/features/product/product.service.js +1 -440
  112. package/src/features/product-category/product-category.handler.js +1 -59
  113. package/src/features/product-category/product-category.route.js +1 -139
  114. package/src/features/product-category/product-category.schema.js +1 -86
  115. package/src/features/product-category/product-category.service.js +1 -220
  116. package/src/features/reservation/emails/reservation-cancellation.email.js +1 -82
  117. package/src/features/reservation/emails/reservation-confirmation.email.js +1 -82
  118. package/src/features/reservation/emails/reservation-notification.email.js +1 -93
  119. package/src/features/reservation/reservation.handler.js +1 -65
  120. package/src/features/reservation/reservation.route.js +1 -167
  121. package/src/features/reservation/reservation.schema.js +1 -51
  122. package/src/features/reservation/reservation.service.js +1 -231
  123. package/src/features/shipping/shipping.handler.js +1 -32
  124. package/src/features/shipping/shipping.route.js +1 -51
  125. package/src/features/shipping/shipping.service.js +1 -96
  126. package/src/features/shipping-method/shipping-method.handler.js +1 -60
  127. package/src/features/shipping-method/shipping-method.route.js +1 -144
  128. package/src/features/shipping-method/shipping-method.schema.js +1 -48
  129. package/src/features/shipping-method/shipping-method.service.js +1 -229
  130. package/src/features/shipping-method/shipping-zone.schema.js +1 -31
  131. package/src/features/webhook/webhook.handler.js +1 -50
  132. package/src/features/webhook/webhook.route.js +1 -33
  133. package/src/index.js +1 -6
  134. package/src/integrations/next.js +1 -82
  135. package/src/schemas/address.schema.js +1 -112
  136. package/src/schemas/currency.schema.js +1 -118
  137. package/src/schemas/error.schema.js +1 -12
  138. package/src/schemas/index.js +1 -29
  139. package/src/schemas/locales.schema.js +1 -238
  140. package/src/schemas/number.schema.js +1 -29
  141. package/src/schemas/pagination.schema.js +1 -54
  142. package/src/schemas/params.schema.js +1 -20
  143. package/src/schemas/queries.schema.js +1 -6
  144. package/src/test/global-setup.js +1 -37
  145. package/src/test/integration/api-fixtures.js +1 -160
  146. package/src/test/integration/seed.js +1 -368
  147. package/src/test/integration/test-helpers.js +1 -154
  148. package/src/test/setup-test-env.js +1 -7
@@ -1,231 +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 { EmailService } from "../../core/notifications/email.service";
6
- import { PaginationMetaSchema, ReservationSchema, } from "../../schemas";
7
- const nanoid = customAlphabet("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ", 6);
8
- class ReservationService {
9
- constructor(prisma, resendApiKey) {
10
- this.prisma = prisma;
11
- this.emailService = new EmailService(resendApiKey);
12
- }
13
- /**
14
- * Create a new reservation
15
- */
16
- createReservation(organizationId, user, body) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- const organization = yield this.prisma.organization.findFirst({
19
- where: {
20
- id: organizationId,
21
- },
22
- });
23
- if (!organization) {
24
- throw new HttpException(404, "Organization not found");
25
- }
26
- // Create the reservation
27
- const reservation = yield this.prisma.reservation.create({
28
- data: Object.assign({ referenceId: nanoid(), firstname: body.firstname, lastname: body.lastname, guests: body.guests, phone: body.phone, date: body.date, organization: {
29
- connect: {
30
- id: organizationId,
31
- },
32
- } }, (user
33
- ? {
34
- user: {
35
- connect: {
36
- id: user.id,
37
- },
38
- },
39
- }
40
- : {})),
41
- include: {
42
- organization: {
43
- include: {
44
- address: true,
45
- configuration: true,
46
- logoFile: true,
47
- members: {
48
- include: {
49
- user: true,
50
- },
51
- },
52
- },
53
- },
54
- user: true,
55
- },
56
- });
57
- for (const member of reservation.organization.members) {
58
- yield this.emailService.sendReservationNotificationEmail(member.user, reservation);
59
- }
60
- return ReservationSchema.parse(reservation);
61
- });
62
- }
63
- /**
64
- * Get a specific reservation by ID
65
- */
66
- getReservation(user, organizationId, reservationId) {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- const reservation = yield this.prisma.reservation.findUnique({
69
- where: {
70
- id: reservationId,
71
- organizationId: organizationId,
72
- user: {
73
- id: user.id,
74
- },
75
- },
76
- });
77
- if (!reservation) {
78
- throw new HttpException(404, "Reservation not found");
79
- }
80
- return ReservationSchema.parse(reservation);
81
- });
82
- }
83
- /**
84
- * Get all reservations for an organization
85
- */
86
- getReservations(organizationId, query) {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- const { page = 1, limit = 10, search } = query;
89
- // Fetch reservations with pagination
90
- const [list, meta] = yield this.prisma.reservation
91
- .paginate({
92
- orderBy: {
93
- createdAt: "desc",
94
- },
95
- where: Object.assign({ organizationId }, (search && {
96
- OR: [
97
- {
98
- firstname: {
99
- contains: search,
100
- mode: "insensitive",
101
- },
102
- },
103
- {
104
- lastname: {
105
- contains: search,
106
- mode: "insensitive",
107
- },
108
- },
109
- {
110
- referenceId: {
111
- contains: search,
112
- mode: "insensitive",
113
- },
114
- },
115
- ],
116
- })),
117
- include: {
118
- user: true,
119
- },
120
- })
121
- .withPages({
122
- page,
123
- limit,
124
- });
125
- return z
126
- .object({
127
- meta: PaginationMetaSchema,
128
- list: z.array(ReservationSchema),
129
- })
130
- .parse({
131
- meta,
132
- list,
133
- });
134
- });
135
- }
136
- /**
137
- * Get all reservations for a user
138
- */
139
- getUserReservations(userId, organizationId) {
140
- return __awaiter(this, void 0, void 0, function* () {
141
- const reservations = yield this.prisma.reservation.findMany({
142
- where: {
143
- organizationId: organizationId,
144
- userId: userId,
145
- },
146
- });
147
- return z.array(ReservationSchema).parse(reservations);
148
- });
149
- }
150
- /**
151
- * Update reservation status
152
- */
153
- updateStatus(organizationId, reservationId, operation) {
154
- return __awaiter(this, void 0, void 0, function* () {
155
- const reservation = yield this.prisma.reservation.findUnique({
156
- where: {
157
- id: reservationId,
158
- organizationId: organizationId,
159
- },
160
- });
161
- if (!reservation) {
162
- throw new HttpException(404, "Reservation not found");
163
- }
164
- let updateData = {};
165
- switch (operation) {
166
- case "accept":
167
- updateData = {
168
- acceptedAt: new Date(),
169
- };
170
- break;
171
- case "cancel":
172
- updateData = {
173
- cancelledAt: new Date(),
174
- };
175
- break;
176
- }
177
- const updatedReservation = yield this.prisma.reservation.update({
178
- where: {
179
- id: reservationId,
180
- },
181
- data: updateData,
182
- include: {
183
- organization: {
184
- include: {
185
- address: true,
186
- configuration: true,
187
- logoFile: true,
188
- members: {
189
- include: {
190
- user: true,
191
- },
192
- },
193
- },
194
- },
195
- user: true,
196
- },
197
- });
198
- if (operation === "cancel") {
199
- yield this.emailService.sendReservationCancellationEmail(updatedReservation);
200
- }
201
- if (operation === "accept") {
202
- yield this.emailService.sendReservationConfirmationEmail(updatedReservation);
203
- }
204
- return ReservationSchema.parse(updatedReservation);
205
- });
206
- }
207
- /**
208
- * Delete a reservation
209
- */
210
- deleteReservation(organizationId, reservationId) {
211
- return __awaiter(this, void 0, void 0, function* () {
212
- const reservation = yield this.prisma.reservation.findUnique({
213
- where: {
214
- id: reservationId,
215
- organizationId: organizationId,
216
- },
217
- });
218
- if (!reservation) {
219
- throw new HttpException(404, "Reservation not found");
220
- }
221
- yield this.prisma.reservation.delete({
222
- where: {
223
- id: reservationId,
224
- },
225
- });
226
- return;
227
- });
228
- }
229
- }
230
- export { ReservationService };
231
- //# sourceMappingURL=reservation.service.js.map
1
+ import{__awaiter as s}from"tslib";import{z as c}from"@hono/zod-openapi";import{customAlphabet as m}from"nanoid";import{HttpException as d}from"../../core/exceptions/http-exception";import{EmailService as l}from"../../core/notifications/email.service";import{PaginationMetaSchema as v,ReservationSchema as o}from"../../schemas";const h=m("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ",6);class f{constructor(t,e){this.prisma=t,this.emailService=new l(e)}createReservation(t,e,i){return s(this,void 0,void 0,function*(){if(!(yield this.prisma.organization.findFirst({where:{id:t}})))throw new d(404,"Organization not found");const r=yield this.prisma.reservation.create({data:Object.assign({referenceId:h(),firstname:i.firstname,lastname:i.lastname,guests:i.guests,phone:i.phone,date:i.date,organization:{connect:{id:t}}},e?{user:{connect:{id:e.id}}}:{}),include:{organization:{include:{address:!0,configuration:!0,logoFile:!0,members:{include:{user:!0}}}},user:!0}});for(const n of r.organization.members)yield this.emailService.sendReservationNotificationEmail(n.user,r);return o.parse(r)})}getReservation(t,e,i){return s(this,void 0,void 0,function*(){const a=yield this.prisma.reservation.findUnique({where:{id:i,organizationId:e,user:{id:t.id}}});if(!a)throw new d(404,"Reservation not found");return o.parse(a)})}getReservations(t,e){return s(this,void 0,void 0,function*(){const{page:i=1,limit:a=10,search:r}=e,[n,u]=yield this.prisma.reservation.paginate({orderBy:{createdAt:"desc"},where:Object.assign({organizationId:t},r&&{OR:[{firstname:{contains:r,mode:"insensitive"}},{lastname:{contains:r,mode:"insensitive"}},{referenceId:{contains:r,mode:"insensitive"}}]}),include:{user:!0}}).withPages({page:i,limit:a});return c.object({meta:v,list:c.array(o)}).parse({meta:u,list:n})})}getUserReservations(t,e){return s(this,void 0,void 0,function*(){const i=yield this.prisma.reservation.findMany({where:{organizationId:e,userId:t}});return c.array(o).parse(i)})}updateStatus(t,e,i){return s(this,void 0,void 0,function*(){if(!(yield this.prisma.reservation.findUnique({where:{id:e,organizationId:t}})))throw new d(404,"Reservation not found");let r={};switch(i){case"accept":r={acceptedAt:new Date};break;case"cancel":r={cancelledAt:new Date};break}const n=yield this.prisma.reservation.update({where:{id:e},data:r,include:{organization:{include:{address:!0,configuration:!0,logoFile:!0,members:{include:{user:!0}}}},user:!0}});return i==="cancel"&&(yield this.emailService.sendReservationCancellationEmail(n)),i==="accept"&&(yield this.emailService.sendReservationConfirmationEmail(n)),o.parse(n)})}deleteReservation(t,e){return s(this,void 0,void 0,function*(){if(!(yield this.prisma.reservation.findUnique({where:{id:e,organizationId:t}})))throw new d(404,"Reservation not found");yield this.prisma.reservation.delete({where:{id:e}})})}}export{f as ReservationService};
@@ -1,32 +1 @@
1
- import { __awaiter } from "tslib";
2
- import { createApiRouter } from "../../core/hono/hono";
3
- import { shippingRoute } from "./shipping.route";
4
- import { ShippingService } from "./shipping.service";
5
- export const buildShippingHandler = (prisma, googleMapsApiKey) => {
6
- const app = createApiRouter();
7
- app.openapi(shippingRoute.createShippingAddress, (c) => __awaiter(void 0, void 0, void 0, function* () {
8
- const auth = c.get("auth");
9
- const body = c.req.valid("json");
10
- const user = yield auth.getCurrentUser();
11
- const service = new ShippingService(prisma, googleMapsApiKey);
12
- const shippingAddress = yield service.createShippingAddress(user.id, body, true);
13
- return c.json(shippingAddress, 201);
14
- }));
15
- app.openapi(shippingRoute.getShippingAddress, (c) => __awaiter(void 0, void 0, void 0, function* () {
16
- const auth = c.get("auth");
17
- const user = yield auth.getCurrentUser();
18
- const service = new ShippingService(prisma, googleMapsApiKey);
19
- const shippingAddress = yield service.findShippingAddress(user.id, true);
20
- return c.json(shippingAddress, 200);
21
- }));
22
- app.openapi(shippingRoute.updateShippingAddress, (c) => __awaiter(void 0, void 0, void 0, function* () {
23
- const auth = c.get("auth");
24
- const body = c.req.valid("json");
25
- const user = yield auth.getCurrentUser();
26
- const service = new ShippingService(prisma, googleMapsApiKey);
27
- const shippingAddress = yield service.updateShippingAddress(user.id, body);
28
- return c.json(shippingAddress, 200);
29
- }));
30
- return app;
31
- };
32
- //# sourceMappingURL=shipping.handler.js.map
1
+ import{__awaiter as u}from"tslib";import{createApiRouter as v}from"../../core/hono/hono";import{shippingRoute as c}from"./shipping.route";import{ShippingService as h}from"./shipping.service";export const buildShippingHandler=(s,d)=>{const t=v();return t.openapi(c.createShippingAddress,e=>u(void 0,void 0,void 0,function*(){const n=e.get("auth"),i=e.req.valid("json"),r=yield n.getCurrentUser(),p=yield new h(s,d).createShippingAddress(r.id,i,!0);return e.json(p,201)})),t.openapi(c.getShippingAddress,e=>u(void 0,void 0,void 0,function*(){const i=yield e.get("auth").getCurrentUser(),o=yield new h(s,d).findShippingAddress(i.id,!0);return e.json(o,200)})),t.openapi(c.updateShippingAddress,e=>u(void 0,void 0,void 0,function*(){const n=e.get("auth"),i=e.req.valid("json"),r=yield n.getCurrentUser(),p=yield new h(s,d).updateShippingAddress(r.id,i);return e.json(p,200)})),t};
@@ -1,51 +1 @@
1
- import { createApiRoute } from "../../core/hono/hono";
2
- import { CreateShippingAddressSchema, ErrorSchema, HeaderSchema, ShippingAddressSchema, UpdateShippingAddressSchema, } from "../../schemas";
3
- const getShippingAddressRoute = createApiRoute({
4
- description: "Get the default shipping address for the user",
5
- headers: HeaderSchema,
6
- method: "GET",
7
- operationId: "getShippingAddress",
8
- path: "/shipping",
9
- responses: {
10
- 200: ShippingAddressSchema.nullable(),
11
- 401: ErrorSchema,
12
- },
13
- summary: "Get Shipping Address",
14
- tags: ["Shipping"],
15
- });
16
- const createShippingAddressRoute = createApiRoute({
17
- body: CreateShippingAddressSchema,
18
- description: "Creates a new shipping address for the user",
19
- headers: HeaderSchema,
20
- method: "POST",
21
- operationId: "createShippingAddress",
22
- path: "/shipping",
23
- responses: {
24
- 201: ShippingAddressSchema,
25
- 400: ErrorSchema,
26
- 401: ErrorSchema,
27
- },
28
- summary: "Create Shipping Address",
29
- tags: ["Shipping"],
30
- });
31
- const updateShippingAddressRoute = createApiRoute({
32
- body: UpdateShippingAddressSchema,
33
- description: "Updates the shipping address for the user",
34
- headers: HeaderSchema,
35
- method: "PUT",
36
- operationId: "updateShippingAddress",
37
- path: "/shipping",
38
- responses: {
39
- 200: ShippingAddressSchema,
40
- 400: ErrorSchema,
41
- 401: ErrorSchema,
42
- },
43
- summary: "Update Shipping Address",
44
- tags: ["Shipping"],
45
- });
46
- export const shippingRoute = {
47
- getShippingAddress: getShippingAddressRoute,
48
- createShippingAddress: createShippingAddressRoute,
49
- updateShippingAddress: updateShippingAddressRoute,
50
- };
51
- //# sourceMappingURL=shipping.route.js.map
1
+ import{createApiRoute as s}from"../../core/hono/hono";import{CreateShippingAddressSchema as d,ErrorSchema as e,HeaderSchema as p,ShippingAddressSchema as i,UpdateShippingAddressSchema as r}from"../../schemas";const t=s({description:"Get the default shipping address for the user",headers:p,method:"GET",operationId:"getShippingAddress",path:"/shipping",responses:{200:i.nullable(),401:e},summary:"Get Shipping Address",tags:["Shipping"]}),h=s({body:d,description:"Creates a new shipping address for the user",headers:p,method:"POST",operationId:"createShippingAddress",path:"/shipping",responses:{201:i,400:e,401:e},summary:"Create Shipping Address",tags:["Shipping"]}),a=s({body:r,description:"Updates the shipping address for the user",headers:p,method:"PUT",operationId:"updateShippingAddress",path:"/shipping",responses:{200:i,400:e,401:e},summary:"Update Shipping Address",tags:["Shipping"]});export const shippingRoute={getShippingAddress:t,createShippingAddress:h,updateShippingAddress:a};
@@ -1,96 +1 @@
1
- import { __awaiter } from "tslib";
2
- import { HttpException } from "../../core/exceptions/http-exception";
3
- import { ShippingAddressSchema, } from "../../schemas";
4
- import { LocationService } from "../location/location.service";
5
- class ShippingService {
6
- constructor(prisma, googleMapsApiKey) {
7
- this.prisma = prisma;
8
- this.locationService = new LocationService(googleMapsApiKey);
9
- }
10
- /**
11
- * Find a shipping method by ID and organization ID
12
- * @throws HttpException with 404 status if shipping method is not found
13
- */
14
- findShippingAddress(userId, isDefault) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- const shippingAddress = yield this.prisma.address.findFirst({
17
- where: {
18
- users: {
19
- some: {
20
- id: userId,
21
- },
22
- },
23
- isDefault,
24
- },
25
- });
26
- if (!shippingAddress) {
27
- return null;
28
- }
29
- return ShippingAddressSchema.parse(shippingAddress);
30
- });
31
- }
32
- /**
33
- * Create a new shipping address for the user
34
- */
35
- createShippingAddress(userId, body, isDefault) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const placeDetails = yield this.locationService.getPlaceDetails(body.placeId);
38
- const shippingMethod = yield this.prisma.address.create({
39
- data: {
40
- firstname: body.firstname,
41
- lastname: body.lastname,
42
- phone: body.phone,
43
- addressLineOne: body.addressLineOne,
44
- addressLineTwo: body.addressLineTwo,
45
- doorNumber: body.doorNumber,
46
- placeId: body.placeId,
47
- deliveryInstructions: body.deliveryInstructions,
48
- city: body.city,
49
- country: body.country,
50
- zipCode: body.zipCode,
51
- createdBy: userId,
52
- latitude: placeDetails.latitude,
53
- longitude: placeDetails.longitude,
54
- isDefault,
55
- users: {
56
- connect: {
57
- id: userId,
58
- },
59
- },
60
- },
61
- });
62
- return ShippingAddressSchema.parse(shippingMethod);
63
- });
64
- }
65
- updateShippingAddress(userId, body) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- const defaultShippingAddress = yield this.findShippingAddress(userId, true);
68
- if (!defaultShippingAddress) {
69
- throw new HttpException(400, "No default shipping address found");
70
- }
71
- const placeDetails = yield this.locationService.getPlaceDetails(body.placeId);
72
- const shippingAddress = yield this.prisma.address.update({
73
- where: { id: defaultShippingAddress.id },
74
- data: {
75
- firstname: body.firstname,
76
- lastname: body.lastname,
77
- phone: body.phone,
78
- addressLineOne: body.addressLineOne,
79
- addressLineTwo: body.addressLineTwo,
80
- doorNumber: body.doorNumber,
81
- placeId: body.placeId,
82
- deliveryInstructions: body.deliveryInstructions,
83
- city: body.city,
84
- country: body.country,
85
- zipCode: body.zipCode,
86
- latitude: placeDetails.latitude,
87
- longitude: placeDetails.longitude,
88
- createdBy: userId,
89
- },
90
- });
91
- return ShippingAddressSchema.parse(shippingAddress);
92
- });
93
- }
94
- }
95
- export { ShippingService };
96
- //# sourceMappingURL=shipping.service.js.map
1
+ import{__awaiter as n}from"tslib";import{HttpException as a}from"../../core/exceptions/http-exception";import{ShippingAddressSchema as d}from"../../schemas";import{LocationService as p}from"../location/location.service";class c{constructor(i,e){this.prisma=i,this.locationService=new p(e)}findShippingAddress(i,e){return n(this,void 0,void 0,function*(){const t=yield this.prisma.address.findFirst({where:{users:{some:{id:i}},isDefault:e}});return t?d.parse(t):null})}createShippingAddress(i,e,t){return n(this,void 0,void 0,function*(){const s=yield this.locationService.getPlaceDetails(e.placeId),r=yield this.prisma.address.create({data:{firstname:e.firstname,lastname:e.lastname,phone:e.phone,addressLineOne:e.addressLineOne,addressLineTwo:e.addressLineTwo,doorNumber:e.doorNumber,placeId:e.placeId,deliveryInstructions:e.deliveryInstructions,city:e.city,country:e.country,zipCode:e.zipCode,createdBy:i,latitude:s.latitude,longitude:s.longitude,isDefault:t,users:{connect:{id:i}}}});return d.parse(r)})}updateShippingAddress(i,e){return n(this,void 0,void 0,function*(){const t=yield this.findShippingAddress(i,!0);if(!t)throw new a(400,"No default shipping address found");const s=yield this.locationService.getPlaceDetails(e.placeId),r=yield this.prisma.address.update({where:{id:t.id},data:{firstname:e.firstname,lastname:e.lastname,phone:e.phone,addressLineOne:e.addressLineOne,addressLineTwo:e.addressLineTwo,doorNumber:e.doorNumber,placeId:e.placeId,deliveryInstructions:e.deliveryInstructions,city:e.city,country:e.country,zipCode:e.zipCode,latitude:s.latitude,longitude:s.longitude,createdBy:i}});return d.parse(r)})}}export{c as ShippingService};
@@ -1,60 +1 @@
1
- import { __awaiter } from "tslib";
2
- import { createApiRouter } from "../../core/hono/hono";
3
- import { shippingMethodRoute } from "./shipping-method.route";
4
- import { ShippingMethodService } from "./shipping-method.service";
5
- export const buildShippingMethodHandler = (prisma) => {
6
- const app = createApiRouter();
7
- app.openapi(shippingMethodRoute.createShippingMethod, (c) => __awaiter(void 0, void 0, void 0, function* () {
8
- const auth = c.get("auth");
9
- const params = c.req.valid("param");
10
- const body = c.req.valid("json");
11
- const user = yield auth.isGranted("create");
12
- const service = new ShippingMethodService(prisma);
13
- const shippingMethod = yield service.createShippingMethod(params.organizationId, user.id, body);
14
- return c.json(shippingMethod, 201);
15
- }));
16
- app.openapi(shippingMethodRoute.getShippingMethod, (c) => __awaiter(void 0, void 0, void 0, function* () {
17
- const auth = c.get("auth");
18
- const params = c.req.valid("param");
19
- yield auth.isGranted("read");
20
- const service = new ShippingMethodService(prisma);
21
- const shippingMethod = yield service.getShippingMethod(params.organizationId, params.id);
22
- return c.json(shippingMethod, 200);
23
- }));
24
- app.openapi(shippingMethodRoute.accessEligibility, (c) => __awaiter(void 0, void 0, void 0, function* () {
25
- const auth = c.get("auth");
26
- const params = c.req.valid("param");
27
- const user = yield auth.getCurrentUser();
28
- const service = new ShippingMethodService(prisma);
29
- const shippingMethods = yield service.accessEligibility(user, params.organizationId);
30
- return c.json(shippingMethods, 200);
31
- }));
32
- app.openapi(shippingMethodRoute.getShippingMethods, (c) => __awaiter(void 0, void 0, void 0, function* () {
33
- const auth = c.get("auth");
34
- const params = c.req.valid("param");
35
- const query = c.req.valid("query");
36
- yield auth.isGranted("read");
37
- const service = new ShippingMethodService(prisma);
38
- const result = yield service.getShippingMethods(params.organizationId, Object.assign({}, query));
39
- return c.json(result, 200);
40
- }));
41
- app.openapi(shippingMethodRoute.updateShippingMethod, (c) => __awaiter(void 0, void 0, void 0, function* () {
42
- const auth = c.get("auth");
43
- const params = c.req.valid("param");
44
- const body = c.req.valid("json");
45
- const user = yield auth.isGranted("update");
46
- const service = new ShippingMethodService(prisma);
47
- const updatedShippingMethod = yield service.updateShippingMethod(params.organizationId, params.id, user.id, body);
48
- return c.json(updatedShippingMethod, 200);
49
- }));
50
- app.openapi(shippingMethodRoute.deleteShippingMethod, (c) => __awaiter(void 0, void 0, void 0, function* () {
51
- const auth = c.get("auth");
52
- const params = c.req.valid("param");
53
- const user = yield auth.isGranted("delete");
54
- const service = new ShippingMethodService(prisma);
55
- yield service.deleteShippingMethod(params.organizationId, params.id, user.id);
56
- return c.body(null, 204);
57
- }));
58
- return app;
59
- };
60
- //# sourceMappingURL=shipping-method.handler.js.map
1
+ import{__awaiter as a}from"tslib";import{createApiRouter as u}from"../../core/hono/hono";import{shippingMethodRoute as s}from"./shipping-method.route";import{ShippingMethodService as p}from"./shipping-method.service";export const buildShippingMethodHandler=r=>{const d=u();return d.openapi(s.createShippingMethod,e=>a(void 0,void 0,void 0,function*(){const t=e.get("auth"),i=e.req.valid("param"),o=e.req.valid("json"),n=yield t.isGranted("create"),c=yield new p(r).createShippingMethod(i.organizationId,n.id,o);return e.json(c,201)})),d.openapi(s.getShippingMethod,e=>a(void 0,void 0,void 0,function*(){const t=e.get("auth"),i=e.req.valid("param");yield t.isGranted("read");const n=yield new p(r).getShippingMethod(i.organizationId,i.id);return e.json(n,200)})),d.openapi(s.accessEligibility,e=>a(void 0,void 0,void 0,function*(){const t=e.get("auth"),i=e.req.valid("param"),o=yield t.getCurrentUser(),h=yield new p(r).accessEligibility(o,i.organizationId);return e.json(h,200)})),d.openapi(s.getShippingMethods,e=>a(void 0,void 0,void 0,function*(){const t=e.get("auth"),i=e.req.valid("param"),o=e.req.valid("query");yield t.isGranted("read");const h=yield new p(r).getShippingMethods(i.organizationId,Object.assign({},o));return e.json(h,200)})),d.openapi(s.updateShippingMethod,e=>a(void 0,void 0,void 0,function*(){const t=e.get("auth"),i=e.req.valid("param"),o=e.req.valid("json"),n=yield t.isGranted("update"),c=yield new p(r).updateShippingMethod(i.organizationId,i.id,n.id,o);return e.json(c,200)})),d.openapi(s.deleteShippingMethod,e=>a(void 0,void 0,void 0,function*(){const t=e.get("auth"),i=e.req.valid("param"),o=yield t.isGranted("delete");return yield new p(r).deleteShippingMethod(i.organizationId,i.id,o.id),e.body(null,204)})),d};
@@ -1,144 +1 @@
1
- import { z } from "@hono/zod-openapi";
2
- import { createApiRoute } from "../../core/hono/hono";
3
- import { CreateShippingMethodSchema, ErrorSchema, HeaderSchema, OrganizationParams, OrganizationWithIdParams, PaginationMetaSchema, PaginationQuerySchema, ShippingMethodSchema, UpdateShippingMethodSchema, } from "../../schemas";
4
- const shippingMethodPathParams = z.object({
5
- id: z.string().openapi({
6
- description: "ID of the shipping method",
7
- example: "clf9876543210abcdef",
8
- param: {
9
- in: "path",
10
- name: "id",
11
- },
12
- }),
13
- organizationId: z.string().openapi({
14
- description: "ID of the organization",
15
- example: "cju0z9k4z0000l1qg5z1z1z1z",
16
- param: {
17
- in: "path",
18
- name: "organizationId",
19
- },
20
- }),
21
- });
22
- const getShippingMethodRoute = createApiRoute({
23
- headers: HeaderSchema,
24
- method: "GET",
25
- operationId: "getShippingMethod",
26
- path: "/:organizationId/shipping-methods/:id",
27
- pathParams: OrganizationWithIdParams,
28
- responses: {
29
- 200: ShippingMethodSchema,
30
- 401: ErrorSchema,
31
- 404: ErrorSchema,
32
- },
33
- summary: "Get Shipping Method",
34
- tags: ["ShippingMethod"],
35
- });
36
- const accessEligibilityRoute = createApiRoute({
37
- description: "Fetches a list of published shipping methods a user can use",
38
- headers: HeaderSchema,
39
- method: "GET",
40
- operationId: "accessEligibility",
41
- path: "/:organizationId/shipping-methods/access/eligibility",
42
- pathParams: OrganizationParams,
43
- responses: {
44
- 200: z.array(ShippingMethodSchema),
45
- },
46
- summary: "Get Eligible Shipping Methods",
47
- tags: ["ShippingMethod"],
48
- });
49
- const getShippingMethodsRoute = createApiRoute({
50
- description: "Fetches a paginated list of shipping methods for an organization",
51
- headers: HeaderSchema,
52
- method: "GET",
53
- operationId: "getShippingMethods",
54
- path: "/:organizationId/shipping-methods",
55
- pathParams: z.object({
56
- organizationId: z.string().openapi({
57
- description: "ID of the organization",
58
- example: "cju0z9k4z0000l1qg5z1z1z1z",
59
- param: {
60
- in: "path",
61
- name: "organizationId",
62
- },
63
- }),
64
- }),
65
- query: PaginationQuerySchema,
66
- responses: {
67
- 200: z.object({
68
- list: z.array(ShippingMethodSchema),
69
- meta: PaginationMetaSchema,
70
- }),
71
- 400: ErrorSchema,
72
- 401: ErrorSchema,
73
- },
74
- summary: "Get Shipping Methods",
75
- tags: ["ShippingMethod"],
76
- });
77
- const createShippingMethodRoute = createApiRoute({
78
- body: CreateShippingMethodSchema,
79
- description: "Creates a new shipping method for an organization",
80
- headers: HeaderSchema,
81
- method: "POST",
82
- operationId: "createShippingMethod",
83
- path: "/:organizationId/shipping-methods",
84
- pathParams: z.object({
85
- organizationId: z.string().openapi({
86
- description: "ID of the organization",
87
- example: "cju0z9k4z0000l1qg5z1z1z1z",
88
- param: {
89
- in: "path",
90
- name: "organizationId",
91
- },
92
- }),
93
- }),
94
- responses: {
95
- 201: ShippingMethodSchema,
96
- 400: ErrorSchema,
97
- 401: ErrorSchema,
98
- 404: ErrorSchema,
99
- },
100
- summary: "Create Shipping Method",
101
- tags: ["ShippingMethod"],
102
- });
103
- const updateShippingMethodRoute = createApiRoute({
104
- body: UpdateShippingMethodSchema,
105
- description: "Updates an existing shipping method",
106
- headers: HeaderSchema,
107
- method: "PUT",
108
- operationId: "updateShippingMethod",
109
- path: "/:organizationId/shipping-methods/:id",
110
- pathParams: shippingMethodPathParams,
111
- responses: {
112
- 200: ShippingMethodSchema,
113
- 400: ErrorSchema,
114
- 401: ErrorSchema,
115
- 404: ErrorSchema,
116
- },
117
- summary: "Update Shipping Method",
118
- tags: ["ShippingMethod"],
119
- });
120
- const deleteShippingMethodRoute = createApiRoute({
121
- description: "Soft deletes a shipping method",
122
- headers: HeaderSchema,
123
- method: "DELETE",
124
- operationId: "deleteShippingMethod",
125
- path: "/:organizationId/shipping-methods/:id",
126
- pathParams: shippingMethodPathParams,
127
- responses: {
128
- 204: null,
129
- 400: ErrorSchema,
130
- 401: ErrorSchema,
131
- 404: ErrorSchema,
132
- },
133
- summary: "Delete Shipping Method",
134
- tags: ["ShippingMethod"],
135
- });
136
- export const shippingMethodRoute = {
137
- getShippingMethod: getShippingMethodRoute,
138
- accessEligibility: accessEligibilityRoute,
139
- getShippingMethods: getShippingMethodsRoute,
140
- createShippingMethod: createShippingMethodRoute,
141
- updateShippingMethod: updateShippingMethodRoute,
142
- deleteShippingMethod: deleteShippingMethodRoute,
143
- };
144
- //# sourceMappingURL=shipping-method.route.js.map
1
+ import{z as e}from"@hono/zod-openapi";import{createApiRoute as t}from"../../core/hono/hono";import{CreateShippingMethodSchema as n,ErrorSchema as i,HeaderSchema as a,OrganizationParams as h,OrganizationWithIdParams as s,PaginationMetaSchema as d,PaginationQuerySchema as r,ShippingMethodSchema as o,UpdateShippingMethodSchema as g}from"../../schemas";const p=e.object({id:e.string().openapi({description:"ID of the shipping method",example:"clf9876543210abcdef",param:{in:"path",name:"id"}}),organizationId:e.string().openapi({description:"ID of the organization",example:"cju0z9k4z0000l1qg5z1z1z1z",param:{in:"path",name:"organizationId"}})}),m=t({headers:a,method:"GET",operationId:"getShippingMethod",path:"/:organizationId/shipping-methods/:id",pathParams:s,responses:{200:o,401:i,404:i},summary:"Get Shipping Method",tags:["ShippingMethod"]}),c=t({description:"Fetches a list of published shipping methods a user can use",headers:a,method:"GET",operationId:"accessEligibility",path:"/:organizationId/shipping-methods/access/eligibility",pathParams:h,responses:{200:e.array(o)},summary:"Get Eligible Shipping Methods",tags:["ShippingMethod"]}),S=t({description:"Fetches a paginated list of shipping methods for an organization",headers:a,method:"GET",operationId:"getShippingMethods",path:"/:organizationId/shipping-methods",pathParams:e.object({organizationId:e.string().openapi({description:"ID of the organization",example:"cju0z9k4z0000l1qg5z1z1z1z",param:{in:"path",name:"organizationId"}})}),query:r,responses:{200:e.object({list:e.array(o),meta:d}),400:i,401:i},summary:"Get Shipping Methods",tags:["ShippingMethod"]}),z=t({body:n,description:"Creates a new shipping method for an organization",headers:a,method:"POST",operationId:"createShippingMethod",path:"/:organizationId/shipping-methods",pathParams:e.object({organizationId:e.string().openapi({description:"ID of the organization",example:"cju0z9k4z0000l1qg5z1z1z1z",param:{in:"path",name:"organizationId"}})}),responses:{201:o,400:i,401:i,404:i},summary:"Create Shipping Method",tags:["ShippingMethod"]}),M=t({body:g,description:"Updates an existing shipping method",headers:a,method:"PUT",operationId:"updateShippingMethod",path:"/:organizationId/shipping-methods/:id",pathParams:p,responses:{200:o,400:i,401:i,404:i},summary:"Update Shipping Method",tags:["ShippingMethod"]}),l=t({description:"Soft deletes a shipping method",headers:a,method:"DELETE",operationId:"deleteShippingMethod",path:"/:organizationId/shipping-methods/:id",pathParams:p,responses:{204:null,400:i,401:i,404:i},summary:"Delete Shipping Method",tags:["ShippingMethod"]});export const shippingMethodRoute={getShippingMethod:m,accessEligibility:c,getShippingMethods:S,createShippingMethod:z,updateShippingMethod:M,deleteShippingMethod:l};