@shophost/rest-api 2.0.33 → 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.
- package/package.json +1 -1
- package/scripts/minify-dist.mjs +45 -0
- package/src/app.js +1 -53
- package/src/core/auth/auth.schema.js +1 -41
- package/src/core/auth/auth.util.js +1 -44
- package/src/core/auth/better-auth.lib.js +1 -100
- package/src/core/auth/generate-password-hash.util.js +1 -30
- package/src/core/auth/headers.schema.js +1 -22
- package/src/core/auth/user.schema.js +1 -30
- package/src/core/db/__generated__/client/browser.js +1 -18
- package/src/core/db/__generated__/client/client.js +1 -35
- package/src/core/db/__generated__/client/commonInputTypes.js +1 -11
- package/src/core/db/__generated__/client/enums.js +1 -200
- package/src/core/db/__generated__/client/internal/class.js +769 -55
- package/src/core/db/__generated__/client/internal/prismaNamespace.js +1 -541
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js +1 -512
- package/src/core/db/__generated__/client/models/Account.js +1 -2
- package/src/core/db/__generated__/client/models/Address.js +1 -2
- package/src/core/db/__generated__/client/models/Campaign.js +1 -2
- package/src/core/db/__generated__/client/models/ClosingTimes.js +1 -2
- package/src/core/db/__generated__/client/models/File.js +1 -2
- package/src/core/db/__generated__/client/models/Invitation.js +1 -2
- package/src/core/db/__generated__/client/models/LegalEntity.js +1 -2
- package/src/core/db/__generated__/client/models/Manufacturer.js +1 -2
- package/src/core/db/__generated__/client/models/ManufacturerTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/Member.js +1 -2
- package/src/core/db/__generated__/client/models/Modifier.js +1 -2
- package/src/core/db/__generated__/client/models/ModifierGroup.js +1 -2
- package/src/core/db/__generated__/client/models/ModifierGroupTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/OpeningTimes.js +1 -2
- package/src/core/db/__generated__/client/models/Order.js +1 -2
- package/src/core/db/__generated__/client/models/OrderItem.js +1 -2
- package/src/core/db/__generated__/client/models/OrderItemTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/Organization.js +1 -2
- package/src/core/db/__generated__/client/models/OrganizationConfiguration.js +1 -2
- package/src/core/db/__generated__/client/models/Payment.js +1 -2
- package/src/core/db/__generated__/client/models/PaymentSession.js +1 -2
- package/src/core/db/__generated__/client/models/Product.js +1 -2
- package/src/core/db/__generated__/client/models/ProductCategory.js +1 -2
- package/src/core/db/__generated__/client/models/ProductCategoryTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/ProductSnapshot.js +1 -2
- package/src/core/db/__generated__/client/models/ProductTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/Reservation.js +1 -2
- package/src/core/db/__generated__/client/models/Session.js +1 -2
- package/src/core/db/__generated__/client/models/ShippingMethod.js +1 -2
- package/src/core/db/__generated__/client/models/ShippingZone.js +1 -2
- package/src/core/db/__generated__/client/models/User.js +1 -2
- package/src/core/db/__generated__/client/models/Verification.js +1 -2
- package/src/core/db/__generated__/client/models.js +1 -2
- package/src/core/db/index.js +1 -2
- package/src/core/exceptions/http-exception.js +1 -9
- package/src/core/hono/hono.js +1 -123
- package/src/core/lib/prisma.js +1 -11
- package/src/core/logging/pino.js +1 -5
- package/src/core/notifications/email.service.js +1 -116
- package/src/core/openapi/openapi.lib.js +1 -26
- package/src/core/types/google-maps.types.js +1 -2
- package/src/core/utils/currency.util.js +1 -11
- package/src/core/utils/env.util.js +1 -8
- package/src/core/utils/object.util.js +1 -39
- package/src/core/utils/translations.util.js +0 -1
- package/src/core/utils/zod.util.js +1 -85
- package/src/db.js +1 -3
- package/src/features/access/access.handler.js +1 -91
- package/src/features/access/access.route.js +1 -220
- package/src/features/access/access.schema.js +1 -108
- package/src/features/access/access.service.js +1 -294
- package/src/features/cart/cart.handler.js +1 -17
- package/src/features/cart/cart.route.js +1 -32
- package/src/features/cart/cart.schema.js +1 -39
- package/src/features/cart/cart.service.js +1 -97
- package/src/features/cart/cart.util.js +1 -76
- package/src/features/file/file.handler.js +1 -23
- package/src/features/file/file.route.js +1 -34
- package/src/features/file/file.schema.js +1 -77
- package/src/features/file/file.service.js +1 -66
- package/src/features/health/health.handler.js +1 -10
- package/src/features/health/health.route.js +1 -25
- package/src/features/index.js +1 -16
- package/src/features/location/location.handler.js +1 -25
- package/src/features/location/location.route.js +1 -56
- package/src/features/location/location.schema.js +1 -50
- package/src/features/location/location.service.js +1 -141
- package/src/features/manufacturer/manufacturer.handler.js +1 -53
- package/src/features/manufacturer/manufacturer.route.js +1 -97
- package/src/features/manufacturer/manufacturer.schema.js +1 -125
- package/src/features/manufacturer/manufacturer.service.js +1 -190
- package/src/features/order/emails/order-confirmation.email.js +1 -229
- package/src/features/order/emails/order-notification.email.js +1 -229
- package/src/features/order/fulfilment.schema.js +1 -3
- package/src/features/order/order.handler.js +1 -54
- package/src/features/order/order.route.js +1 -111
- package/src/features/order/order.schema.js +1 -158
- package/src/features/order/order.service.js +1 -306
- package/src/features/order/recipient.schema.js +1 -38
- package/src/features/organization/legal-entity.schema.js +1 -83
- package/src/features/organization/organization-configuration.schema.js +1 -115
- package/src/features/organization/organization.handler.js +1 -48
- package/src/features/organization/organization.route.js +1 -84
- package/src/features/organization/organization.schema.js +1 -64
- package/src/features/organization/organization.service.js +1 -334
- package/src/features/payment/payment.handler.js +1 -16
- package/src/features/payment/payment.route.js +1 -22
- package/src/features/payment/payment.schema.js +1 -46
- package/src/features/payment/payment.service.js +1 -100
- package/src/features/payment/stripe.service.js +1 -164
- package/src/features/product/product-modifier.schema.js +1 -84
- package/src/features/product/product.handler.js +1 -87
- package/src/features/product/product.route.js +1 -179
- package/src/features/product/product.schema.js +1 -143
- package/src/features/product/product.service.js +1 -440
- package/src/features/product-category/product-category.handler.js +1 -59
- package/src/features/product-category/product-category.route.js +1 -139
- package/src/features/product-category/product-category.schema.js +1 -86
- package/src/features/product-category/product-category.service.js +1 -220
- package/src/features/reservation/emails/reservation-cancellation.email.js +1 -82
- package/src/features/reservation/emails/reservation-confirmation.email.js +1 -82
- package/src/features/reservation/emails/reservation-notification.email.js +1 -93
- package/src/features/reservation/reservation.handler.js +1 -65
- package/src/features/reservation/reservation.route.js +1 -167
- package/src/features/reservation/reservation.schema.js +1 -51
- package/src/features/reservation/reservation.service.js +1 -231
- package/src/features/shipping/shipping.handler.js +1 -32
- package/src/features/shipping/shipping.route.js +1 -51
- package/src/features/shipping/shipping.service.js +1 -96
- package/src/features/shipping-method/shipping-method.handler.js +1 -60
- package/src/features/shipping-method/shipping-method.route.js +1 -144
- package/src/features/shipping-method/shipping-method.schema.js +1 -48
- package/src/features/shipping-method/shipping-method.service.js +1 -229
- package/src/features/shipping-method/shipping-zone.schema.js +1 -31
- package/src/features/webhook/webhook.handler.js +1 -50
- package/src/features/webhook/webhook.route.js +1 -33
- package/src/index.js +1 -6
- package/src/integrations/next.js +1 -82
- package/src/schemas/address.schema.js +1 -112
- package/src/schemas/currency.schema.js +1 -118
- package/src/schemas/error.schema.js +1 -12
- package/src/schemas/index.js +1 -29
- package/src/schemas/locales.schema.js +1 -238
- package/src/schemas/number.schema.js +1 -29
- package/src/schemas/pagination.schema.js +1 -54
- package/src/schemas/params.schema.js +1 -20
- package/src/schemas/queries.schema.js +1 -6
- package/src/test/global-setup.js +1 -37
- package/src/test/integration/api-fixtures.js +1 -160
- package/src/test/integration/seed.js +1 -368
- package/src/test/integration/test-helpers.js +1 -154
- package/src/test/setup-test-env.js +1 -7
|
@@ -1,306 +1 @@
|
|
|
1
|
-
import {
|
|
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 o}from"tslib";import{z as k}from"@hono/zod-openapi";import{customAlphabet as D}from"nanoid";import{HttpException as a}from"../../core/exceptions/http-exception";import{OrderSchema as c,PaginationMetaSchema as U}from"../../schemas";import{transformCartItemToOrderItem as I}from"../cart/cart.util";import{PaymentService as S}from"../payment/payment.service";const v=D("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ",6);class Z{constructor(t,i){this.prisma=t,this.paymentOptions=i,this.paymentService=new S(t,i)}createOrder(t,i,e){return o(this,void 0,void 0,function*(){var n,r,d,p,u;const l=yield this.prisma.organization.findFirst({where:{id:t},include:{configuration:!0}});if(!l)throw new a(404,"Organization not found");const h=yield this.prisma.address.findFirst({where:{users:{some:{id:i.id}},isDefault:!0}});if(e.fulfilmentMethod==="delivery"&&!h)throw new a(400,"This user does not have a default shipping address");const g=yield Promise.all(e.items.map(I(this.prisma))),s=yield this.prisma.shippingMethod.findFirst({where:{id:e.shippingMethodId},include:{shippingZones:!0}}),w=(r=(n=s?.shippingZones[0])===null||n===void 0?void 0:n.price)!==null&&r!==void 0?r:0,f=g.reduce((O,M)=>O+M.totalPrice,0),y=f+w,m=yield this.prisma.order.create({data:Object.assign(Object.assign({token:v(),referenceId:v(),organization:{connect:{id:t}},fulfilmentMethod:e.fulfilmentMethod,shippingMethod:e.shippingMethodId?{connect:{id:e.shippingMethodId}}:void 0,currency:l.configuration.defaultCurrency,sourceIp:"127.0.0.1",items:{create:g}},h?{shippingAddress:{create:Object.assign(Object.assign({},h),{id:void 0})}}:{}),{user:{connect:{id:i.id}},payment:{create:{method:e.payment.method,provider:e.payment.provider,shipping:(p=(d=s?.shippingZones[0])===null||d===void 0?void 0:d.price)!==null&&p!==void 0?p:0,subtotal:f,total:y,discount:0,currency:l.configuration.defaultCurrency}}}),include:{items:{include:{translations:!0,image:!0}},payment:!0,shippingMethod:{include:{shippingZones:!0}}}}),A=c.parse(m);return{redirectUrl:(u=(yield this.paymentService.createCheckoutSession(i,A,{locale:"en",successUrl:`${e.checkoutBaseUrl}/account/orders/${m.id}?clearCart=true`,cancelUrl:`${e.checkoutBaseUrl}/checkout/shipping-and-payment`})).redirectUrl)!==null&&u!==void 0?u:void 0,order:c.parse(m)}})}getOrder(t,i,e){return o(this,void 0,void 0,function*(){const n=yield this.prisma.order.findUnique({where:{id:e,organizationId:i,deletedAt:null,user:{id:t.id}},include:{items:{include:{translations:!0,image:!0}},shippingAddress:!0,shippingMethod:{include:{shippingZones:!0}},payment:!0}});if(!n)throw new a(404,"Order not found");return c.parse(n)})}getOrders(t,i){return o(this,void 0,void 0,function*(){const{page:e=1,limit:n=10}=i,[r,d]=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:n});return{meta:U.parse(d),list:k.array(c).parse(r)}})}deleteOrder(t,i,e){return o(this,void 0,void 0,function*(){if(!(yield this.prisma.order.findUnique({where:{id:i,organizationId:t,deletedAt:null}})))throw new a(404,"Order not found");yield this.prisma.order.update({where:{id:i,organizationId:t,deletedAt:null},data:{deletedAt:new Date,deletedBy:e}})})}updateStatus(t,i,e){return o(this,void 0,void 0,function*(){if(!(yield this.prisma.order.findUnique({where:{id:i,organizationId:t,deletedAt:null},include:{items:!0,shippingMethod:{include:{shippingZones:!0}}}})))throw new a(404,"Order not found");let r={};switch(e){case"accepted":r={acceptedAt:new Date};break;case"ready-for-dispatch":r={readyForDispatchAt:new Date};break;case"dispatched":r={dispatchedAt:new Date};break;case"completed":r={completedAt:new Date};break;case"cancelled":r={cancelledAt:new Date};break}const d=yield this.prisma.order.update({where:{id:i},data:r,include:{items:{include:{translations:!0,image:!0}},shippingAddress:!0,shippingMethod:{include:{shippingZones:!0}},payment:!0}});return c.parse(d)})}}export{Z as OrderService};
|
|
@@ -1,38 +1 @@
|
|
|
1
|
-
import
|
|
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 t,CreateAddressSchema as o}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:t.nullable().optional().openapi({description:"Address of the customer"}),createdAt:e.date(),updatedAt:e.date()}).openapi("Customer"),CreateRecipientSchema=RecipientSchema.pick({firstname:!0,email:!0,phone:!0}).extend({address:o}).openapi("Customer"),UpdateCustomerSchema=CreateRecipientSchema.partial().openapi("UpdateCustomer");
|
|
@@ -1,83 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { AddressSchema, CreateAddressSchema, UpdateAddressSchema, } from "../../schemas/address.schema";
|
|
3
|
-
export const LegalEntitySchema = z
|
|
4
|
-
.object({
|
|
5
|
-
id: z.string().openapi({
|
|
6
|
-
example: "clm1234567890abcdef",
|
|
7
|
-
description: "The unique identifier of the legal entity",
|
|
8
|
-
}),
|
|
9
|
-
name: z.string().openapi({
|
|
10
|
-
example: "Acme Corporation",
|
|
11
|
-
description: "The name of the legal entity",
|
|
12
|
-
}),
|
|
13
|
-
taxId: z.string().min(2).max(20).openapi({
|
|
14
|
-
example: "PL1234567890",
|
|
15
|
-
description: "The TAX ID of the legal entity",
|
|
16
|
-
}),
|
|
17
|
-
email: z.string().email().nullable().openapi({
|
|
18
|
-
example: "contact@acme.com",
|
|
19
|
-
description: "The email of the legal entity",
|
|
20
|
-
format: "email",
|
|
21
|
-
}),
|
|
22
|
-
phone: z.string().nullable().openapi({
|
|
23
|
-
example: "+48123456789",
|
|
24
|
-
description: "The phone number of the legal entity",
|
|
25
|
-
}),
|
|
26
|
-
createdAt: z.date().openapi({
|
|
27
|
-
description: "The date and time when the legal entity was created",
|
|
28
|
-
format: "date-time",
|
|
29
|
-
}),
|
|
30
|
-
address: AddressSchema.required().openapi({
|
|
31
|
-
description: "The address of the legal entity",
|
|
32
|
-
}),
|
|
33
|
-
})
|
|
34
|
-
.openapi("LegalEntity");
|
|
35
|
-
export const CreateLegalEntitySchema = z
|
|
36
|
-
.object({
|
|
37
|
-
name: z.string().min(1, "Name is required").openapi({
|
|
38
|
-
example: "Acme Corporation",
|
|
39
|
-
description: "The name of the legal entity",
|
|
40
|
-
}),
|
|
41
|
-
taxId: z.string().min(2).max(20).openapi({
|
|
42
|
-
example: "PL1234567890",
|
|
43
|
-
description: "The TAX ID of the legal entity",
|
|
44
|
-
}),
|
|
45
|
-
email: z.string().email().optional().openapi({
|
|
46
|
-
example: "contact@acme.com",
|
|
47
|
-
description: "The email of the legal entity",
|
|
48
|
-
format: "email",
|
|
49
|
-
}),
|
|
50
|
-
phone: z.string().optional().openapi({
|
|
51
|
-
example: "+48123456789",
|
|
52
|
-
description: "The phone number of the legal entity",
|
|
53
|
-
}),
|
|
54
|
-
address: CreateAddressSchema.required().openapi({
|
|
55
|
-
description: "The address of the legal entity",
|
|
56
|
-
}),
|
|
57
|
-
})
|
|
58
|
-
.openapi("CreateLegalEntity");
|
|
59
|
-
export const UpdateLegalEntitySchema = z
|
|
60
|
-
.object({
|
|
61
|
-
name: z.string().min(1, "Name is required").optional().openapi({
|
|
62
|
-
example: "Acme Corporation",
|
|
63
|
-
description: "The name of the legal entity",
|
|
64
|
-
}),
|
|
65
|
-
taxId: z.string().min(2).max(20).openapi({
|
|
66
|
-
example: "PL1234567890",
|
|
67
|
-
description: "The TAX ID of the legal entity",
|
|
68
|
-
}),
|
|
69
|
-
email: z.string().email().optional().openapi({
|
|
70
|
-
example: "contact@acme.com",
|
|
71
|
-
description: "The email of the legal entity",
|
|
72
|
-
format: "email",
|
|
73
|
-
}),
|
|
74
|
-
phone: z.string().optional().openapi({
|
|
75
|
-
example: "+48123456789",
|
|
76
|
-
description: "The phone number of the legal entity",
|
|
77
|
-
}),
|
|
78
|
-
address: UpdateAddressSchema.required().openapi({
|
|
79
|
-
description: "The address of the legal entity",
|
|
80
|
-
}),
|
|
81
|
-
})
|
|
82
|
-
.openapi("UpdateLegalEntity");
|
|
83
|
-
//# sourceMappingURL=legal-entity.schema.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{AddressSchema as t,CreateAddressSchema as i,UpdateAddressSchema as a}from"../../schemas/address.schema";export const LegalEntitySchema=e.object({id:e.string().openapi({example:"clm1234567890abcdef",description:"The unique identifier of the legal entity"}),name:e.string().openapi({example:"Acme Corporation",description:"The name of the legal entity"}),taxId:e.string().min(2).max(20).openapi({example:"PL1234567890",description:"The TAX ID of the legal entity"}),email:e.string().email().nullable().openapi({example:"contact@acme.com",description:"The email of the legal entity",format:"email"}),phone:e.string().nullable().openapi({example:"+48123456789",description:"The phone number of the legal entity"}),createdAt:e.date().openapi({description:"The date and time when the legal entity was created",format:"date-time"}),address:t.required().openapi({description:"The address of the legal entity"})}).openapi("LegalEntity"),CreateLegalEntitySchema=e.object({name:e.string().min(1,"Name is required").openapi({example:"Acme Corporation",description:"The name of the legal entity"}),taxId:e.string().min(2).max(20).openapi({example:"PL1234567890",description:"The TAX ID of the legal entity"}),email:e.string().email().optional().openapi({example:"contact@acme.com",description:"The email of the legal entity",format:"email"}),phone:e.string().optional().openapi({example:"+48123456789",description:"The phone number of the legal entity"}),address:i.required().openapi({description:"The address of the legal entity"})}).openapi("CreateLegalEntity"),UpdateLegalEntitySchema=e.object({name:e.string().min(1,"Name is required").optional().openapi({example:"Acme Corporation",description:"The name of the legal entity"}),taxId:e.string().min(2).max(20).openapi({example:"PL1234567890",description:"The TAX ID of the legal entity"}),email:e.string().email().optional().openapi({example:"contact@acme.com",description:"The email of the legal entity",format:"email"}),phone:e.string().optional().openapi({example:"+48123456789",description:"The phone number of the legal entity"}),address:a.required().openapi({description:"The address of the legal entity"})}).openapi("UpdateLegalEntity");
|
|
@@ -1,115 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { currency } from "../../schemas/currency.schema";
|
|
3
|
-
import { locale } from "../../schemas/locales.schema";
|
|
4
|
-
export const TimeScheduleSchema = z
|
|
5
|
-
.object({
|
|
6
|
-
monday: z.string().nullable().openapi({
|
|
7
|
-
example: "09:00",
|
|
8
|
-
description: "Opening time for Monday",
|
|
9
|
-
}),
|
|
10
|
-
tuesday: z.string().nullable().openapi({
|
|
11
|
-
example: "09:00",
|
|
12
|
-
description: "Opening time for Tuesday",
|
|
13
|
-
}),
|
|
14
|
-
wednesday: z.string().nullable().openapi({
|
|
15
|
-
example: "09:00",
|
|
16
|
-
description: "Opening time for Wednesday",
|
|
17
|
-
}),
|
|
18
|
-
thursday: z.string().nullable().openapi({
|
|
19
|
-
example: "09:00",
|
|
20
|
-
description: "Opening time for Thursday",
|
|
21
|
-
}),
|
|
22
|
-
friday: z.string().nullable().openapi({
|
|
23
|
-
example: "09:00",
|
|
24
|
-
description: "Opening time for Friday",
|
|
25
|
-
}),
|
|
26
|
-
saturday: z.string().nullable().openapi({
|
|
27
|
-
example: "09:00",
|
|
28
|
-
description: "Opening time for Saturday",
|
|
29
|
-
}),
|
|
30
|
-
sunday: z.string().nullable().openapi({
|
|
31
|
-
example: "09:00",
|
|
32
|
-
description: "Opening time for Sunday",
|
|
33
|
-
}),
|
|
34
|
-
})
|
|
35
|
-
.openapi("TimeSchedule");
|
|
36
|
-
export const OrganizationConfigurationSchema = z
|
|
37
|
-
.object({
|
|
38
|
-
id: z.string().openapi({
|
|
39
|
-
example: "clm1234567890abcdef",
|
|
40
|
-
description: "Unique identifier for the organization configuration",
|
|
41
|
-
}),
|
|
42
|
-
hostname: z.coerce.string().optional().openapi({
|
|
43
|
-
example: "store.example.com",
|
|
44
|
-
description: "Hostname associated with the organization",
|
|
45
|
-
}),
|
|
46
|
-
countriesShipping: z.array(z.string()).openapi({
|
|
47
|
-
example: ["US", "CA"],
|
|
48
|
-
description: "List of countries where shipping is available",
|
|
49
|
-
}),
|
|
50
|
-
stripeAccountId: z.coerce.string().optional().openapi({
|
|
51
|
-
example: "acct_123456789",
|
|
52
|
-
description: "Stripe account ID associated with the organization",
|
|
53
|
-
}),
|
|
54
|
-
enableHostCheckout: z.boolean().openapi({
|
|
55
|
-
example: true,
|
|
56
|
-
description: "Indicates if host checkout is enabled",
|
|
57
|
-
}),
|
|
58
|
-
enableHostTracking: z.boolean().openapi({
|
|
59
|
-
example: true,
|
|
60
|
-
description: "Indicates if host tracking is enabled",
|
|
61
|
-
}),
|
|
62
|
-
isAcceptingOrders: z.boolean().openapi({
|
|
63
|
-
example: true,
|
|
64
|
-
description: "Indicates if the organization is currently accepting orders",
|
|
65
|
-
}),
|
|
66
|
-
isOpen: z.boolean().default(false).openapi({
|
|
67
|
-
example: true,
|
|
68
|
-
description: "Indicates if the organization is currently open",
|
|
69
|
-
}),
|
|
70
|
-
defaultLocale: locale,
|
|
71
|
-
supportedLocales: z.array(locale).openapi({
|
|
72
|
-
description: "List of supported locales for the organization",
|
|
73
|
-
}),
|
|
74
|
-
openingTimes: TimeScheduleSchema.optional(),
|
|
75
|
-
closingTimes: TimeScheduleSchema.optional(),
|
|
76
|
-
facebookProfile: z.string().nullable().optional().openapi({
|
|
77
|
-
example: "https://www.facebook.com/example",
|
|
78
|
-
description: "Facebook profile URL for the organization",
|
|
79
|
-
}),
|
|
80
|
-
instagramProfile: z.string().nullable().optional().openapi({
|
|
81
|
-
example: "https://www.instagram.com/example",
|
|
82
|
-
description: "Instagram profile URL for the organization",
|
|
83
|
-
}),
|
|
84
|
-
xProfile: z.string().nullable().optional().openapi({
|
|
85
|
-
example: "https://www.x.com/example",
|
|
86
|
-
description: "X profile URL for the organization",
|
|
87
|
-
}),
|
|
88
|
-
defaultCurrency: currency.openapi({
|
|
89
|
-
example: "USD",
|
|
90
|
-
description: "Default currency for the organization",
|
|
91
|
-
}),
|
|
92
|
-
createdAt: z.date().openapi({
|
|
93
|
-
description: "Timestamp when the organization configuration was created",
|
|
94
|
-
}),
|
|
95
|
-
})
|
|
96
|
-
.openapi("OrganizationConfiguration");
|
|
97
|
-
export const UpdateOrganizationConfigurationSchema = OrganizationConfigurationSchema.pick({
|
|
98
|
-
hostname: true,
|
|
99
|
-
countriesShipping: true,
|
|
100
|
-
stripeAccountId: true,
|
|
101
|
-
enableHostCheckout: true,
|
|
102
|
-
enableHostTracking: true,
|
|
103
|
-
isAcceptingOrders: true,
|
|
104
|
-
defaultLocale: true,
|
|
105
|
-
supportedLocales: true,
|
|
106
|
-
defaultCurrency: true,
|
|
107
|
-
openingTimes: true,
|
|
108
|
-
closingTimes: true,
|
|
109
|
-
facebookProfile: true,
|
|
110
|
-
instagramProfile: true,
|
|
111
|
-
xProfile: true,
|
|
112
|
-
})
|
|
113
|
-
.partial()
|
|
114
|
-
.openapi("UpdateOrganizationConfiguration");
|
|
115
|
-
//# sourceMappingURL=organization-configuration.schema.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{currency as o}from"../../schemas/currency.schema";import{locale as i}from"../../schemas/locales.schema";export const TimeScheduleSchema=e.object({monday:e.string().nullable().openapi({example:"09:00",description:"Opening time for Monday"}),tuesday:e.string().nullable().openapi({example:"09:00",description:"Opening time for Tuesday"}),wednesday:e.string().nullable().openapi({example:"09:00",description:"Opening time for Wednesday"}),thursday:e.string().nullable().openapi({example:"09:00",description:"Opening time for Thursday"}),friday:e.string().nullable().openapi({example:"09:00",description:"Opening time for Friday"}),saturday:e.string().nullable().openapi({example:"09:00",description:"Opening time for Saturday"}),sunday:e.string().nullable().openapi({example:"09:00",description:"Opening time for Sunday"})}).openapi("TimeSchedule"),OrganizationConfigurationSchema=e.object({id:e.string().openapi({example:"clm1234567890abcdef",description:"Unique identifier for the organization configuration"}),hostname:e.coerce.string().optional().openapi({example:"store.example.com",description:"Hostname associated with the organization"}),countriesShipping:e.array(e.string()).openapi({example:["US","CA"],description:"List of countries where shipping is available"}),stripeAccountId:e.coerce.string().optional().openapi({example:"acct_123456789",description:"Stripe account ID associated with the organization"}),enableHostCheckout:e.boolean().openapi({example:!0,description:"Indicates if host checkout is enabled"}),enableHostTracking:e.boolean().openapi({example:!0,description:"Indicates if host tracking is enabled"}),isAcceptingOrders:e.boolean().openapi({example:!0,description:"Indicates if the organization is currently accepting orders"}),isOpen:e.boolean().default(!1).openapi({example:!0,description:"Indicates if the organization is currently open"}),defaultLocale:i,supportedLocales:e.array(i).openapi({description:"List of supported locales for the organization"}),openingTimes:TimeScheduleSchema.optional(),closingTimes:TimeScheduleSchema.optional(),facebookProfile:e.string().nullable().optional().openapi({example:"https://www.facebook.com/example",description:"Facebook profile URL for the organization"}),instagramProfile:e.string().nullable().optional().openapi({example:"https://www.instagram.com/example",description:"Instagram profile URL for the organization"}),xProfile:e.string().nullable().optional().openapi({example:"https://www.x.com/example",description:"X profile URL for the organization"}),defaultCurrency:o.openapi({example:"USD",description:"Default currency for the organization"}),createdAt:e.date().openapi({description:"Timestamp when the organization configuration was created"})}).openapi("OrganizationConfiguration"),UpdateOrganizationConfigurationSchema=OrganizationConfigurationSchema.pick({hostname:!0,countriesShipping:!0,stripeAccountId:!0,enableHostCheckout:!0,enableHostTracking:!0,isAcceptingOrders:!0,defaultLocale:!0,supportedLocales:!0,defaultCurrency:!0,openingTimes:!0,closingTimes:!0,facebookProfile:!0,instagramProfile:!0,xProfile:!0}).partial().openapi("UpdateOrganizationConfiguration");
|
|
@@ -1,48 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createApiRouter } from "../../core/hono/hono";
|
|
3
|
-
import { organizationRoute } from "./organization.route";
|
|
4
|
-
import { OrganizationService } from "./organization.service";
|
|
5
|
-
export const buildOrganizationHandler = (prisma, googleMapsApiKey) => {
|
|
6
|
-
const app = createApiRouter();
|
|
7
|
-
app.openapi(organizationRoute.getOrganizations, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
-
const auth = c.get("auth");
|
|
9
|
-
const query = c.req.valid("query");
|
|
10
|
-
const user = yield auth.getCurrentUser();
|
|
11
|
-
const service = new OrganizationService(prisma, googleMapsApiKey);
|
|
12
|
-
const result = yield service.getOrganizations(user.id, query);
|
|
13
|
-
return c.json(result, 200);
|
|
14
|
-
}));
|
|
15
|
-
app.openapi(organizationRoute.getOrganization, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
const params = c.req.valid("param");
|
|
17
|
-
const service = new OrganizationService(prisma, googleMapsApiKey);
|
|
18
|
-
const organization = yield service.getOrganization(params.organizationId);
|
|
19
|
-
return c.json(organization, 200);
|
|
20
|
-
}));
|
|
21
|
-
app.openapi(organizationRoute.createOrganization, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
-
const auth = c.get("auth");
|
|
23
|
-
const body = c.req.valid("json");
|
|
24
|
-
const user = yield auth.getCurrentUser();
|
|
25
|
-
const service = new OrganizationService(prisma, googleMapsApiKey);
|
|
26
|
-
const organization = yield service.createOrganization(user.id, body);
|
|
27
|
-
return c.json(organization, 201);
|
|
28
|
-
}));
|
|
29
|
-
app.openapi(organizationRoute.updateOrganization, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
-
const auth = c.get("auth");
|
|
31
|
-
const params = c.req.valid("param");
|
|
32
|
-
const body = c.req.valid("json");
|
|
33
|
-
const user = yield auth.isGranted("update");
|
|
34
|
-
const service = new OrganizationService(prisma, googleMapsApiKey);
|
|
35
|
-
const organization = yield service.updateOrganization(params.organizationId, user.id, body);
|
|
36
|
-
return c.json(organization, 200);
|
|
37
|
-
}));
|
|
38
|
-
app.openapi(organizationRoute.deleteOrganization, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
-
const auth = c.get("auth");
|
|
40
|
-
const params = c.req.valid("param");
|
|
41
|
-
const user = yield auth.isGranted("delete");
|
|
42
|
-
const service = new OrganizationService(prisma, googleMapsApiKey);
|
|
43
|
-
yield service.deleteOrganization(params.organizationId, user.id);
|
|
44
|
-
return c.body(null, 204);
|
|
45
|
-
}));
|
|
46
|
-
return app;
|
|
47
|
-
};
|
|
48
|
-
//# sourceMappingURL=organization.handler.js.map
|
|
1
|
+
import{__awaiter as d}from"tslib";import{createApiRouter as l}from"../../core/hono/hono";import{organizationRoute as s}from"./organization.route";import{OrganizationService as u}from"./organization.service";export const buildOrganizationHandler=(r,a)=>{const o=l();return o.openapi(s.getOrganizations,n=>d(void 0,void 0,void 0,function*(){const t=n.get("auth"),e=n.req.valid("query"),i=yield t.getCurrentUser(),v=yield new u(r,a).getOrganizations(i.id,e);return n.json(v,200)})),o.openapi(s.getOrganization,n=>d(void 0,void 0,void 0,function*(){const t=n.req.valid("param"),i=yield new u(r,a).getOrganization(t.organizationId);return n.json(i,200)})),o.openapi(s.createOrganization,n=>d(void 0,void 0,void 0,function*(){const t=n.get("auth"),e=n.req.valid("json"),i=yield t.getCurrentUser(),v=yield new u(r,a).createOrganization(i.id,e);return n.json(v,201)})),o.openapi(s.updateOrganization,n=>d(void 0,void 0,void 0,function*(){const t=n.get("auth"),e=n.req.valid("param"),i=n.req.valid("json"),c=yield t.isGranted("update"),g=yield new u(r,a).updateOrganization(e.organizationId,c.id,i);return n.json(g,200)})),o.openapi(s.deleteOrganization,n=>d(void 0,void 0,void 0,function*(){const t=n.get("auth"),e=n.req.valid("param"),i=yield t.isGranted("delete");return yield new u(r,a).deleteOrganization(e.organizationId,i.id),n.body(null,204)})),o};
|