@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,32 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createApiRoute } from "../../core/hono/hono";
|
|
3
|
-
import { CartProductsMappingSchema, CartSchema, ErrorSchema, HeaderSchema, locale, OrganizationParams, } from "../../schemas";
|
|
4
|
-
const getCartDataRoute = createApiRoute({
|
|
5
|
-
body: CartSchema,
|
|
6
|
-
description: "Fetches formatted cart data",
|
|
7
|
-
headers: HeaderSchema,
|
|
8
|
-
method: "POST",
|
|
9
|
-
operationId: "getCartData",
|
|
10
|
-
path: "/:organizationId/cart",
|
|
11
|
-
pathParams: OrganizationParams,
|
|
12
|
-
query: z.object({
|
|
13
|
-
locale: locale.default("en"),
|
|
14
|
-
}),
|
|
15
|
-
responses: {
|
|
16
|
-
200: z.object({
|
|
17
|
-
invalidProductIds: z.array(z.string()),
|
|
18
|
-
products: CartProductsMappingSchema,
|
|
19
|
-
shipping: z.number().optional(),
|
|
20
|
-
subtotal: z.number(),
|
|
21
|
-
total: z.number(),
|
|
22
|
-
}),
|
|
23
|
-
400: ErrorSchema,
|
|
24
|
-
401: ErrorSchema,
|
|
25
|
-
},
|
|
26
|
-
summary: "Get Formatted Cart",
|
|
27
|
-
tags: ["Cart"],
|
|
28
|
-
});
|
|
29
|
-
export const cartRoute = {
|
|
30
|
-
getCartData: getCartDataRoute,
|
|
31
|
-
};
|
|
32
|
-
//# sourceMappingURL=cart.route.js.map
|
|
1
|
+
import{z as t}from"@hono/zod-openapi";import{createApiRoute as r}from"../../core/hono/hono";import{CartProductsMappingSchema as e,CartSchema as o,ErrorSchema as a,HeaderSchema as m,locale as c,OrganizationParams as i}from"../../schemas";const n=r({body:o,description:"Fetches formatted cart data",headers:m,method:"POST",operationId:"getCartData",path:"/:organizationId/cart",pathParams:i,query:t.object({locale:c.default("en")}),responses:{200:t.object({invalidProductIds:t.array(t.string()),products:e,shipping:t.number().optional(),subtotal:t.number(),total:t.number()}),400:a,401:a},summary:"Get Formatted Cart",tags:["Cart"]});export const cartRoute={getCartData:n};
|
|
@@ -1,39 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { LocalizedProductSchema } from "../product/product.schema";
|
|
3
|
-
export const CartProductsMappingSchema = z.record(z.string().openapi({
|
|
4
|
-
example: "clf9876543210abcdef",
|
|
5
|
-
description: "ID of the product in the cart",
|
|
6
|
-
}), LocalizedProductSchema);
|
|
7
|
-
export const CartItemSchema = z
|
|
8
|
-
.object({
|
|
9
|
-
productId: z.string().cuid().openapi({
|
|
10
|
-
example: "clf9876543210abcdef",
|
|
11
|
-
description: "ID of the product in the cart",
|
|
12
|
-
}),
|
|
13
|
-
quantity: z.number().default(1).optional().openapi({
|
|
14
|
-
example: 2,
|
|
15
|
-
description: "Quantity of this item in the cart",
|
|
16
|
-
}),
|
|
17
|
-
modifierGroups: z.array(z.object({
|
|
18
|
-
id: z.string().cuid().openapi({
|
|
19
|
-
example: "clg1234567890abcdef",
|
|
20
|
-
description: "ID of the modifier group",
|
|
21
|
-
}),
|
|
22
|
-
modifiers: z.array(z.object({
|
|
23
|
-
id: z.string().cuid().openapi({
|
|
24
|
-
example: "clh9876543210abcdef",
|
|
25
|
-
description: "ID of the selected modifier",
|
|
26
|
-
}),
|
|
27
|
-
quantity: z.number().default(1).openapi({
|
|
28
|
-
example: 1,
|
|
29
|
-
description: "Quantity of this modifier",
|
|
30
|
-
}),
|
|
31
|
-
})),
|
|
32
|
-
})),
|
|
33
|
-
})
|
|
34
|
-
.openapi("CartItem");
|
|
35
|
-
export const CartSchema = z.object({
|
|
36
|
-
items: z.array(CartItemSchema),
|
|
37
|
-
shippingMethodId: z.string().cuid().optional(),
|
|
38
|
-
});
|
|
39
|
-
//# sourceMappingURL=cart.schema.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{LocalizedProductSchema as t}from"../product/product.schema";export const CartProductsMappingSchema=e.record(e.string().openapi({example:"clf9876543210abcdef",description:"ID of the product in the cart"}),t),CartItemSchema=e.object({productId:e.string().cuid().openapi({example:"clf9876543210abcdef",description:"ID of the product in the cart"}),quantity:e.number().default(1).optional().openapi({example:2,description:"Quantity of this item in the cart"}),modifierGroups:e.array(e.object({id:e.string().cuid().openapi({example:"clg1234567890abcdef",description:"ID of the modifier group"}),modifiers:e.array(e.object({id:e.string().cuid().openapi({example:"clh9876543210abcdef",description:"ID of the selected modifier"}),quantity:e.number().default(1).openapi({example:1,description:"Quantity of this modifier"})}))}))}).openapi("CartItem"),CartSchema=e.object({items:e.array(CartItemSchema),shippingMethodId:e.string().cuid().optional()});
|
|
@@ -1,97 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { flattenTranslationData } from "../../core/utils/zod.util";
|
|
3
|
-
import { LocalizedProductSchema, } from "../../schemas";
|
|
4
|
-
class CartService {
|
|
5
|
-
constructor(prisma) {
|
|
6
|
-
this.prisma = prisma;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Calculate price breakdown for cart items
|
|
10
|
-
*/
|
|
11
|
-
calculatePriceBreakdown(items, products, shippingMethodId) {
|
|
12
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
var _a, _b;
|
|
14
|
-
const shippingMethod = shippingMethodId
|
|
15
|
-
? yield this.prisma.shippingMethod.findUnique({
|
|
16
|
-
where: {
|
|
17
|
-
id: shippingMethodId,
|
|
18
|
-
},
|
|
19
|
-
include: {
|
|
20
|
-
shippingZones: true,
|
|
21
|
-
},
|
|
22
|
-
})
|
|
23
|
-
: null;
|
|
24
|
-
const subtotal = items.reduce((total, item) => {
|
|
25
|
-
var _a, _b;
|
|
26
|
-
const product = products.find((p) => p.id === item.productId);
|
|
27
|
-
if (!product)
|
|
28
|
-
return total;
|
|
29
|
-
const price = (_b = (_a = product.discountedBasePrice) !== null && _a !== void 0 ? _a : product.basePrice) !== null && _b !== void 0 ? _b : 0;
|
|
30
|
-
return total + price * (item.quantity || 1);
|
|
31
|
-
}, 0);
|
|
32
|
-
const shipping = (_a = shippingMethod === null || shippingMethod === void 0 ? void 0 : shippingMethod.shippingZones[0]) === null || _a === void 0 ? void 0 : _a.price;
|
|
33
|
-
const total = subtotal + (shipping !== null && shipping !== void 0 ? shipping : 0);
|
|
34
|
-
return {
|
|
35
|
-
total,
|
|
36
|
-
subtotal,
|
|
37
|
-
shipping: (_b = shippingMethod === null || shippingMethod === void 0 ? void 0 : shippingMethod.shippingZones[0]) === null || _b === void 0 ? void 0 : _b.price,
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Get product mapping for cart items
|
|
43
|
-
* This method takes cart items and returns a mapping of product IDs to localized product data
|
|
44
|
-
*/
|
|
45
|
-
getCartData(organizationId, body, query) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
const { locale } = query;
|
|
48
|
-
const productIds = new Set(body.items.map((item) => item.productId));
|
|
49
|
-
const products = yield this.prisma.product.findMany({
|
|
50
|
-
where: {
|
|
51
|
-
id: { in: Array.from(productIds) },
|
|
52
|
-
organizationId,
|
|
53
|
-
deletedAt: null,
|
|
54
|
-
publishedAt: {
|
|
55
|
-
not: null,
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
include: {
|
|
59
|
-
translations: true,
|
|
60
|
-
images: true,
|
|
61
|
-
categories: {
|
|
62
|
-
include: {
|
|
63
|
-
translations: {
|
|
64
|
-
where: {
|
|
65
|
-
locale,
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
modifierGroups: {
|
|
71
|
-
include: {
|
|
72
|
-
translations: {
|
|
73
|
-
where: {
|
|
74
|
-
locale,
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
modifiers: true,
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
const invalidProductIds = body.items
|
|
83
|
-
.filter((item) => {
|
|
84
|
-
const product = products.find((p) => p.id === item.productId);
|
|
85
|
-
return !product;
|
|
86
|
-
})
|
|
87
|
-
.map((item) => item.productId);
|
|
88
|
-
const paymentBreakdown = yield this.calculatePriceBreakdown(body.items, products, body.shippingMethodId);
|
|
89
|
-
return Object.assign(Object.assign({}, paymentBreakdown), { invalidProductIds, products: products.reduce((acc, product) => {
|
|
90
|
-
acc[product.id] = LocalizedProductSchema.parse(flattenTranslationData(product));
|
|
91
|
-
return acc;
|
|
92
|
-
}, {}) });
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
export { CartService };
|
|
97
|
-
//# sourceMappingURL=cart.service.js.map
|
|
1
|
+
import{__awaiter as m}from"tslib";import{flattenTranslationData as g}from"../../core/utils/zod.util";import{LocalizedProductSchema as w}from"../../schemas";class I{constructor(o){this.prisma=o}calculatePriceBreakdown(o,e,c){return m(this,void 0,void 0,function*(){var r,d;const i=c?yield this.prisma.shippingMethod.findUnique({where:{id:c},include:{shippingZones:!0}}):null,u=o.reduce((n,a)=>{var l,p;const h=e.find(f=>f.id===a.productId);if(!h)return n;const v=(p=(l=h.discountedBasePrice)!==null&&l!==void 0?l:h.basePrice)!==null&&p!==void 0?p:0;return n+v*(a.quantity||1)},0),s=(r=i?.shippingZones[0])===null||r===void 0?void 0:r.price;return{total:u+(s??0),subtotal:u,shipping:(d=i?.shippingZones[0])===null||d===void 0?void 0:d.price}})}getCartData(o,e,c){return m(this,void 0,void 0,function*(){const{locale:r}=c,d=new Set(e.items.map(t=>t.productId)),i=yield this.prisma.product.findMany({where:{id:{in:Array.from(d)},organizationId:o,deletedAt:null,publishedAt:{not:null}},include:{translations:!0,images:!0,categories:{include:{translations:{where:{locale:r}}}},modifierGroups:{include:{translations:{where:{locale:r}},modifiers:!0}}}}),u=e.items.filter(t=>!i.find(a=>a.id===t.productId)).map(t=>t.productId),s=yield this.calculatePriceBreakdown(e.items,i,e.shippingMethodId);return Object.assign(Object.assign({},s),{invalidProductIds:u,products:i.reduce((t,n)=>(t[n.id]=w.parse(g(n)),t),{})})})}}export{I as CartService};
|
|
@@ -1,76 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export const transformCartItemToOrderItem = (prisma) => (item) => __awaiter(void 0, void 0, void 0, function* () {
|
|
3
|
-
// Fetch the product with all necessary relations
|
|
4
|
-
const product = yield prisma.product.findUnique({
|
|
5
|
-
where: { id: item.productId },
|
|
6
|
-
include: {
|
|
7
|
-
translations: true,
|
|
8
|
-
modifierGroups: {
|
|
9
|
-
include: {
|
|
10
|
-
translations: true,
|
|
11
|
-
modifiers: true,
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
images: true,
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
if (!product) {
|
|
18
|
-
throw new Error(`Product with ID ${item.productId} not found`);
|
|
19
|
-
}
|
|
20
|
-
const image = product.images[0];
|
|
21
|
-
// Calculate the unit price (base price + modifiers)
|
|
22
|
-
let unitPrice = product.basePrice;
|
|
23
|
-
// Generate translations with title from product and subtitle from modifiers
|
|
24
|
-
const translations = product.translations.map((translation) => {
|
|
25
|
-
// Find all selected modifiers for this product
|
|
26
|
-
const modifierSelections = [];
|
|
27
|
-
// Process each modifier group
|
|
28
|
-
item.modifierGroups.forEach((cartModifierGroup) => {
|
|
29
|
-
var _a;
|
|
30
|
-
// Find the corresponding product modifier group
|
|
31
|
-
const productModifierGroup = product.modifierGroups.find((group) => group.id === cartModifierGroup.id);
|
|
32
|
-
if (productModifierGroup) {
|
|
33
|
-
// Get the translation for this modifier group
|
|
34
|
-
const groupTranslation = productModifierGroup.translations.find((t) => t.locale === translation.locale);
|
|
35
|
-
// Process each selected modifier
|
|
36
|
-
const modifierTexts = [];
|
|
37
|
-
cartModifierGroup.modifiers.forEach((cartModifier) => {
|
|
38
|
-
// Find the corresponding product modifier
|
|
39
|
-
const productModifier = productModifierGroup.modifiers.find((mod) => mod.id === cartModifier.id);
|
|
40
|
-
if (productModifier) {
|
|
41
|
-
// Add the modifier price to the unit price
|
|
42
|
-
unitPrice += productModifier.price * cartModifier.quantity;
|
|
43
|
-
// Add the modifier text
|
|
44
|
-
modifierTexts.push(`${productModifier.title}${cartModifier.quantity > 1 ? ` (${cartModifier.quantity}x)` : ""}`);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
// Add the group and its modifiers to the selections
|
|
48
|
-
if (modifierTexts.length > 0) {
|
|
49
|
-
modifierSelections.push(`${(groupTranslation === null || groupTranslation === void 0 ? void 0 : groupTranslation.title) || ((_a = productModifierGroup.translations[0]) === null || _a === void 0 ? void 0 : _a.title) || ""}: ${modifierTexts.join(", ")}`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
// Create the subtitle from modifier selections
|
|
54
|
-
const subtitle = modifierSelections.join(", ");
|
|
55
|
-
return {
|
|
56
|
-
locale: translation.locale,
|
|
57
|
-
title: translation.title || "",
|
|
58
|
-
subtitle: subtitle || "",
|
|
59
|
-
};
|
|
60
|
-
});
|
|
61
|
-
// Calculate the total price based on quantity
|
|
62
|
-
const quantity = item.quantity || 1;
|
|
63
|
-
const totalPrice = unitPrice * quantity;
|
|
64
|
-
return {
|
|
65
|
-
translations: {
|
|
66
|
-
create: translations,
|
|
67
|
-
},
|
|
68
|
-
unitPrice,
|
|
69
|
-
totalPrice,
|
|
70
|
-
quantity,
|
|
71
|
-
rawData: item,
|
|
72
|
-
imageId: image === null || image === void 0 ? void 0 : image.id,
|
|
73
|
-
productSnapshotId: product.latestSnapshotId,
|
|
74
|
-
};
|
|
75
|
-
});
|
|
76
|
-
//# sourceMappingURL=cart.util.js.map
|
|
1
|
+
import{__awaiter as q}from"tslib";export const transformCartItemToOrderItem=m=>o=>q(void 0,void 0,void 0,function*(){const t=yield m.product.findUnique({where:{id:o.productId},include:{translations:!0,modifierGroups:{include:{translations:!0,modifiers:!0}},images:!0}});if(!t)throw new Error(`Product with ID ${o.productId} not found`);const e=t.images[0];let s=t.basePrice;const h=t.translations.map(d=>{const f=[];o.modifierGroups.forEach(p=>{var a;const r=t.modifierGroups.find(n=>n.id===p.id);if(r){const n=r.translations.find(i=>i.locale===d.locale),u=[];p.modifiers.forEach(i=>{const l=r.modifiers.find(g=>g.id===i.id);l&&(s+=l.price*i.quantity,u.push(`${l.title}${i.quantity>1?` (${i.quantity}x)`:""}`))}),u.length>0&&f.push(`${n?.title||((a=r.translations[0])===null||a===void 0?void 0:a.title)||""}: ${u.join(", ")}`)}});const I=f.join(", ");return{locale:d.locale,title:d.title||"",subtitle:I||""}}),c=o.quantity||1,v=s*c;return{translations:{create:h},unitPrice:s,totalPrice:v,quantity:c,rawData:o,imageId:e?.id,productSnapshotId:t.latestSnapshotId}});
|
|
@@ -1,23 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createApiRouter } from "../../core/hono/hono";
|
|
3
|
-
import { fileRoute } from "./file.route";
|
|
4
|
-
import { FileService } from "./file.service";
|
|
5
|
-
export const buildFileHandler = (prisma) => {
|
|
6
|
-
const app = createApiRouter();
|
|
7
|
-
app.openapi(fileRoute.getVercelToken, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
-
const body = c.req.valid("json");
|
|
9
|
-
const service = new FileService(prisma);
|
|
10
|
-
const tokenResponse = yield service.getVercelToken(body, c.req.raw);
|
|
11
|
-
return c.json(tokenResponse, 200);
|
|
12
|
-
}));
|
|
13
|
-
app.openapi(fileRoute.createTemporaryFile, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
-
const body = c.req.valid("json");
|
|
15
|
-
const auth = c.get("auth");
|
|
16
|
-
const user = yield auth.getCurrentUser();
|
|
17
|
-
const service = new FileService(prisma);
|
|
18
|
-
const file = yield service.createTemporaryFile(user.id, body);
|
|
19
|
-
return c.json(file, 201);
|
|
20
|
-
}));
|
|
21
|
-
return app;
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=file.handler.js.map
|
|
1
|
+
import{__awaiter as n}from"tslib";import{createApiRouter as l}from"../../core/hono/hono";import{fileRoute as s}from"./file.route";import{FileService as c}from"./file.service";export const buildFileHandler=i=>{const o=l();return o.openapi(s.getVercelToken,e=>n(void 0,void 0,void 0,function*(){const r=e.req.valid("json"),t=yield new c(i).getVercelToken(r,e.req.raw);return e.json(t,200)})),o.openapi(s.createTemporaryFile,e=>n(void 0,void 0,void 0,function*(){const r=e.req.valid("json"),t=yield e.get("auth").getCurrentUser(),d=yield new c(i).createTemporaryFile(t.id,r);return e.json(d,201)})),o};
|
|
@@ -1,34 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { CreateTemporaryFileSchema, FileSchema, GetVercelTokenBody, GetVercelTokenResponse, HeaderSchema, } from "../../schemas";
|
|
3
|
-
const createTemporaryFileRoute = createApiRoute({
|
|
4
|
-
body: CreateTemporaryFileSchema,
|
|
5
|
-
description: "Creates a temporary file record and returns its ID",
|
|
6
|
-
headers: HeaderSchema,
|
|
7
|
-
method: "POST",
|
|
8
|
-
operationId: "createTemporaryFile",
|
|
9
|
-
path: "/files",
|
|
10
|
-
responses: {
|
|
11
|
-
201: FileSchema,
|
|
12
|
-
},
|
|
13
|
-
summary: "Create Temporary File",
|
|
14
|
-
tags: ["File"],
|
|
15
|
-
});
|
|
16
|
-
const getVercelTokenRoute = createApiRoute({
|
|
17
|
-
body: GetVercelTokenBody,
|
|
18
|
-
description: "Returns a Vercel token",
|
|
19
|
-
headers: HeaderSchema,
|
|
20
|
-
method: "POST",
|
|
21
|
-
operationId: "getVercelToken",
|
|
22
|
-
path: "/files/token/vercel",
|
|
23
|
-
responses: {
|
|
24
|
-
200: GetVercelTokenResponse,
|
|
25
|
-
204: null,
|
|
26
|
-
},
|
|
27
|
-
summary: "Get Vercel Token",
|
|
28
|
-
tags: ["File"],
|
|
29
|
-
});
|
|
30
|
-
export const fileRoute = {
|
|
31
|
-
createTemporaryFile: createTemporaryFileRoute,
|
|
32
|
-
getVercelToken: getVercelTokenRoute,
|
|
33
|
-
};
|
|
34
|
-
//# sourceMappingURL=file.route.js.map
|
|
1
|
+
import{createApiRoute as e}from"../../core/hono/hono";import{CreateTemporaryFileSchema as o,FileSchema as t,GetVercelTokenBody as a,GetVercelTokenResponse as s,HeaderSchema as r}from"../../schemas";const i=e({body:o,description:"Creates a temporary file record and returns its ID",headers:r,method:"POST",operationId:"createTemporaryFile",path:"/files",responses:{201:t},summary:"Create Temporary File",tags:["File"]}),l=e({body:a,description:"Returns a Vercel token",headers:r,method:"POST",operationId:"getVercelToken",path:"/files/token/vercel",responses:{200:s,204:null},summary:"Get Vercel Token",tags:["File"]});export const fileRoute={createTemporaryFile:i,getVercelToken:l};
|
|
@@ -1,77 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
const GenerateClientTokenEventSchema = z.object({
|
|
3
|
-
type: z.literal("blob.generate-client-token"),
|
|
4
|
-
payload: z.object({
|
|
5
|
-
pathname: z.string(),
|
|
6
|
-
callbackUrl: z.string(),
|
|
7
|
-
multipart: z.boolean(),
|
|
8
|
-
clientPayload: z.string().nullable(),
|
|
9
|
-
}),
|
|
10
|
-
});
|
|
11
|
-
// Schema for UploadCompletedEvent
|
|
12
|
-
const UploadCompletedEventSchema = z.object({
|
|
13
|
-
type: z.literal("blob.upload-completed"),
|
|
14
|
-
payload: z.object({
|
|
15
|
-
// Replace z.any() with an appropriate schema for PutBlobResult if available
|
|
16
|
-
blob: z.any(),
|
|
17
|
-
tokenPayload: z.string().nullable().optional(),
|
|
18
|
-
}),
|
|
19
|
-
});
|
|
20
|
-
// Discriminated union schema for HandleUploadBody
|
|
21
|
-
export const GetVercelTokenBody = z.discriminatedUnion("type", [
|
|
22
|
-
GenerateClientTokenEventSchema,
|
|
23
|
-
UploadCompletedEventSchema,
|
|
24
|
-
]);
|
|
25
|
-
export const GetVercelTokenResponse = z.discriminatedUnion("type", [
|
|
26
|
-
z.object({
|
|
27
|
-
type: z.literal("blob.generate-client-token"),
|
|
28
|
-
clientToken: z.string(),
|
|
29
|
-
}),
|
|
30
|
-
z.object({
|
|
31
|
-
type: z.literal("blob.upload-completed"),
|
|
32
|
-
response: z.literal("ok"),
|
|
33
|
-
}),
|
|
34
|
-
]);
|
|
35
|
-
export const CreateTemporaryFileSchema = z.object({
|
|
36
|
-
mimeType: z.string().min(1, "MIME type is required").openapi({
|
|
37
|
-
example: "image/png",
|
|
38
|
-
description: "MIME type of the file",
|
|
39
|
-
}),
|
|
40
|
-
size: z.number().min(1, "Size is required").openapi({
|
|
41
|
-
example: 1024,
|
|
42
|
-
description: "Size of the file in bytes",
|
|
43
|
-
}),
|
|
44
|
-
filename: z.string().min(1, "Filename is required").openapi({
|
|
45
|
-
example: "example.png",
|
|
46
|
-
description: "Name of the file",
|
|
47
|
-
}),
|
|
48
|
-
organizationId: z.string().optional().openapi({
|
|
49
|
-
example: "clm1234567890abcdef",
|
|
50
|
-
description: "ID of the organization",
|
|
51
|
-
}),
|
|
52
|
-
});
|
|
53
|
-
export const FileSchema = z
|
|
54
|
-
.object({
|
|
55
|
-
id: z.string().min(1, "ID is required").openapi({
|
|
56
|
-
example: "clf9876543210abcdef",
|
|
57
|
-
description: "ID of the file",
|
|
58
|
-
}),
|
|
59
|
-
url: z.string().min(1, "Path is required").openapi({
|
|
60
|
-
example: "/path/to/file",
|
|
61
|
-
description: "Path of the file",
|
|
62
|
-
}),
|
|
63
|
-
mimeType: z.string().min(1, "MIME type is required").openapi({
|
|
64
|
-
example: "image/png",
|
|
65
|
-
description: "MIME type of the file",
|
|
66
|
-
}),
|
|
67
|
-
size: z.number().min(1, "Size is required").openapi({
|
|
68
|
-
example: 1024,
|
|
69
|
-
description: "Size of the file in bytes",
|
|
70
|
-
}),
|
|
71
|
-
filename: z.string().min(1, "Filename is required").openapi({
|
|
72
|
-
example: "example.png",
|
|
73
|
-
description: "Name of the file",
|
|
74
|
-
}),
|
|
75
|
-
})
|
|
76
|
-
.openapi("UploadedFile");
|
|
77
|
-
//# sourceMappingURL=file.schema.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";const i=e.object({type:e.literal("blob.generate-client-token"),payload:e.object({pathname:e.string(),callbackUrl:e.string(),multipart:e.boolean(),clientPayload:e.string().nullable()})}),t=e.object({type:e.literal("blob.upload-completed"),payload:e.object({blob:e.any(),tokenPayload:e.string().nullable().optional()})});export const GetVercelTokenBody=e.discriminatedUnion("type",[i,t]),GetVercelTokenResponse=e.discriminatedUnion("type",[e.object({type:e.literal("blob.generate-client-token"),clientToken:e.string()}),e.object({type:e.literal("blob.upload-completed"),response:e.literal("ok")})]),CreateTemporaryFileSchema=e.object({mimeType:e.string().min(1,"MIME type is required").openapi({example:"image/png",description:"MIME type of the file"}),size:e.number().min(1,"Size is required").openapi({example:1024,description:"Size of the file in bytes"}),filename:e.string().min(1,"Filename is required").openapi({example:"example.png",description:"Name of the file"}),organizationId:e.string().optional().openapi({example:"clm1234567890abcdef",description:"ID of the organization"})}),FileSchema=e.object({id:e.string().min(1,"ID is required").openapi({example:"clf9876543210abcdef",description:"ID of the file"}),url:e.string().min(1,"Path is required").openapi({example:"/path/to/file",description:"Path of the file"}),mimeType:e.string().min(1,"MIME type is required").openapi({example:"image/png",description:"MIME type of the file"}),size:e.number().min(1,"Size is required").openapi({example:1024,description:"Size of the file in bytes"}),filename:e.string().min(1,"Filename is required").openapi({example:"example.png",description:"Name of the file"})}).openapi("UploadedFile");
|
|
@@ -1,66 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { handleUpload } from "@vercel/blob/client";
|
|
3
|
-
import { logger } from "../../core/logging/pino";
|
|
4
|
-
import { FileSchema, GetVercelTokenResponse, } from "../../schemas";
|
|
5
|
-
class FileService {
|
|
6
|
-
constructor(prisma) {
|
|
7
|
-
this.prisma = prisma;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Get Vercel token for file upload
|
|
11
|
-
*/
|
|
12
|
-
getVercelToken(body, request) {
|
|
13
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
const jsonResponse = yield handleUpload({
|
|
15
|
-
body: body,
|
|
16
|
-
request,
|
|
17
|
-
onBeforeGenerateToken: () => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
if (body.type !== "blob.generate-client-token") {
|
|
19
|
-
throw new Error("Invalid type");
|
|
20
|
-
}
|
|
21
|
-
if (!body.payload.clientPayload) {
|
|
22
|
-
throw new Error("clientPayload is required");
|
|
23
|
-
}
|
|
24
|
-
yield request.auth.getCurrentUser();
|
|
25
|
-
return {
|
|
26
|
-
addRandomSuffix: true,
|
|
27
|
-
allowedContentTypes: ["image/jpeg", "image/png", "image/gif"],
|
|
28
|
-
tokenPayload: body.payload.clientPayload,
|
|
29
|
-
};
|
|
30
|
-
}),
|
|
31
|
-
onUploadCompleted: (_a) => __awaiter(this, [_a], void 0, function* ({ blob, tokenPayload }) {
|
|
32
|
-
logger.info({ blob, tokenPayload }, "blob upload completed");
|
|
33
|
-
if (!tokenPayload) {
|
|
34
|
-
throw new Error("tokenPayload is required");
|
|
35
|
-
}
|
|
36
|
-
const { fileId } = JSON.parse(tokenPayload);
|
|
37
|
-
yield this.prisma.file.update({
|
|
38
|
-
where: {
|
|
39
|
-
id: fileId,
|
|
40
|
-
},
|
|
41
|
-
data: {
|
|
42
|
-
filename: blob.pathname,
|
|
43
|
-
url: blob.url,
|
|
44
|
-
mimeType: blob.contentType,
|
|
45
|
-
status: "completed",
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
}),
|
|
49
|
-
});
|
|
50
|
-
return GetVercelTokenResponse.parse(jsonResponse);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Create a temporary file record
|
|
55
|
-
*/
|
|
56
|
-
createTemporaryFile(userId, body) {
|
|
57
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
const file = yield this.prisma.file.create({
|
|
59
|
-
data: Object.assign(Object.assign({}, body), { url: "-", createdBy: userId }),
|
|
60
|
-
});
|
|
61
|
-
return FileSchema.parse(file);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
export { FileService };
|
|
66
|
-
//# sourceMappingURL=file.service.js.map
|
|
1
|
+
import{__awaiter as i}from"tslib";import{handleUpload as d}from"@vercel/blob/client";import{logger as s}from"../../core/logging/pino";import{FileSchema as p,GetVercelTokenResponse as c}from"../../schemas";class m{constructor(e){this.prisma=e}getVercelToken(e,r){return i(this,void 0,void 0,function*(){const o=yield d({body:e,request:r,onBeforeGenerateToken:()=>i(this,void 0,void 0,function*(){if(e.type!=="blob.generate-client-token")throw new Error("Invalid type");if(!e.payload.clientPayload)throw new Error("clientPayload is required");return yield r.auth.getCurrentUser(),{addRandomSuffix:!0,allowedContentTypes:["image/jpeg","image/png","image/gif"],tokenPayload:e.payload.clientPayload}}),onUploadCompleted:n=>i(this,[n],void 0,function*({blob:t,tokenPayload:a}){if(s.info({blob:t,tokenPayload:a},"blob upload completed"),!a)throw new Error("tokenPayload is required");const{fileId:l}=JSON.parse(a);yield this.prisma.file.update({where:{id:l},data:{filename:t.pathname,url:t.url,mimeType:t.contentType,status:"completed"}})})});return c.parse(o)})}createTemporaryFile(e,r){return i(this,void 0,void 0,function*(){const o=yield this.prisma.file.create({data:Object.assign(Object.assign({},r),{url:"-",createdBy:e})});return p.parse(o)})}}export{m as FileService};
|
|
@@ -1,10 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { healthRoute } from "./health.route";
|
|
3
|
-
export const buildHealthHandler = () => {
|
|
4
|
-
const app = createApiRouter();
|
|
5
|
-
app.openapi(healthRoute.ping, (c) => {
|
|
6
|
-
return c.json({ ok: true }, 200);
|
|
7
|
-
});
|
|
8
|
-
return app;
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=health.handler.js.map
|
|
1
|
+
import{createApiRouter as e}from"../../core/hono/hono";import{healthRoute as o}from"./health.route";export const buildHealthHandler=()=>{const r=e();return r.openapi(o.ping,t=>t.json({ok:!0},200)),r};
|
|
@@ -1,25 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createApiRoute } from "../../core/hono/hono";
|
|
3
|
-
import { ErrorSchema, HeaderSchema } from "../../schemas";
|
|
4
|
-
const pingRoute = createApiRoute({
|
|
5
|
-
description: "Pings the relevancy score service to check its availability",
|
|
6
|
-
headers: HeaderSchema,
|
|
7
|
-
method: "GET",
|
|
8
|
-
operationId: "ping",
|
|
9
|
-
path: "/ping",
|
|
10
|
-
responses: {
|
|
11
|
-
200: z.object({
|
|
12
|
-
ok: z.boolean().openapi({
|
|
13
|
-
description: "Indicates if the service is available",
|
|
14
|
-
example: true,
|
|
15
|
-
}),
|
|
16
|
-
}),
|
|
17
|
-
500: ErrorSchema,
|
|
18
|
-
},
|
|
19
|
-
summary: "Ping",
|
|
20
|
-
tags: ["Health"],
|
|
21
|
-
});
|
|
22
|
-
export const healthRoute = {
|
|
23
|
-
ping: pingRoute,
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=health.route.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{createApiRoute as i}from"../../core/hono/hono";import{ErrorSchema as o,HeaderSchema as t}from"../../schemas";const r=i({description:"Pings the relevancy score service to check its availability",headers:t,method:"GET",operationId:"ping",path:"/ping",responses:{200:e.object({ok:e.boolean().openapi({description:"Indicates if the service is available",example:!0})}),500:o},summary:"Ping",tags:["Health"]});export const healthRoute={ping:r};
|
package/src/features/index.js
CHANGED
|
@@ -1,16 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { buildCartHandler } from "./cart/cart.handler";
|
|
3
|
-
export { buildFileHandler } from "./file/file.handler";
|
|
4
|
-
export { buildHealthHandler } from "./health/health.handler";
|
|
5
|
-
export { buildLocationHandler } from "./location/location.handler";
|
|
6
|
-
export { buildManufacturerHandler } from "./manufacturer/manufacturer.handler";
|
|
7
|
-
export { buildOrderHandler } from "./order/order.handler";
|
|
8
|
-
export { buildOrganizationHandler } from "./organization/organization.handler";
|
|
9
|
-
export { buildPaymentHandler } from "./payment/payment.handler";
|
|
10
|
-
export { buildProductCategoryHandler } from "./product-category/product-category.handler";
|
|
11
|
-
export { buildProductHandler } from "./product/product.handler";
|
|
12
|
-
export { buildReservationHandler } from "./reservation/reservation.handler";
|
|
13
|
-
export { buildShippingHandler } from "./shipping/shipping.handler";
|
|
14
|
-
export { buildShippingMethodHandler } from "./shipping-method/shipping-method.handler";
|
|
15
|
-
export { buildWebhookHandler } from "./webhook/webhook.handler";
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export{buildAccessHandler}from"./access/access.handler";export{buildCartHandler}from"./cart/cart.handler";export{buildFileHandler}from"./file/file.handler";export{buildHealthHandler}from"./health/health.handler";export{buildLocationHandler}from"./location/location.handler";export{buildManufacturerHandler}from"./manufacturer/manufacturer.handler";export{buildOrderHandler}from"./order/order.handler";export{buildOrganizationHandler}from"./organization/organization.handler";export{buildPaymentHandler}from"./payment/payment.handler";export{buildProductCategoryHandler}from"./product-category/product-category.handler";export{buildProductHandler}from"./product/product.handler";export{buildReservationHandler}from"./reservation/reservation.handler";export{buildShippingHandler}from"./shipping/shipping.handler";export{buildShippingMethodHandler}from"./shipping-method/shipping-method.handler";export{buildWebhookHandler}from"./webhook/webhook.handler";
|
|
@@ -1,25 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createApiRouter } from "../../core/hono/hono";
|
|
3
|
-
import { locationRoute } from "./location.route";
|
|
4
|
-
import { LocationService } from "./location.service";
|
|
5
|
-
export const buildLocationHandler = (options) => {
|
|
6
|
-
const app = createApiRouter();
|
|
7
|
-
app.openapi(locationRoute.getPredictions, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
-
const auth = c.get("auth");
|
|
9
|
-
const query = c.req.valid("query");
|
|
10
|
-
yield auth.getCurrentUser();
|
|
11
|
-
const service = new LocationService(options.google.key);
|
|
12
|
-
const predictions = yield service.getPredictions(query.query, query.radius);
|
|
13
|
-
return c.json(predictions, 200);
|
|
14
|
-
}));
|
|
15
|
-
app.openapi(locationRoute.getPlaceDetails, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
const auth = c.get("auth");
|
|
17
|
-
const params = c.req.valid("param");
|
|
18
|
-
yield auth.getCurrentUser();
|
|
19
|
-
const service = new LocationService(options.google.key);
|
|
20
|
-
const placeDetails = yield service.getPlaceDetails(params.placeId);
|
|
21
|
-
return c.json(placeDetails, 200);
|
|
22
|
-
}));
|
|
23
|
-
return app;
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=location.handler.js.map
|
|
1
|
+
import{__awaiter as a}from"tslib";import{createApiRouter as l}from"../../core/hono/hono";import{locationRoute as s}from"./location.route";import{LocationService as c}from"./location.service";export const buildLocationHandler=n=>{const o=l();return o.openapi(s.getPredictions,e=>a(void 0,void 0,void 0,function*(){const r=e.get("auth"),t=e.req.valid("query");yield r.getCurrentUser();const i=yield new c(n.google.key).getPredictions(t.query,t.radius);return e.json(i,200)})),o.openapi(s.getPlaceDetails,e=>a(void 0,void 0,void 0,function*(){const r=e.get("auth"),t=e.req.valid("param");yield r.getCurrentUser();const i=yield new c(n.google.key).getPlaceDetails(t.placeId);return e.json(i,200)})),o};
|
|
@@ -1,56 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createApiRoute } from "../../core/hono/hono";
|
|
3
|
-
import { ErrorSchema, HeaderSchema, PlaceDetailsSchema, PlaceSchema, } from "../../schemas";
|
|
4
|
-
const getPredictionsRoute = createApiRoute({
|
|
5
|
-
description: "Returns a list of places for autocompletion based on a search query",
|
|
6
|
-
headers: HeaderSchema,
|
|
7
|
-
method: "GET",
|
|
8
|
-
operationId: "getPredictions",
|
|
9
|
-
path: "/places/prediction",
|
|
10
|
-
query: z.object({
|
|
11
|
-
query: z.string().openapi({
|
|
12
|
-
description: "Search query",
|
|
13
|
-
example: "123 Main St",
|
|
14
|
-
}),
|
|
15
|
-
radius: z.coerce.number().default(10000).openapi({
|
|
16
|
-
description: "Search radius in meters",
|
|
17
|
-
example: 10000,
|
|
18
|
-
}),
|
|
19
|
-
}),
|
|
20
|
-
responses: {
|
|
21
|
-
200: z.array(PlaceSchema),
|
|
22
|
-
400: ErrorSchema,
|
|
23
|
-
401: ErrorSchema,
|
|
24
|
-
},
|
|
25
|
-
summary: "Get Places Predictions",
|
|
26
|
-
tags: ["Location"],
|
|
27
|
-
});
|
|
28
|
-
const getPlaceDetailsRoute = createApiRoute({
|
|
29
|
-
description: "Returns details for a specific place based on its placeId",
|
|
30
|
-
headers: HeaderSchema,
|
|
31
|
-
method: "GET",
|
|
32
|
-
operationId: "getPlaceDetails",
|
|
33
|
-
path: "/places/:placeId",
|
|
34
|
-
pathParams: z.object({
|
|
35
|
-
placeId: z.string().openapi({
|
|
36
|
-
description: "The Google Place ID for the address",
|
|
37
|
-
example: "ChIJN1t_tKlj4AR4GeTYWZ7frY",
|
|
38
|
-
param: {
|
|
39
|
-
in: "path",
|
|
40
|
-
name: "placeId",
|
|
41
|
-
},
|
|
42
|
-
}),
|
|
43
|
-
}),
|
|
44
|
-
responses: {
|
|
45
|
-
200: PlaceDetailsSchema,
|
|
46
|
-
400: ErrorSchema,
|
|
47
|
-
401: ErrorSchema,
|
|
48
|
-
},
|
|
49
|
-
summary: "Get Place Details",
|
|
50
|
-
tags: ["Location"],
|
|
51
|
-
});
|
|
52
|
-
export const locationRoute = {
|
|
53
|
-
getPredictions: getPredictionsRoute,
|
|
54
|
-
getPlaceDetails: getPlaceDetailsRoute,
|
|
55
|
-
};
|
|
56
|
-
//# sourceMappingURL=location.route.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{createApiRoute as t}from"../../core/hono/hono";import{ErrorSchema as a,HeaderSchema as o,PlaceDetailsSchema as r,PlaceSchema as i}from"../../schemas";const s=t({description:"Returns a list of places for autocompletion based on a search query",headers:o,method:"GET",operationId:"getPredictions",path:"/places/prediction",query:e.object({query:e.string().openapi({description:"Search query",example:"123 Main St"}),radius:e.coerce.number().default(1e4).openapi({description:"Search radius in meters",example:1e4})}),responses:{200:e.array(i),400:a,401:a},summary:"Get Places Predictions",tags:["Location"]}),c=t({description:"Returns details for a specific place based on its placeId",headers:o,method:"GET",operationId:"getPlaceDetails",path:"/places/:placeId",pathParams:e.object({placeId:e.string().openapi({description:"The Google Place ID for the address",example:"ChIJN1t_tKlj4AR4GeTYWZ7frY",param:{in:"path",name:"placeId"}})}),responses:{200:r,400:a,401:a},summary:"Get Place Details",tags:["Location"]});export const locationRoute={getPredictions:s,getPlaceDetails:c};
|