@shophost/rest-api 2.0.34 → 2.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,84 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createApiRoute } from "../../core/hono/hono";
|
|
3
|
-
import { CreateOrganizationSchema, ErrorSchema, HeaderSchema, OrganizationParams, OrganizationSchema, PaginationMetaSchema, PaginationQuerySchema, UpdateOrganizationSchema, } from "../../schemas";
|
|
4
|
-
const getOrganizationsRoute = createApiRoute({
|
|
5
|
-
description: "Fetches a paginated list of organizations",
|
|
6
|
-
headers: HeaderSchema,
|
|
7
|
-
method: "GET",
|
|
8
|
-
operationId: "getOrganizations",
|
|
9
|
-
path: "/organizations",
|
|
10
|
-
query: PaginationQuerySchema,
|
|
11
|
-
responses: {
|
|
12
|
-
200: z.object({
|
|
13
|
-
list: z.array(OrganizationSchema),
|
|
14
|
-
meta: PaginationMetaSchema,
|
|
15
|
-
}),
|
|
16
|
-
},
|
|
17
|
-
summary: "Get Organizations",
|
|
18
|
-
tags: ["Organization"],
|
|
19
|
-
});
|
|
20
|
-
const getOrganizationRoute = createApiRoute({
|
|
21
|
-
description: "Fetches a specific organization by ID",
|
|
22
|
-
headers: HeaderSchema,
|
|
23
|
-
method: "GET",
|
|
24
|
-
operationId: "getOrganization",
|
|
25
|
-
path: "/organizations/:organizationId",
|
|
26
|
-
pathParams: OrganizationParams,
|
|
27
|
-
responses: {
|
|
28
|
-
200: OrganizationSchema,
|
|
29
|
-
404: ErrorSchema,
|
|
30
|
-
},
|
|
31
|
-
summary: "Get Organization",
|
|
32
|
-
tags: ["Organization"],
|
|
33
|
-
});
|
|
34
|
-
const createOrganizationRoute = createApiRoute({
|
|
35
|
-
body: CreateOrganizationSchema,
|
|
36
|
-
description: "Creates a new organization",
|
|
37
|
-
headers: HeaderSchema,
|
|
38
|
-
method: "POST",
|
|
39
|
-
operationId: "createOrganization",
|
|
40
|
-
path: "/organizations",
|
|
41
|
-
responses: {
|
|
42
|
-
201: OrganizationSchema,
|
|
43
|
-
400: ErrorSchema,
|
|
44
|
-
},
|
|
45
|
-
summary: "Create Organization",
|
|
46
|
-
tags: ["Organization"],
|
|
47
|
-
});
|
|
48
|
-
const updateOrganizationRoute = createApiRoute({
|
|
49
|
-
body: UpdateOrganizationSchema,
|
|
50
|
-
description: "Updates a specific organization by ID",
|
|
51
|
-
headers: HeaderSchema,
|
|
52
|
-
method: "PATCH",
|
|
53
|
-
operationId: "updateOrganization",
|
|
54
|
-
path: "/organizations/:organizationId",
|
|
55
|
-
pathParams: OrganizationParams,
|
|
56
|
-
responses: {
|
|
57
|
-
200: OrganizationSchema,
|
|
58
|
-
404: ErrorSchema,
|
|
59
|
-
},
|
|
60
|
-
summary: "Update Organization",
|
|
61
|
-
tags: ["Organization"],
|
|
62
|
-
});
|
|
63
|
-
const deleteOrganizationRoute = createApiRoute({
|
|
64
|
-
description: "Deletes a specific organization by ID",
|
|
65
|
-
headers: HeaderSchema,
|
|
66
|
-
method: "DELETE",
|
|
67
|
-
operationId: "deleteOrganization",
|
|
68
|
-
path: "/organizations/:organizationId",
|
|
69
|
-
pathParams: OrganizationParams,
|
|
70
|
-
responses: {
|
|
71
|
-
204: null,
|
|
72
|
-
404: ErrorSchema,
|
|
73
|
-
},
|
|
74
|
-
summary: "Delete Organization",
|
|
75
|
-
tags: ["Organization"],
|
|
76
|
-
});
|
|
77
|
-
export const organizationRoute = {
|
|
78
|
-
getOrganizations: getOrganizationsRoute,
|
|
79
|
-
getOrganization: getOrganizationRoute,
|
|
80
|
-
createOrganization: createOrganizationRoute,
|
|
81
|
-
updateOrganization: updateOrganizationRoute,
|
|
82
|
-
deleteOrganization: deleteOrganizationRoute,
|
|
83
|
-
};
|
|
84
|
-
//# sourceMappingURL=organization.route.js.map
|
|
1
|
+
import{z as o}from"@hono/zod-openapi";import{createApiRoute as a}from"../../core/hono/hono";import{CreateOrganizationSchema as r,ErrorSchema as i,HeaderSchema as t,OrganizationParams as e,OrganizationSchema as n,PaginationMetaSchema as s,PaginationQuerySchema as g,UpdateOrganizationSchema as z}from"../../schemas";const p=a({description:"Fetches a paginated list of organizations",headers:t,method:"GET",operationId:"getOrganizations",path:"/organizations",query:g,responses:{200:o.object({list:o.array(n),meta:s})},summary:"Get Organizations",tags:["Organization"]}),d=a({description:"Fetches a specific organization by ID",headers:t,method:"GET",operationId:"getOrganization",path:"/organizations/:organizationId",pathParams:e,responses:{200:n,404:i},summary:"Get Organization",tags:["Organization"]}),m=a({body:r,description:"Creates a new organization",headers:t,method:"POST",operationId:"createOrganization",path:"/organizations",responses:{201:n,400:i},summary:"Create Organization",tags:["Organization"]}),c=a({body:z,description:"Updates a specific organization by ID",headers:t,method:"PATCH",operationId:"updateOrganization",path:"/organizations/:organizationId",pathParams:e,responses:{200:n,404:i},summary:"Update Organization",tags:["Organization"]}),O=a({description:"Deletes a specific organization by ID",headers:t,method:"DELETE",operationId:"deleteOrganization",path:"/organizations/:organizationId",pathParams:e,responses:{204:null,404:i},summary:"Delete Organization",tags:["Organization"]});export const organizationRoute={getOrganizations:p,getOrganization:d,createOrganization:m,updateOrganization:c,deleteOrganization:O};
|
|
@@ -1,64 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { AddressSchema, CreateAddressSchema, UpdateAddressSchema, } from "../../schemas/address.schema";
|
|
3
|
-
import { FileSchema } from "../file/file.schema";
|
|
4
|
-
import { OrganizationConfigurationSchema, UpdateOrganizationConfigurationSchema, } from "./organization-configuration.schema";
|
|
5
|
-
export const OrganizationSchema = z
|
|
6
|
-
.object({
|
|
7
|
-
id: z.string().openapi({
|
|
8
|
-
example: "clm1234567890abcdef",
|
|
9
|
-
description: "The unique identifier of the organization",
|
|
10
|
-
}),
|
|
11
|
-
name: z.string().openapi({
|
|
12
|
-
example: "Acme Store",
|
|
13
|
-
description: "The name of the organization",
|
|
14
|
-
}),
|
|
15
|
-
phone: z.string().min(1, "Phone number is required").openapi({
|
|
16
|
-
example: "+48123456890",
|
|
17
|
-
description: "The phone number of the organization",
|
|
18
|
-
}),
|
|
19
|
-
email: z.string().email().optional().openapi({
|
|
20
|
-
example: "john.doe@example.com",
|
|
21
|
-
description: "The email address of the organization",
|
|
22
|
-
}),
|
|
23
|
-
createdAt: z.date().openapi({
|
|
24
|
-
example: "2022-01-01T00:00:00.000Z",
|
|
25
|
-
description: "The date and time the organization was created",
|
|
26
|
-
}),
|
|
27
|
-
legalEntityId: z.string().nullable().openapi({
|
|
28
|
-
example: "clm1234567890abcdef",
|
|
29
|
-
description: "The unique identifier of the legal entity associated with the organization",
|
|
30
|
-
}),
|
|
31
|
-
address: AddressSchema,
|
|
32
|
-
configuration: OrganizationConfigurationSchema.openapi({
|
|
33
|
-
description: "The configuration settings for the organization",
|
|
34
|
-
}),
|
|
35
|
-
logo: z.string().url().optional().nullable().openapi({
|
|
36
|
-
example: "https://example.com/logo.jpg",
|
|
37
|
-
description: "The logo of the organization",
|
|
38
|
-
}),
|
|
39
|
-
logoFile: FileSchema.optional().nullable().openapi({
|
|
40
|
-
description: "The logo of the organization",
|
|
41
|
-
}),
|
|
42
|
-
})
|
|
43
|
-
.openapi("Organization");
|
|
44
|
-
export const CreateOrganizationSchema = OrganizationSchema.pick({
|
|
45
|
-
name: true,
|
|
46
|
-
phone: true,
|
|
47
|
-
email: true,
|
|
48
|
-
logoFile: true,
|
|
49
|
-
})
|
|
50
|
-
.extend({
|
|
51
|
-
logoId: z.string().optional().nullable().openapi({
|
|
52
|
-
example: "clm1234567890abcdef",
|
|
53
|
-
description: "The unique identifier of the thumbnail image associated with the organization",
|
|
54
|
-
}),
|
|
55
|
-
address: CreateAddressSchema,
|
|
56
|
-
})
|
|
57
|
-
.openapi("CreateOrganization");
|
|
58
|
-
export const UpdateOrganizationSchema = CreateOrganizationSchema.extend({
|
|
59
|
-
address: UpdateAddressSchema,
|
|
60
|
-
configuration: UpdateOrganizationConfigurationSchema,
|
|
61
|
-
})
|
|
62
|
-
.partial()
|
|
63
|
-
.openapi("UpdateOrganization");
|
|
64
|
-
//# sourceMappingURL=organization.schema.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{AddressSchema as i,CreateAddressSchema as a,UpdateAddressSchema as o}from"../../schemas/address.schema";import{FileSchema as n}from"../file/file.schema";import{OrganizationConfigurationSchema as t,UpdateOrganizationConfigurationSchema as r}from"./organization-configuration.schema";export const OrganizationSchema=e.object({id:e.string().openapi({example:"clm1234567890abcdef",description:"The unique identifier of the organization"}),name:e.string().openapi({example:"Acme Store",description:"The name of the organization"}),phone:e.string().min(1,"Phone number is required").openapi({example:"+48123456890",description:"The phone number of the organization"}),email:e.string().email().optional().openapi({example:"john.doe@example.com",description:"The email address of the organization"}),createdAt:e.date().openapi({example:"2022-01-01T00:00:00.000Z",description:"The date and time the organization was created"}),legalEntityId:e.string().nullable().openapi({example:"clm1234567890abcdef",description:"The unique identifier of the legal entity associated with the organization"}),address:i,configuration:t.openapi({description:"The configuration settings for the organization"}),logo:e.string().url().optional().nullable().openapi({example:"https://example.com/logo.jpg",description:"The logo of the organization"}),logoFile:n.optional().nullable().openapi({description:"The logo of the organization"})}).openapi("Organization"),CreateOrganizationSchema=OrganizationSchema.pick({name:!0,phone:!0,email:!0,logoFile:!0}).extend({logoId:e.string().optional().nullable().openapi({example:"clm1234567890abcdef",description:"The unique identifier of the thumbnail image associated with the organization"}),address:a}).openapi("CreateOrganization"),UpdateOrganizationSchema=CreateOrganizationSchema.extend({address:o,configuration:r}).partial().openapi("UpdateOrganization");
|
|
@@ -1,334 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { z } from "@hono/zod-openapi";
|
|
3
|
-
import { HttpException } from "../../core/exceptions/http-exception";
|
|
4
|
-
import { OrganizationSchema, PaginationMetaSchema, } from "../../schemas";
|
|
5
|
-
import { LocationService } from "../location/location.service";
|
|
6
|
-
class OrganizationService {
|
|
7
|
-
constructor(prisma, googleMapsApiKey) {
|
|
8
|
-
this.prisma = prisma;
|
|
9
|
-
this.convertToTimeString = (date) => {
|
|
10
|
-
if (!date)
|
|
11
|
-
return "";
|
|
12
|
-
return date.toLocaleTimeString("en-US", {
|
|
13
|
-
hour: "2-digit",
|
|
14
|
-
minute: "2-digit",
|
|
15
|
-
hour12: false,
|
|
16
|
-
timeZone: "UTC",
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
this.locationService = new LocationService(googleMapsApiKey);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Get a paginated list of organizations
|
|
23
|
-
*/
|
|
24
|
-
getOrganizations(userId, query) {
|
|
25
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const { page, limit } = query;
|
|
27
|
-
// Fetch organizations with pagination
|
|
28
|
-
const [list, meta] = yield this.prisma.organization
|
|
29
|
-
.paginate({
|
|
30
|
-
orderBy: {
|
|
31
|
-
createdAt: "desc",
|
|
32
|
-
},
|
|
33
|
-
where: {
|
|
34
|
-
members: {
|
|
35
|
-
some: {
|
|
36
|
-
userId: userId,
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
include: {
|
|
41
|
-
address: true,
|
|
42
|
-
configuration: true,
|
|
43
|
-
logoFile: true,
|
|
44
|
-
},
|
|
45
|
-
})
|
|
46
|
-
.withPages({
|
|
47
|
-
page,
|
|
48
|
-
limit,
|
|
49
|
-
});
|
|
50
|
-
return {
|
|
51
|
-
meta: PaginationMetaSchema.parse(meta),
|
|
52
|
-
list: z.array(OrganizationSchema).parse(list),
|
|
53
|
-
};
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
formatDateScheduleToTimeString(times) {
|
|
57
|
-
if (!times)
|
|
58
|
-
return null;
|
|
59
|
-
const weekdays = [
|
|
60
|
-
"monday",
|
|
61
|
-
"tuesday",
|
|
62
|
-
"wednesday",
|
|
63
|
-
"thursday",
|
|
64
|
-
"friday",
|
|
65
|
-
"saturday",
|
|
66
|
-
"sunday",
|
|
67
|
-
];
|
|
68
|
-
return weekdays.reduce((acc, day) => {
|
|
69
|
-
acc[day] = this.convertToTimeString(times[day]);
|
|
70
|
-
return acc;
|
|
71
|
-
}, {});
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Get a specific organization by ID
|
|
75
|
-
*/
|
|
76
|
-
getOrganization(organizationId) {
|
|
77
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
// Check if the organization exists in the database
|
|
79
|
-
const organization = yield this.prisma.organization.findUnique({
|
|
80
|
-
where: { id: organizationId, deletedAt: null },
|
|
81
|
-
include: {
|
|
82
|
-
address: true,
|
|
83
|
-
configuration: {
|
|
84
|
-
include: {
|
|
85
|
-
openingTimes: true,
|
|
86
|
-
closingTimes: true,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
logoFile: true,
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
if (!organization) {
|
|
93
|
-
throw new HttpException(404, "Organization not found");
|
|
94
|
-
}
|
|
95
|
-
const isOpen = (() => {
|
|
96
|
-
if (!organization.configuration.isAcceptingOrders)
|
|
97
|
-
return false;
|
|
98
|
-
if (!organization.configuration.openingTimes ||
|
|
99
|
-
!organization.configuration.closingTimes)
|
|
100
|
-
return false;
|
|
101
|
-
const warsawDate = new Date(new Date().toLocaleString("en-US", { timeZone: "Europe/Warsaw" }));
|
|
102
|
-
const currentDay = warsawDate
|
|
103
|
-
.toLocaleDateString("en-US", {
|
|
104
|
-
weekday: "long",
|
|
105
|
-
})
|
|
106
|
-
.toLowerCase();
|
|
107
|
-
const currentTime = warsawDate.toLocaleTimeString("en-US", {
|
|
108
|
-
hour: "2-digit",
|
|
109
|
-
minute: "2-digit",
|
|
110
|
-
hour12: false,
|
|
111
|
-
timeZone: "Europe/Warsaw",
|
|
112
|
-
});
|
|
113
|
-
const openingTime = organization.configuration.openingTimes[currentDay];
|
|
114
|
-
const closingTime = organization.configuration.closingTimes[currentDay];
|
|
115
|
-
if (!openingTime || !closingTime)
|
|
116
|
-
return false;
|
|
117
|
-
const openingTimeStr = this.convertToTimeString(openingTime);
|
|
118
|
-
const closingTimeStr = this.convertToTimeString(closingTime);
|
|
119
|
-
return currentTime >= openingTimeStr && currentTime <= closingTimeStr;
|
|
120
|
-
})();
|
|
121
|
-
return OrganizationSchema.parse(Object.assign(Object.assign({}, organization), { configuration: Object.assign(Object.assign({}, organization.configuration), { isOpen, openingTimes: this.formatDateScheduleToTimeString(organization.configuration.openingTimes), closingTimes: this.formatDateScheduleToTimeString(organization.configuration.closingTimes) }) }));
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Create a new organization
|
|
126
|
-
*/
|
|
127
|
-
createOrganization(userId, body) {
|
|
128
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
-
const placeDetails = yield this.locationService.getPlaceDetails(body.address.placeId);
|
|
130
|
-
// Create organization
|
|
131
|
-
const organization = yield this.prisma.organization.create({
|
|
132
|
-
data: Object.assign({ name: body.name, phone: body.phone, email: body.email, address: {
|
|
133
|
-
create: Object.assign(Object.assign({}, body.address), { latitude: placeDetails.latitude, longitude: placeDetails.longitude, createdBy: userId }),
|
|
134
|
-
}, configuration: {
|
|
135
|
-
create: {
|
|
136
|
-
countriesShipping: ["us"],
|
|
137
|
-
createdBy: userId,
|
|
138
|
-
enableHostCheckout: false,
|
|
139
|
-
enableHostTracking: false,
|
|
140
|
-
openingTimes: {
|
|
141
|
-
create: {
|
|
142
|
-
monday: null,
|
|
143
|
-
tuesday: null,
|
|
144
|
-
wednesday: null,
|
|
145
|
-
thursday: null,
|
|
146
|
-
friday: null,
|
|
147
|
-
saturday: null,
|
|
148
|
-
sunday: null,
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
closingTimes: {
|
|
152
|
-
create: {
|
|
153
|
-
monday: null,
|
|
154
|
-
tuesday: null,
|
|
155
|
-
wednesday: null,
|
|
156
|
-
thursday: null,
|
|
157
|
-
friday: null,
|
|
158
|
-
saturday: null,
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
}, members: {
|
|
163
|
-
create: {
|
|
164
|
-
user: {
|
|
165
|
-
connect: {
|
|
166
|
-
id: userId,
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
role: "owner",
|
|
170
|
-
},
|
|
171
|
-
}, createdBy: userId }, (body.logoId ? { logoFile: { connect: { id: body.logoId } } } : {})),
|
|
172
|
-
include: {
|
|
173
|
-
address: true,
|
|
174
|
-
configuration: {
|
|
175
|
-
include: {
|
|
176
|
-
openingTimes: true,
|
|
177
|
-
closingTimes: true,
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
logoFile: true,
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
return OrganizationSchema.parse(organization);
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Update an existing organization
|
|
188
|
-
*/
|
|
189
|
-
updateOrganization(organizationId, userId, body) {
|
|
190
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
-
// Check if the organization exists
|
|
192
|
-
const organization = yield this.prisma.organization.findUnique({
|
|
193
|
-
where: { id: organizationId, deletedAt: null },
|
|
194
|
-
});
|
|
195
|
-
if (!organization) {
|
|
196
|
-
// Throw 404 error if organization not found
|
|
197
|
-
throw new HttpException(404, "Organization not found");
|
|
198
|
-
}
|
|
199
|
-
const placeDetails = body.address
|
|
200
|
-
? yield this.locationService.getPlaceDetails(body.address.placeId)
|
|
201
|
-
: undefined;
|
|
202
|
-
const convertToDate = (timeString) => {
|
|
203
|
-
if (!timeString)
|
|
204
|
-
return null;
|
|
205
|
-
const [hours, minutes] = timeString.split(":").map(Number);
|
|
206
|
-
// Create date in UTC
|
|
207
|
-
const date = new Date();
|
|
208
|
-
date.setUTCHours(hours);
|
|
209
|
-
date.setUTCMinutes(minutes);
|
|
210
|
-
date.setUTCSeconds(0);
|
|
211
|
-
date.setUTCMilliseconds(0);
|
|
212
|
-
return date;
|
|
213
|
-
};
|
|
214
|
-
const updatedOrganization = yield this.prisma.organization.update({
|
|
215
|
-
where: { id: organizationId },
|
|
216
|
-
data: Object.assign(Object.assign(Object.assign(Object.assign({ name: body.name, phone: body.phone, email: body.email }, (body.logoId ? { logoFile: { connect: { id: body.logoId } } } : {})), { address: body.address
|
|
217
|
-
? {
|
|
218
|
-
update: Object.assign(Object.assign({}, body.address), { latitude: placeDetails.latitude, longitude: placeDetails.longitude, updatedBy: userId }),
|
|
219
|
-
}
|
|
220
|
-
: undefined }), (body.configuration
|
|
221
|
-
? {
|
|
222
|
-
configuration: {
|
|
223
|
-
update: {
|
|
224
|
-
countriesShipping: body.configuration.countriesShipping,
|
|
225
|
-
enableHostCheckout: body.configuration.enableHostCheckout,
|
|
226
|
-
enableHostTracking: body.configuration.enableHostTracking,
|
|
227
|
-
defaultLocale: body.configuration.defaultLocale,
|
|
228
|
-
supportedLocales: body.configuration.supportedLocales,
|
|
229
|
-
defaultCurrency: body.configuration.defaultCurrency,
|
|
230
|
-
updatedBy: userId,
|
|
231
|
-
isAcceptingOrders: body.configuration.isAcceptingOrders,
|
|
232
|
-
openingTimes: body.configuration.openingTimes
|
|
233
|
-
? {
|
|
234
|
-
update: {
|
|
235
|
-
data: {
|
|
236
|
-
monday: body.configuration.openingTimes.monday
|
|
237
|
-
? convertToDate(body.configuration.openingTimes.monday)
|
|
238
|
-
: null,
|
|
239
|
-
tuesday: body.configuration.openingTimes.tuesday
|
|
240
|
-
? convertToDate(body.configuration.openingTimes.tuesday)
|
|
241
|
-
: null,
|
|
242
|
-
wednesday: body.configuration.openingTimes.wednesday
|
|
243
|
-
? convertToDate(body.configuration.openingTimes.wednesday)
|
|
244
|
-
: null,
|
|
245
|
-
thursday: body.configuration.openingTimes.thursday
|
|
246
|
-
? convertToDate(body.configuration.openingTimes.thursday)
|
|
247
|
-
: null,
|
|
248
|
-
friday: body.configuration.openingTimes.friday
|
|
249
|
-
? convertToDate(body.configuration.openingTimes.friday)
|
|
250
|
-
: null,
|
|
251
|
-
saturday: body.configuration.openingTimes.saturday
|
|
252
|
-
? convertToDate(body.configuration.openingTimes.saturday)
|
|
253
|
-
: null,
|
|
254
|
-
sunday: body.configuration.openingTimes.sunday
|
|
255
|
-
? convertToDate(body.configuration.openingTimes.sunday)
|
|
256
|
-
: null,
|
|
257
|
-
},
|
|
258
|
-
},
|
|
259
|
-
}
|
|
260
|
-
: undefined,
|
|
261
|
-
closingTimes: body.configuration.closingTimes
|
|
262
|
-
? {
|
|
263
|
-
update: {
|
|
264
|
-
data: {
|
|
265
|
-
monday: body.configuration.closingTimes.monday
|
|
266
|
-
? convertToDate(body.configuration.closingTimes.monday)
|
|
267
|
-
: null,
|
|
268
|
-
tuesday: body.configuration.closingTimes.tuesday
|
|
269
|
-
? convertToDate(body.configuration.closingTimes.tuesday)
|
|
270
|
-
: null,
|
|
271
|
-
wednesday: body.configuration.closingTimes.wednesday
|
|
272
|
-
? convertToDate(body.configuration.closingTimes.wednesday)
|
|
273
|
-
: null,
|
|
274
|
-
thursday: body.configuration.closingTimes.thursday
|
|
275
|
-
? convertToDate(body.configuration.closingTimes.thursday)
|
|
276
|
-
: null,
|
|
277
|
-
friday: body.configuration.closingTimes.friday
|
|
278
|
-
? convertToDate(body.configuration.closingTimes.friday)
|
|
279
|
-
: null,
|
|
280
|
-
saturday: body.configuration.closingTimes.saturday
|
|
281
|
-
? convertToDate(body.configuration.closingTimes.saturday)
|
|
282
|
-
: null,
|
|
283
|
-
sunday: body.configuration.closingTimes.sunday
|
|
284
|
-
? convertToDate(body.configuration.closingTimes.sunday)
|
|
285
|
-
: null,
|
|
286
|
-
},
|
|
287
|
-
},
|
|
288
|
-
}
|
|
289
|
-
: undefined,
|
|
290
|
-
},
|
|
291
|
-
},
|
|
292
|
-
}
|
|
293
|
-
: undefined)), { updatedBy: userId }),
|
|
294
|
-
include: {
|
|
295
|
-
address: true,
|
|
296
|
-
logoFile: true,
|
|
297
|
-
configuration: {
|
|
298
|
-
include: {
|
|
299
|
-
openingTimes: true,
|
|
300
|
-
closingTimes: true,
|
|
301
|
-
},
|
|
302
|
-
},
|
|
303
|
-
},
|
|
304
|
-
});
|
|
305
|
-
return OrganizationSchema.parse(Object.assign(Object.assign({}, updatedOrganization), { configuration: Object.assign(Object.assign({}, updatedOrganization.configuration), { openingTimes: this.formatDateScheduleToTimeString(updatedOrganization.configuration.openingTimes), closingTimes: this.formatDateScheduleToTimeString(updatedOrganization.configuration.closingTimes) }) }));
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Delete an organization (soft delete)
|
|
310
|
-
*/
|
|
311
|
-
deleteOrganization(organizationId, userId) {
|
|
312
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
313
|
-
// Check if the organization exists
|
|
314
|
-
const organization = yield this.prisma.organization.findUnique({
|
|
315
|
-
where: { id: organizationId },
|
|
316
|
-
});
|
|
317
|
-
// Throw 404 error if organization not found
|
|
318
|
-
if (!organization) {
|
|
319
|
-
throw new HttpException(404, "Organization not found");
|
|
320
|
-
}
|
|
321
|
-
// Soft delete the organization
|
|
322
|
-
yield this.prisma.organization.update({
|
|
323
|
-
where: { id: organizationId },
|
|
324
|
-
data: {
|
|
325
|
-
deletedAt: new Date(),
|
|
326
|
-
deletedBy: userId,
|
|
327
|
-
},
|
|
328
|
-
});
|
|
329
|
-
return;
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
export { OrganizationService };
|
|
334
|
-
//# sourceMappingURL=organization.service.js.map
|
|
1
|
+
import{__awaiter as c}from"tslib";import{z as f}from"@hono/zod-openapi";import{HttpException as m}from"../../core/exceptions/http-exception";import{OrganizationSchema as g,PaginationMetaSchema as p}from"../../schemas";import{LocationService as T}from"../location/location.service";class h{constructor(e,n){this.prisma=e,this.convertToTimeString=i=>i?i.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:!1,timeZone:"UTC"}):"",this.locationService=new T(n)}getOrganizations(e,n){return c(this,void 0,void 0,function*(){const{page:i,limit:a}=n,[o,t]=yield this.prisma.organization.paginate({orderBy:{createdAt:"desc"},where:{members:{some:{userId:e}}},include:{address:!0,configuration:!0,logoFile:!0}}).withPages({page:i,limit:a});return{meta:p.parse(t),list:f.array(g).parse(o)}})}formatDateScheduleToTimeString(e){return e?["monday","tuesday","wednesday","thursday","friday","saturday","sunday"].reduce((i,a)=>(i[a]=this.convertToTimeString(e[a]),i),{}):null}getOrganization(e){return c(this,void 0,void 0,function*(){const n=yield this.prisma.organization.findUnique({where:{id:e,deletedAt:null},include:{address:!0,configuration:{include:{openingTimes:!0,closingTimes:!0}},logoFile:!0}});if(!n)throw new m(404,"Organization not found");const i=(()=>{if(!n.configuration.isAcceptingOrders||!n.configuration.openingTimes||!n.configuration.closingTimes)return!1;const a=new Date(new Date().toLocaleString("en-US",{timeZone:"Europe/Warsaw"})),o=a.toLocaleDateString("en-US",{weekday:"long"}).toLowerCase(),t=a.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:!1,timeZone:"Europe/Warsaw"}),s=n.configuration.openingTimes[o],r=n.configuration.closingTimes[o];if(!s||!r)return!1;const l=this.convertToTimeString(s),d=this.convertToTimeString(r);return t>=l&&t<=d})();return g.parse(Object.assign(Object.assign({},n),{configuration:Object.assign(Object.assign({},n.configuration),{isOpen:i,openingTimes:this.formatDateScheduleToTimeString(n.configuration.openingTimes),closingTimes:this.formatDateScheduleToTimeString(n.configuration.closingTimes)})}))})}createOrganization(e,n){return c(this,void 0,void 0,function*(){const i=yield this.locationService.getPlaceDetails(n.address.placeId),a=yield this.prisma.organization.create({data:Object.assign({name:n.name,phone:n.phone,email:n.email,address:{create:Object.assign(Object.assign({},n.address),{latitude:i.latitude,longitude:i.longitude,createdBy:e})},configuration:{create:{countriesShipping:["us"],createdBy:e,enableHostCheckout:!1,enableHostTracking:!1,openingTimes:{create:{monday:null,tuesday:null,wednesday:null,thursday:null,friday:null,saturday:null,sunday:null}},closingTimes:{create:{monday:null,tuesday:null,wednesday:null,thursday:null,friday:null,saturday:null}}}},members:{create:{user:{connect:{id:e}},role:"owner"}},createdBy:e},n.logoId?{logoFile:{connect:{id:n.logoId}}}:{}),include:{address:!0,configuration:{include:{openingTimes:!0,closingTimes:!0}},logoFile:!0}});return g.parse(a)})}updateOrganization(e,n,i){return c(this,void 0,void 0,function*(){if(!(yield this.prisma.organization.findUnique({where:{id:e,deletedAt:null}})))throw new m(404,"Organization not found");const o=i.address?yield this.locationService.getPlaceDetails(i.address.placeId):void 0,t=r=>{if(!r)return null;const[l,d]=r.split(":").map(Number),u=new Date;return u.setUTCHours(l),u.setUTCMinutes(d),u.setUTCSeconds(0),u.setUTCMilliseconds(0),u},s=yield this.prisma.organization.update({where:{id:e},data:Object.assign(Object.assign(Object.assign(Object.assign({name:i.name,phone:i.phone,email:i.email},i.logoId?{logoFile:{connect:{id:i.logoId}}}:{}),{address:i.address?{update:Object.assign(Object.assign({},i.address),{latitude:o.latitude,longitude:o.longitude,updatedBy:n})}:void 0}),i.configuration?{configuration:{update:{countriesShipping:i.configuration.countriesShipping,enableHostCheckout:i.configuration.enableHostCheckout,enableHostTracking:i.configuration.enableHostTracking,defaultLocale:i.configuration.defaultLocale,supportedLocales:i.configuration.supportedLocales,defaultCurrency:i.configuration.defaultCurrency,updatedBy:n,isAcceptingOrders:i.configuration.isAcceptingOrders,openingTimes:i.configuration.openingTimes?{update:{data:{monday:i.configuration.openingTimes.monday?t(i.configuration.openingTimes.monday):null,tuesday:i.configuration.openingTimes.tuesday?t(i.configuration.openingTimes.tuesday):null,wednesday:i.configuration.openingTimes.wednesday?t(i.configuration.openingTimes.wednesday):null,thursday:i.configuration.openingTimes.thursday?t(i.configuration.openingTimes.thursday):null,friday:i.configuration.openingTimes.friday?t(i.configuration.openingTimes.friday):null,saturday:i.configuration.openingTimes.saturday?t(i.configuration.openingTimes.saturday):null,sunday:i.configuration.openingTimes.sunday?t(i.configuration.openingTimes.sunday):null}}}:void 0,closingTimes:i.configuration.closingTimes?{update:{data:{monday:i.configuration.closingTimes.monday?t(i.configuration.closingTimes.monday):null,tuesday:i.configuration.closingTimes.tuesday?t(i.configuration.closingTimes.tuesday):null,wednesday:i.configuration.closingTimes.wednesday?t(i.configuration.closingTimes.wednesday):null,thursday:i.configuration.closingTimes.thursday?t(i.configuration.closingTimes.thursday):null,friday:i.configuration.closingTimes.friday?t(i.configuration.closingTimes.friday):null,saturday:i.configuration.closingTimes.saturday?t(i.configuration.closingTimes.saturday):null,sunday:i.configuration.closingTimes.sunday?t(i.configuration.closingTimes.sunday):null}}}:void 0}}}:void 0),{updatedBy:n}),include:{address:!0,logoFile:!0,configuration:{include:{openingTimes:!0,closingTimes:!0}}}});return g.parse(Object.assign(Object.assign({},s),{configuration:Object.assign(Object.assign({},s.configuration),{openingTimes:this.formatDateScheduleToTimeString(s.configuration.openingTimes),closingTimes:this.formatDateScheduleToTimeString(s.configuration.closingTimes)})}))})}deleteOrganization(e,n){return c(this,void 0,void 0,function*(){if(!(yield this.prisma.organization.findUnique({where:{id:e}})))throw new m(404,"Organization not found");yield this.prisma.organization.update({where:{id:e},data:{deletedAt:new Date,deletedBy:n}})})}}export{h as OrganizationService};
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createApiRouter } from "../../core/hono/hono";
|
|
3
|
-
import { paymentRoute } from "./payment.route";
|
|
4
|
-
import { PaymentService } from "./payment.service";
|
|
5
|
-
export const buildPaymentHandler = (prisma, options) => {
|
|
6
|
-
const app = createApiRouter();
|
|
7
|
-
app.openapi(paymentRoute.getAvailablePaymentMethods, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
-
const auth = c.get("auth");
|
|
9
|
-
yield auth.getCurrentUser();
|
|
10
|
-
const service = new PaymentService(prisma, options);
|
|
11
|
-
const paymentMethods = yield service.getPaymentMethods();
|
|
12
|
-
return c.json(paymentMethods, 200);
|
|
13
|
-
}));
|
|
14
|
-
return app;
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=payment.handler.js.map
|
|
1
|
+
import{__awaiter as i}from"tslib";import{createApiRouter as a}from"../../core/hono/hono";import{paymentRoute as m}from"./payment.route";import{PaymentService as p}from"./payment.service";export const buildPaymentHandler=(o,r)=>{const e=a();return e.openapi(m.getAvailablePaymentMethods,t=>i(void 0,void 0,void 0,function*(){yield t.get("auth").getCurrentUser();const n=yield new p(o,r).getPaymentMethods();return t.json(n,200)})),e};
|
|
@@ -1,22 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ErrorSchema, HeaderSchema, OrganizationParams } from "../../schemas";
|
|
3
|
-
import { PaymentMethodDetailsSchema } from "./payment.schema";
|
|
4
|
-
const getAvailablePaymentMethodsRoute = createApiRoute({
|
|
5
|
-
description: "Returns a list of available payment methods for the organization.",
|
|
6
|
-
headers: HeaderSchema,
|
|
7
|
-
method: "GET",
|
|
8
|
-
operationId: "getAvailablePaymentMethods",
|
|
9
|
-
path: "/:organizationId/payment/methods",
|
|
10
|
-
pathParams: OrganizationParams,
|
|
11
|
-
responses: {
|
|
12
|
-
200: PaymentMethodDetailsSchema.array(),
|
|
13
|
-
400: ErrorSchema,
|
|
14
|
-
401: ErrorSchema,
|
|
15
|
-
},
|
|
16
|
-
summary: "Get Available Payment Methods",
|
|
17
|
-
tags: ["Payment"],
|
|
18
|
-
});
|
|
19
|
-
export const paymentRoute = {
|
|
20
|
-
getAvailablePaymentMethods: getAvailablePaymentMethodsRoute,
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=payment.route.js.map
|
|
1
|
+
import{createApiRoute as a}from"../../core/hono/hono";import{ErrorSchema as e,HeaderSchema as t,OrganizationParams as o}from"../../schemas";import{PaymentMethodDetailsSchema as r}from"./payment.schema";const m=a({description:"Returns a list of available payment methods for the organization.",headers:t,method:"GET",operationId:"getAvailablePaymentMethods",path:"/:organizationId/payment/methods",pathParams:o,responses:{200:r.array(),400:e,401:e},summary:"Get Available Payment Methods",tags:["Payment"]});export const paymentRoute={getAvailablePaymentMethods:m};
|
|
@@ -1,46 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { currency } from "../../schemas/currency.schema";
|
|
3
|
-
export const PaymentMethodSchema = z
|
|
4
|
-
.enum(["card", "blik", "cash_on_delivery", "paypal"])
|
|
5
|
-
.openapi({
|
|
6
|
-
description: "The payment method",
|
|
7
|
-
example: "card",
|
|
8
|
-
});
|
|
9
|
-
export const PaymentProviderSchema = z
|
|
10
|
-
.enum(["stripe", "revolut", "payu", "not_applicable"])
|
|
11
|
-
.openapi({
|
|
12
|
-
description: "The payment method",
|
|
13
|
-
example: "card",
|
|
14
|
-
});
|
|
15
|
-
export const PaymentStatusSchema = z
|
|
16
|
-
.enum(["pending", "succeeded", "refunded", "failed", "canceled"])
|
|
17
|
-
.openapi({
|
|
18
|
-
description: "The payment status",
|
|
19
|
-
example: "pending",
|
|
20
|
-
});
|
|
21
|
-
export const PaymentMethodDetailsSchema = z
|
|
22
|
-
.object({
|
|
23
|
-
id: z.string().min(1),
|
|
24
|
-
provider: PaymentProviderSchema,
|
|
25
|
-
method: PaymentMethodSchema,
|
|
26
|
-
description: z.string().min(1),
|
|
27
|
-
})
|
|
28
|
-
.openapi({
|
|
29
|
-
description: "The payment method",
|
|
30
|
-
example: {
|
|
31
|
-
provider: "stripe",
|
|
32
|
-
type: "card",
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
export const PaymentSchema = z.object({
|
|
36
|
-
id: z.string().cuid().min(1),
|
|
37
|
-
method: PaymentMethodSchema,
|
|
38
|
-
provider: PaymentProviderSchema,
|
|
39
|
-
status: PaymentStatusSchema,
|
|
40
|
-
shipping: z.number().min(0).default(0),
|
|
41
|
-
subtotal: z.number().min(0),
|
|
42
|
-
total: z.number().min(0),
|
|
43
|
-
discount: z.number().min(0).default(0),
|
|
44
|
-
currency,
|
|
45
|
-
});
|
|
46
|
-
//# sourceMappingURL=payment.schema.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{currency as t}from"../../schemas/currency.schema";export const PaymentMethodSchema=e.enum(["card","blik","cash_on_delivery","paypal"]).openapi({description:"The payment method",example:"card"}),PaymentProviderSchema=e.enum(["stripe","revolut","payu","not_applicable"]).openapi({description:"The payment method",example:"card"}),PaymentStatusSchema=e.enum(["pending","succeeded","refunded","failed","canceled"]).openapi({description:"The payment status",example:"pending"}),PaymentMethodDetailsSchema=e.object({id:e.string().min(1),provider:PaymentProviderSchema,method:PaymentMethodSchema,description:e.string().min(1)}).openapi({description:"The payment method",example:{provider:"stripe",type:"card"}}),PaymentSchema=e.object({id:e.string().cuid().min(1),method:PaymentMethodSchema,provider:PaymentProviderSchema,status:PaymentStatusSchema,shipping:e.number().min(0).default(0),subtotal:e.number().min(0),total:e.number().min(0),discount:e.number().min(0).default(0),currency:t});
|