@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,50 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export const PlaceSchema = z
|
|
3
|
-
.object({
|
|
4
|
-
placeId: z.string().openapi({
|
|
5
|
-
example: "ChIJN1t_tKlj4AR4GeTYWZ7frY",
|
|
6
|
-
description: "The Google Place ID for the address",
|
|
7
|
-
}),
|
|
8
|
-
text: z.string().openapi({
|
|
9
|
-
example: "123 Main Street, New York, USA",
|
|
10
|
-
description: "The description of the place",
|
|
11
|
-
}),
|
|
12
|
-
addressLineOne: z.string().openapi({
|
|
13
|
-
example: "123 Main Street",
|
|
14
|
-
description: "The first line of the address",
|
|
15
|
-
}),
|
|
16
|
-
addressLineTwo: z.string().optional().openapi({
|
|
17
|
-
example: "Suite 100",
|
|
18
|
-
description: "The second line of the address",
|
|
19
|
-
}),
|
|
20
|
-
latitude: z.number().optional().openapi({
|
|
21
|
-
example: 40.712776,
|
|
22
|
-
description: "The latitude of the coordinate",
|
|
23
|
-
}),
|
|
24
|
-
longitude: z.number().optional().openapi({
|
|
25
|
-
example: -74.005974,
|
|
26
|
-
description: "The longitude of the coordinate",
|
|
27
|
-
}),
|
|
28
|
-
})
|
|
29
|
-
.openapi("Place");
|
|
30
|
-
export const PlaceDetailsSchema = z
|
|
31
|
-
.object({
|
|
32
|
-
addressLineOne: z.string().openapi({
|
|
33
|
-
example: "123 Main Street",
|
|
34
|
-
description: "The first line of the address",
|
|
35
|
-
}),
|
|
36
|
-
zipCode: z.string().optional().openapi({
|
|
37
|
-
example: "12345",
|
|
38
|
-
description: "The postal code of the address",
|
|
39
|
-
}),
|
|
40
|
-
city: z.string().openapi({
|
|
41
|
-
example: "New York",
|
|
42
|
-
description: "The city of the address",
|
|
43
|
-
}),
|
|
44
|
-
country: z.string().openapi({
|
|
45
|
-
example: "USA",
|
|
46
|
-
description: "The ISO 3166-1 alpha-2 country code",
|
|
47
|
-
}),
|
|
48
|
-
})
|
|
49
|
-
.openapi("PlaceDetails");
|
|
50
|
-
//# sourceMappingURL=location.schema.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";export const PlaceSchema=e.object({placeId:e.string().openapi({example:"ChIJN1t_tKlj4AR4GeTYWZ7frY",description:"The Google Place ID for the address"}),text:e.string().openapi({example:"123 Main Street, New York, USA",description:"The description of the place"}),addressLineOne:e.string().openapi({example:"123 Main Street",description:"The first line of the address"}),addressLineTwo:e.string().optional().openapi({example:"Suite 100",description:"The second line of the address"}),latitude:e.number().optional().openapi({example:40.712776,description:"The latitude of the coordinate"}),longitude:e.number().optional().openapi({example:-74.005974,description:"The longitude of the coordinate"})}).openapi("Place"),PlaceDetailsSchema=e.object({addressLineOne:e.string().openapi({example:"123 Main Street",description:"The first line of the address"}),zipCode:e.string().optional().openapi({example:"12345",description:"The postal code of the address"}),city:e.string().openapi({example:"New York",description:"The city of the address"}),country:e.string().openapi({example:"USA",description:"The ISO 3166-1 alpha-2 country code"})}).openapi("PlaceDetails");
|
|
@@ -1,141 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import axios, { isAxiosError } from "axios";
|
|
3
|
-
import { logger } from "../../core/logging/pino";
|
|
4
|
-
class LocationService {
|
|
5
|
-
constructor(apiKey) {
|
|
6
|
-
this.apiKey = apiKey;
|
|
7
|
-
this.client = axios.create({
|
|
8
|
-
baseURL: "https://places.googleapis.com/v1",
|
|
9
|
-
headers: {
|
|
10
|
-
"Content-Type": "application/json",
|
|
11
|
-
"X-Goog-Api-Key": apiKey,
|
|
12
|
-
},
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Get a list of places for autocompletion based on a search query
|
|
17
|
-
*/
|
|
18
|
-
getPredictions(query, radius) {
|
|
19
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
var _a, _b, _c;
|
|
21
|
-
if (!query || query.trim() === "" || query.length < 3) {
|
|
22
|
-
return [];
|
|
23
|
-
}
|
|
24
|
-
try {
|
|
25
|
-
const { data } = yield this.client.post("/places:autocomplete", {
|
|
26
|
-
input: query,
|
|
27
|
-
locationBias: {
|
|
28
|
-
circle: {
|
|
29
|
-
center: {
|
|
30
|
-
latitude: 37.7937,
|
|
31
|
-
longitude: -122.3965,
|
|
32
|
-
},
|
|
33
|
-
radius: radius || 100000,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
return data.suggestions.map(({ placePrediction }) => ({
|
|
38
|
-
placeId: placePrediction.placeId,
|
|
39
|
-
text: placePrediction.text.text,
|
|
40
|
-
addressLineOne: placePrediction.structuredFormat.mainText.text,
|
|
41
|
-
addressLineTwo: placePrediction.structuredFormat.secondaryText.text,
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
if (isAxiosError(error)) {
|
|
46
|
-
logger.error({
|
|
47
|
-
status: (_a = error.response) === null || _a === void 0 ? void 0 : _a.status,
|
|
48
|
-
statusText: (_b = error.response) === null || _b === void 0 ? void 0 : _b.statusText,
|
|
49
|
-
data: (_c = error.response) === null || _c === void 0 ? void 0 : _c.data,
|
|
50
|
-
query,
|
|
51
|
-
}, "Google Places Autocomplete request failed");
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
logger.error({ err: error, query }, "Unexpected error during Places Autocomplete");
|
|
55
|
-
}
|
|
56
|
-
throw error;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
findDistanceBetweenCoordinates(from, to) {
|
|
61
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
// Helper function to convert degrees to radians
|
|
63
|
-
const toRadians = (degrees) => degrees * (Math.PI / 180);
|
|
64
|
-
// Earth's radius in kilometers
|
|
65
|
-
const earthRadiusKm = 6371;
|
|
66
|
-
// Convert latitude and longitude differences to radians
|
|
67
|
-
const dLat = toRadians(to.latitude - from.latitude);
|
|
68
|
-
const dLon = toRadians(to.longitude - from.longitude);
|
|
69
|
-
// Convert starting coordinates to radians
|
|
70
|
-
const lat1 = toRadians(from.latitude);
|
|
71
|
-
const lat2 = toRadians(to.latitude);
|
|
72
|
-
// Haversine formula
|
|
73
|
-
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
|
|
74
|
-
Math.cos(lat1) * Math.cos(lat2) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
|
|
75
|
-
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
76
|
-
// Calculate the distance
|
|
77
|
-
const distance = earthRadiusKm * c;
|
|
78
|
-
return distance;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
getPlaceDetails(placeId) {
|
|
82
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
var _a, _b, _c;
|
|
84
|
-
let data;
|
|
85
|
-
try {
|
|
86
|
-
const response = yield this.client.get(`/places/${placeId}`, {
|
|
87
|
-
headers: {
|
|
88
|
-
"X-Goog-FieldMask": "addressComponents,adrFormatAddress,formattedAddress,location,plusCode,postalAddress,shortFormattedAddress,types",
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
data = response.data;
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
if (isAxiosError(error)) {
|
|
95
|
-
logger.error({
|
|
96
|
-
status: (_a = error.response) === null || _a === void 0 ? void 0 : _a.status,
|
|
97
|
-
statusText: (_b = error.response) === null || _b === void 0 ? void 0 : _b.statusText,
|
|
98
|
-
data: (_c = error.response) === null || _c === void 0 ? void 0 : _c.data,
|
|
99
|
-
placeId,
|
|
100
|
-
}, "Google Place Details request failed");
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
logger.error({ err: error, placeId }, "Unexpected error during Place Details");
|
|
104
|
-
}
|
|
105
|
-
throw error;
|
|
106
|
-
}
|
|
107
|
-
const result = {
|
|
108
|
-
addressLineOne: "",
|
|
109
|
-
zipCode: "",
|
|
110
|
-
country: "",
|
|
111
|
-
city: "",
|
|
112
|
-
latitude: data.location.latitude,
|
|
113
|
-
longitude: data.location.longitude,
|
|
114
|
-
};
|
|
115
|
-
if (!data.addressComponents) {
|
|
116
|
-
return result;
|
|
117
|
-
}
|
|
118
|
-
for (const component of data.addressComponents) {
|
|
119
|
-
if (component.types.includes("street_number")) {
|
|
120
|
-
result.addressLineOne = component.shortText;
|
|
121
|
-
}
|
|
122
|
-
if (component.types.includes("route")) {
|
|
123
|
-
result.addressLineOne =
|
|
124
|
-
component.shortText + " " + result.addressLineOne;
|
|
125
|
-
}
|
|
126
|
-
if (component.types.includes("postal_code")) {
|
|
127
|
-
result.zipCode = component.shortText;
|
|
128
|
-
}
|
|
129
|
-
if (component.types.includes("country")) {
|
|
130
|
-
result.country = component.shortText;
|
|
131
|
-
}
|
|
132
|
-
if (component.types.includes("locality")) {
|
|
133
|
-
result.city = component.longText;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return result;
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
export { LocationService };
|
|
141
|
-
//# sourceMappingURL=location.service.js.map
|
|
1
|
+
import{__awaiter as d}from"tslib";import h,{isAxiosError as c}from"axios";import{logger as n}from"../../core/logging/pino";class m{constructor(s){this.apiKey=s,this.client=h.create({baseURL:"https://places.googleapis.com/v1",headers:{"Content-Type":"application/json","X-Goog-Api-Key":s}})}getPredictions(s,a){return d(this,void 0,void 0,function*(){var o,i,r;if(!s||s.trim()===""||s.length<3)return[];try{const{data:e}=yield this.client.post("/places:autocomplete",{input:s,locationBias:{circle:{center:{latitude:37.7937,longitude:-122.3965},radius:a||1e5}}});return e.suggestions.map(({placePrediction:t})=>({placeId:t.placeId,text:t.text.text,addressLineOne:t.structuredFormat.mainText.text,addressLineTwo:t.structuredFormat.secondaryText.text}))}catch(e){throw c(e)?n.error({status:(o=e.response)===null||o===void 0?void 0:o.status,statusText:(i=e.response)===null||i===void 0?void 0:i.statusText,data:(r=e.response)===null||r===void 0?void 0:r.data,query:s},"Google Places Autocomplete request failed"):n.error({err:e,query:s},"Unexpected error during Places Autocomplete"),e}})}findDistanceBetweenCoordinates(s,a){return d(this,void 0,void 0,function*(){const o=p=>p*(Math.PI/180),r=o(a.latitude-s.latitude),e=o(a.longitude-s.longitude),t=o(s.latitude),u=o(a.latitude),l=Math.sin(r/2)*Math.sin(r/2)+Math.cos(t)*Math.cos(u)*Math.sin(e/2)*Math.sin(e/2);return 6371*(2*Math.atan2(Math.sqrt(l),Math.sqrt(1-l)))})}getPlaceDetails(s){return d(this,void 0,void 0,function*(){var a,o,i;let r;try{r=(yield this.client.get(`/places/${s}`,{headers:{"X-Goog-FieldMask":"addressComponents,adrFormatAddress,formattedAddress,location,plusCode,postalAddress,shortFormattedAddress,types"}})).data}catch(t){throw c(t)?n.error({status:(a=t.response)===null||a===void 0?void 0:a.status,statusText:(o=t.response)===null||o===void 0?void 0:o.statusText,data:(i=t.response)===null||i===void 0?void 0:i.data,placeId:s},"Google Place Details request failed"):n.error({err:t,placeId:s},"Unexpected error during Place Details"),t}const e={addressLineOne:"",zipCode:"",country:"",city:"",latitude:r.location.latitude,longitude:r.location.longitude};if(!r.addressComponents)return e;for(const t of r.addressComponents)t.types.includes("street_number")&&(e.addressLineOne=t.shortText),t.types.includes("route")&&(e.addressLineOne=t.shortText+" "+e.addressLineOne),t.types.includes("postal_code")&&(e.zipCode=t.shortText),t.types.includes("country")&&(e.country=t.shortText),t.types.includes("locality")&&(e.city=t.longText);return e})}}export{m as LocationService};
|
|
@@ -1,53 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createApiRouter } from "../../core/hono/hono";
|
|
3
|
-
import { manufacturerRoute } from "./manufacturer.route";
|
|
4
|
-
import { ManufacturerService } from "./manufacturer.service";
|
|
5
|
-
export const buildManufacturerHandler = (prisma) => {
|
|
6
|
-
const app = createApiRouter();
|
|
7
|
-
app.openapi(manufacturerRoute.createManufacturer, (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 ManufacturerService(prisma);
|
|
13
|
-
const manufacturer = yield service.createManufacturer(params.organizationId, user.id, body);
|
|
14
|
-
return c.json(manufacturer, 201);
|
|
15
|
-
}));
|
|
16
|
-
app.openapi(manufacturerRoute.getManufacturer, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
-
const auth = c.get("auth");
|
|
18
|
-
const params = c.req.valid("param");
|
|
19
|
-
const query = c.req.valid("query");
|
|
20
|
-
yield auth.isGranted("read");
|
|
21
|
-
const service = new ManufacturerService(prisma);
|
|
22
|
-
const manufacturer = yield service.getManufacturer(params.organizationId, params.id, { locale: query.locale || null });
|
|
23
|
-
return c.json(manufacturer, 200);
|
|
24
|
-
}));
|
|
25
|
-
app.openapi(manufacturerRoute.getManufacturers, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
-
const auth = c.get("auth");
|
|
27
|
-
const params = c.req.valid("param");
|
|
28
|
-
const query = c.req.valid("query");
|
|
29
|
-
yield auth.isGranted("read");
|
|
30
|
-
const service = new ManufacturerService(prisma);
|
|
31
|
-
const result = yield service.getManufacturers(params.organizationId, Object.assign(Object.assign({}, query), { locale: query.locale || null }));
|
|
32
|
-
return c.json(result, 200);
|
|
33
|
-
}));
|
|
34
|
-
app.openapi(manufacturerRoute.updateManufacturer, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
-
const auth = c.get("auth");
|
|
36
|
-
const params = c.req.valid("param");
|
|
37
|
-
const body = c.req.valid("json");
|
|
38
|
-
const user = yield auth.isGranted("update");
|
|
39
|
-
const service = new ManufacturerService(prisma);
|
|
40
|
-
const updatedManufacturer = yield service.updateManufacturer(params.organizationId, params.id, user.id, body);
|
|
41
|
-
return c.json(updatedManufacturer, 200);
|
|
42
|
-
}));
|
|
43
|
-
app.openapi(manufacturerRoute.deleteManufacturer, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
-
const auth = c.get("auth");
|
|
45
|
-
const params = c.req.valid("param");
|
|
46
|
-
const user = yield auth.isGranted("delete");
|
|
47
|
-
const service = new ManufacturerService(prisma);
|
|
48
|
-
yield service.deleteManufacturer(params.organizationId, params.id, user.id);
|
|
49
|
-
return c.body(null, 204);
|
|
50
|
-
}));
|
|
51
|
-
return app;
|
|
52
|
-
};
|
|
53
|
-
//# sourceMappingURL=manufacturer.handler.js.map
|
|
1
|
+
import{__awaiter as d}from"tslib";import{createApiRouter as v}from"../../core/hono/hono";import{manufacturerRoute as s}from"./manufacturer.route";import{ManufacturerService as c}from"./manufacturer.service";export const buildManufacturerHandler=i=>{const n=v();return n.openapi(s.createManufacturer,e=>d(void 0,void 0,void 0,function*(){const t=e.get("auth"),a=e.req.valid("param"),r=e.req.valid("json"),o=yield t.isGranted("create"),l=yield new c(i).createManufacturer(a.organizationId,o.id,r);return e.json(l,201)})),n.openapi(s.getManufacturer,e=>d(void 0,void 0,void 0,function*(){const t=e.get("auth"),a=e.req.valid("param"),r=e.req.valid("query");yield t.isGranted("read");const u=yield new c(i).getManufacturer(a.organizationId,a.id,{locale:r.locale||null});return e.json(u,200)})),n.openapi(s.getManufacturers,e=>d(void 0,void 0,void 0,function*(){const t=e.get("auth"),a=e.req.valid("param"),r=e.req.valid("query");yield t.isGranted("read");const u=yield new c(i).getManufacturers(a.organizationId,Object.assign(Object.assign({},r),{locale:r.locale||null}));return e.json(u,200)})),n.openapi(s.updateManufacturer,e=>d(void 0,void 0,void 0,function*(){const t=e.get("auth"),a=e.req.valid("param"),r=e.req.valid("json"),o=yield t.isGranted("update"),l=yield new c(i).updateManufacturer(a.organizationId,a.id,o.id,r);return e.json(l,200)})),n.openapi(s.deleteManufacturer,e=>d(void 0,void 0,void 0,function*(){const t=e.get("auth"),a=e.req.valid("param"),r=yield t.isGranted("delete");return yield new c(i).deleteManufacturer(a.organizationId,a.id,r.id),e.body(null,204)})),n};
|
|
@@ -1,97 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createApiRoute } from "../../core/hono/hono";
|
|
3
|
-
import { ErrorSchema, HeaderSchema, OrganizationParams, OrganizationWithIdParams, PaginationMetaSchema, PaginationQuerySchema, } from "../../schemas";
|
|
4
|
-
import { GetResourceQuerySchema } from "../../schemas/queries.schema";
|
|
5
|
-
import { CreateManufacturerSchema, LocalizedManufacturerSchema, ManufacturerSchema, UpdateManufacturerSchema, } from "./manufacturer.schema";
|
|
6
|
-
const getManufacturersRoute = createApiRoute({
|
|
7
|
-
description: "Fetches a paginated list of manufacturers for a specific organization",
|
|
8
|
-
headers: HeaderSchema,
|
|
9
|
-
method: "GET",
|
|
10
|
-
operationId: "getManufacturers",
|
|
11
|
-
path: "/:organizationId/manufacturers",
|
|
12
|
-
pathParams: OrganizationParams,
|
|
13
|
-
query: PaginationQuerySchema,
|
|
14
|
-
responses: {
|
|
15
|
-
200: z.object({
|
|
16
|
-
list: z.array(z.union([ManufacturerSchema, LocalizedManufacturerSchema])),
|
|
17
|
-
meta: PaginationMetaSchema,
|
|
18
|
-
}),
|
|
19
|
-
400: ErrorSchema,
|
|
20
|
-
401: ErrorSchema,
|
|
21
|
-
},
|
|
22
|
-
summary: "Get Manufacturers",
|
|
23
|
-
tags: ["Manufacturer"],
|
|
24
|
-
});
|
|
25
|
-
const createManufacturerRoute = createApiRoute({
|
|
26
|
-
body: CreateManufacturerSchema,
|
|
27
|
-
description: "Creates a new manufacturer for a specific organization",
|
|
28
|
-
headers: HeaderSchema,
|
|
29
|
-
method: "POST",
|
|
30
|
-
operationId: "createManufacturer",
|
|
31
|
-
path: "/:organizationId/manufacturers",
|
|
32
|
-
pathParams: OrganizationParams,
|
|
33
|
-
responses: {
|
|
34
|
-
201: ManufacturerSchema,
|
|
35
|
-
400: ErrorSchema,
|
|
36
|
-
401: ErrorSchema,
|
|
37
|
-
404: ErrorSchema,
|
|
38
|
-
},
|
|
39
|
-
summary: "Create Manufacturer",
|
|
40
|
-
tags: ["Manufacturer"],
|
|
41
|
-
});
|
|
42
|
-
const getManufacturerRoute = createApiRoute({
|
|
43
|
-
headers: HeaderSchema,
|
|
44
|
-
method: "GET",
|
|
45
|
-
operationId: "getManufacturer",
|
|
46
|
-
path: "/:organizationId/manufacturers/:id",
|
|
47
|
-
pathParams: OrganizationWithIdParams,
|
|
48
|
-
query: GetResourceQuerySchema,
|
|
49
|
-
responses: {
|
|
50
|
-
200: z.union([ManufacturerSchema, LocalizedManufacturerSchema]),
|
|
51
|
-
401: ErrorSchema,
|
|
52
|
-
404: ErrorSchema,
|
|
53
|
-
},
|
|
54
|
-
summary: "Get Manufacturer",
|
|
55
|
-
tags: ["Manufacturer"],
|
|
56
|
-
});
|
|
57
|
-
const updateManufacturerRoute = createApiRoute({
|
|
58
|
-
body: UpdateManufacturerSchema,
|
|
59
|
-
description: "Updates an existing manufacturer",
|
|
60
|
-
headers: HeaderSchema,
|
|
61
|
-
method: "PUT",
|
|
62
|
-
operationId: "updateManufacturer",
|
|
63
|
-
path: "/:organizationId/manufacturers/:id",
|
|
64
|
-
pathParams: OrganizationWithIdParams,
|
|
65
|
-
responses: {
|
|
66
|
-
200: ManufacturerSchema,
|
|
67
|
-
400: ErrorSchema,
|
|
68
|
-
401: ErrorSchema,
|
|
69
|
-
404: ErrorSchema,
|
|
70
|
-
},
|
|
71
|
-
summary: "Update Manufacturer",
|
|
72
|
-
tags: ["Manufacturer"],
|
|
73
|
-
});
|
|
74
|
-
const deleteManufacturerRoute = createApiRoute({
|
|
75
|
-
description: "Soft deletes a manufacturer",
|
|
76
|
-
headers: HeaderSchema,
|
|
77
|
-
method: "DELETE",
|
|
78
|
-
operationId: "deleteManufacturer",
|
|
79
|
-
path: "/:organizationId/manufacturers/:id",
|
|
80
|
-
pathParams: OrganizationWithIdParams,
|
|
81
|
-
responses: {
|
|
82
|
-
204: null,
|
|
83
|
-
400: ErrorSchema,
|
|
84
|
-
401: ErrorSchema,
|
|
85
|
-
404: ErrorSchema,
|
|
86
|
-
},
|
|
87
|
-
summary: "Delete Manufacturer",
|
|
88
|
-
tags: ["Manufacturer"],
|
|
89
|
-
});
|
|
90
|
-
export const manufacturerRoute = {
|
|
91
|
-
getManufacturers: getManufacturersRoute,
|
|
92
|
-
createManufacturer: createManufacturerRoute,
|
|
93
|
-
getManufacturer: getManufacturerRoute,
|
|
94
|
-
updateManufacturer: updateManufacturerRoute,
|
|
95
|
-
deleteManufacturer: deleteManufacturerRoute,
|
|
96
|
-
};
|
|
97
|
-
//# sourceMappingURL=manufacturer.route.js.map
|
|
1
|
+
import{z as t}from"@hono/zod-openapi";import{createApiRoute as e}from"../../core/hono/hono";import{ErrorSchema as a,HeaderSchema as r,OrganizationParams as o,OrganizationWithIdParams as n,PaginationMetaSchema as s,PaginationQuerySchema as i}from"../../schemas";import{GetResourceQuerySchema as m}from"../../schemas/queries.schema";import{CreateManufacturerSchema as f,LocalizedManufacturerSchema as c,ManufacturerSchema as u,UpdateManufacturerSchema as d}from"./manufacturer.schema";const p=e({description:"Fetches a paginated list of manufacturers for a specific organization",headers:r,method:"GET",operationId:"getManufacturers",path:"/:organizationId/manufacturers",pathParams:o,query:i,responses:{200:t.object({list:t.array(t.union([u,c])),meta:s}),400:a,401:a},summary:"Get Manufacturers",tags:["Manufacturer"]}),h=e({body:f,description:"Creates a new manufacturer for a specific organization",headers:r,method:"POST",operationId:"createManufacturer",path:"/:organizationId/manufacturers",pathParams:o,responses:{201:u,400:a,401:a,404:a},summary:"Create Manufacturer",tags:["Manufacturer"]}),M=e({headers:r,method:"GET",operationId:"getManufacturer",path:"/:organizationId/manufacturers/:id",pathParams:n,query:m,responses:{200:t.union([u,c]),401:a,404:a},summary:"Get Manufacturer",tags:["Manufacturer"]}),g=e({body:d,description:"Updates an existing manufacturer",headers:r,method:"PUT",operationId:"updateManufacturer",path:"/:organizationId/manufacturers/:id",pathParams:n,responses:{200:u,400:a,401:a,404:a},summary:"Update Manufacturer",tags:["Manufacturer"]}),y=e({description:"Soft deletes a manufacturer",headers:r,method:"DELETE",operationId:"deleteManufacturer",path:"/:organizationId/manufacturers/:id",pathParams:n,responses:{204:null,400:a,401:a,404:a},summary:"Delete Manufacturer",tags:["Manufacturer"]});export const manufacturerRoute={getManufacturers:p,createManufacturer:h,getManufacturer:M,updateManufacturer:g,deleteManufacturer:y};
|
|
@@ -1,125 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { validateRequiredForDefaultLocale } from "../../core/utils/zod.util";
|
|
3
|
-
import { FileSchema } from "../file/file.schema";
|
|
4
|
-
export const ManufacturerSchema = z
|
|
5
|
-
.object({
|
|
6
|
-
id: z.string().openapi({
|
|
7
|
-
example: "clf9876543210abcdef",
|
|
8
|
-
description: "ID of the manufacturer",
|
|
9
|
-
}),
|
|
10
|
-
name: z.string().openapi({
|
|
11
|
-
example: "Tech Innovators Inc.",
|
|
12
|
-
description: "Name of the manufacturer",
|
|
13
|
-
}),
|
|
14
|
-
logo: FileSchema.nullable()
|
|
15
|
-
.optional()
|
|
16
|
-
.openapi({ description: "Logo of the manufacturer" }),
|
|
17
|
-
createdAt: z.date(),
|
|
18
|
-
translations: z
|
|
19
|
-
.array(z.object({
|
|
20
|
-
locale: z.string().min(1, "Locale is required").openapi({
|
|
21
|
-
example: "en-US",
|
|
22
|
-
description: "Locale code for the translation",
|
|
23
|
-
}),
|
|
24
|
-
about: z
|
|
25
|
-
.string()
|
|
26
|
-
.max(6000, "Maximum character limit is 6000")
|
|
27
|
-
.nullable()
|
|
28
|
-
.optional()
|
|
29
|
-
.openapi({
|
|
30
|
-
example: "Tech Innovators Inc. is a technology company.",
|
|
31
|
-
description: "Description about the manufacturer in the specified locale",
|
|
32
|
-
}),
|
|
33
|
-
}))
|
|
34
|
-
.optional()
|
|
35
|
-
.openapi({
|
|
36
|
-
description: "List of translations for the manufacturer",
|
|
37
|
-
}),
|
|
38
|
-
})
|
|
39
|
-
.openapi("Manufacturer");
|
|
40
|
-
export const LocalizedManufacturerSchema = ManufacturerSchema.omit({
|
|
41
|
-
translations: true,
|
|
42
|
-
})
|
|
43
|
-
.extend({
|
|
44
|
-
about: z.string().nullable().optional().default(""),
|
|
45
|
-
})
|
|
46
|
-
.openapi("LocalizedManufacturer");
|
|
47
|
-
export const CreateManufacturerSchema = z
|
|
48
|
-
.object({
|
|
49
|
-
name: z.string().min(1, "Name is required").openapi({
|
|
50
|
-
example: "Apple Inc.",
|
|
51
|
-
description: "Name of the manufacturer",
|
|
52
|
-
}),
|
|
53
|
-
defaultLocale: z.string().min(1, "Default locale is required").openapi({
|
|
54
|
-
example: "en-US",
|
|
55
|
-
description: "The default locale for the manufacturer",
|
|
56
|
-
}),
|
|
57
|
-
logo: FileSchema.nullable().optional().openapi({
|
|
58
|
-
description: "Logo of the manufacturer",
|
|
59
|
-
}),
|
|
60
|
-
translations: z
|
|
61
|
-
.array(z.object({
|
|
62
|
-
locale: z.string().min(1, "Locale is required").openapi({
|
|
63
|
-
example: "en-US",
|
|
64
|
-
description: "Locale code for the translation",
|
|
65
|
-
}),
|
|
66
|
-
about: z
|
|
67
|
-
.string()
|
|
68
|
-
.max(6000, "Maximum character limit is 6000")
|
|
69
|
-
.nullable()
|
|
70
|
-
.optional()
|
|
71
|
-
.openapi({
|
|
72
|
-
example: "Apple Inc. is a multinational technology company.",
|
|
73
|
-
description: "Description about the manufacturer in the specified locale",
|
|
74
|
-
}),
|
|
75
|
-
}))
|
|
76
|
-
.min(1, "Translations are required")
|
|
77
|
-
.openapi({
|
|
78
|
-
description: "List of translations for the manufacturer",
|
|
79
|
-
}),
|
|
80
|
-
logoId: z.string().optional().openapi({
|
|
81
|
-
example: "clf9876543210abcdef",
|
|
82
|
-
description: "ID reference to the manufacturer's logo file",
|
|
83
|
-
}),
|
|
84
|
-
})
|
|
85
|
-
.superRefine(validateRequiredForDefaultLocale("about"))
|
|
86
|
-
.openapi("CreateManufacturer");
|
|
87
|
-
export const UpdateManufacturerSchema = z
|
|
88
|
-
.object({
|
|
89
|
-
name: z.string().min(1, "Name is required").optional().openapi({
|
|
90
|
-
example: "Apple Inc. Updated",
|
|
91
|
-
description: "Name of the manufacturer",
|
|
92
|
-
}),
|
|
93
|
-
logo: FileSchema.nullable().optional().openapi({
|
|
94
|
-
description: "Logo of the manufacturer",
|
|
95
|
-
}),
|
|
96
|
-
defaultLocale: z.string().min(1, "Default locale is required").openapi({
|
|
97
|
-
description: "The default locale for the manufacturer",
|
|
98
|
-
}),
|
|
99
|
-
logoId: z.string().nullable().optional().openapi({
|
|
100
|
-
example: "clf9876543210abcdef",
|
|
101
|
-
description: "ID reference to the manufacturer's logo file",
|
|
102
|
-
}),
|
|
103
|
-
translations: z
|
|
104
|
-
.array(z.object({
|
|
105
|
-
locale: z.string().min(1, "Locale is required").openapi({
|
|
106
|
-
example: "en-US",
|
|
107
|
-
description: "Locale code for the translation",
|
|
108
|
-
}),
|
|
109
|
-
about: z
|
|
110
|
-
.string()
|
|
111
|
-
.max(6000, "Maximum character limit is 6000")
|
|
112
|
-
.nullable()
|
|
113
|
-
.optional()
|
|
114
|
-
.openapi({
|
|
115
|
-
example: "Apple Inc. is a multinational technology company.",
|
|
116
|
-
description: "Description about the manufacturer in the specified locale",
|
|
117
|
-
}),
|
|
118
|
-
}))
|
|
119
|
-
.optional()
|
|
120
|
-
.openapi({
|
|
121
|
-
description: "List of translations for the manufacturer",
|
|
122
|
-
}),
|
|
123
|
-
})
|
|
124
|
-
.openapi("UpdateManufacturer");
|
|
125
|
-
//# sourceMappingURL=manufacturer.schema.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{validateRequiredForDefaultLocale as o}from"../../core/utils/zod.util";import{FileSchema as a}from"../file/file.schema";export const ManufacturerSchema=e.object({id:e.string().openapi({example:"clf9876543210abcdef",description:"ID of the manufacturer"}),name:e.string().openapi({example:"Tech Innovators Inc.",description:"Name of the manufacturer"}),logo:a.nullable().optional().openapi({description:"Logo of the manufacturer"}),createdAt:e.date(),translations:e.array(e.object({locale:e.string().min(1,"Locale is required").openapi({example:"en-US",description:"Locale code for the translation"}),about:e.string().max(6e3,"Maximum character limit is 6000").nullable().optional().openapi({example:"Tech Innovators Inc. is a technology company.",description:"Description about the manufacturer in the specified locale"})})).optional().openapi({description:"List of translations for the manufacturer"})}).openapi("Manufacturer"),LocalizedManufacturerSchema=ManufacturerSchema.omit({translations:!0}).extend({about:e.string().nullable().optional().default("")}).openapi("LocalizedManufacturer"),CreateManufacturerSchema=e.object({name:e.string().min(1,"Name is required").openapi({example:"Apple Inc.",description:"Name of the manufacturer"}),defaultLocale:e.string().min(1,"Default locale is required").openapi({example:"en-US",description:"The default locale for the manufacturer"}),logo:a.nullable().optional().openapi({description:"Logo of the manufacturer"}),translations:e.array(e.object({locale:e.string().min(1,"Locale is required").openapi({example:"en-US",description:"Locale code for the translation"}),about:e.string().max(6e3,"Maximum character limit is 6000").nullable().optional().openapi({example:"Apple Inc. is a multinational technology company.",description:"Description about the manufacturer in the specified locale"})})).min(1,"Translations are required").openapi({description:"List of translations for the manufacturer"}),logoId:e.string().optional().openapi({example:"clf9876543210abcdef",description:"ID reference to the manufacturer's logo file"})}).superRefine(o("about")).openapi("CreateManufacturer"),UpdateManufacturerSchema=e.object({name:e.string().min(1,"Name is required").optional().openapi({example:"Apple Inc. Updated",description:"Name of the manufacturer"}),logo:a.nullable().optional().openapi({description:"Logo of the manufacturer"}),defaultLocale:e.string().min(1,"Default locale is required").openapi({description:"The default locale for the manufacturer"}),logoId:e.string().nullable().optional().openapi({example:"clf9876543210abcdef",description:"ID reference to the manufacturer's logo file"}),translations:e.array(e.object({locale:e.string().min(1,"Locale is required").openapi({example:"en-US",description:"Locale code for the translation"}),about:e.string().max(6e3,"Maximum character limit is 6000").nullable().optional().openapi({example:"Apple Inc. is a multinational technology company.",description:"Description about the manufacturer in the specified locale"})})).optional().openapi({description:"List of translations for the manufacturer"})}).openapi("UpdateManufacturer");
|