@shophost/rest-api 2.0.29 → 2.0.31
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 +18 -13
- package/scripts/minify.mjs +110 -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.d.ts +0 -3
- 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.d.ts +0 -128
- package/src/core/db/__generated__/client/browser.js +1 -18
- package/src/core/db/__generated__/client/client.d.ts +0 -143
- 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.d.ts +0 -343
- package/src/core/db/__generated__/client/internal/class.js +1 -55
- package/src/core/db/__generated__/client/internal/prismaNamespace.d.ts +0 -234
- package/src/core/db/__generated__/client/internal/prismaNamespace.js +1 -541
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.d.ts +0 -15
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js +1 -512
- package/src/core/db/__generated__/client/models/Account.d.ts +0 -628
- package/src/core/db/__generated__/client/models/Account.js +1 -2
- package/src/core/db/__generated__/client/models/Address.d.ts +0 -701
- package/src/core/db/__generated__/client/models/Address.js +1 -2
- package/src/core/db/__generated__/client/models/Campaign.d.ts +0 -638
- package/src/core/db/__generated__/client/models/Campaign.js +1 -2
- package/src/core/db/__generated__/client/models/ClosingTimes.d.ts +0 -634
- package/src/core/db/__generated__/client/models/ClosingTimes.js +1 -2
- package/src/core/db/__generated__/client/models/File.d.ts +0 -752
- package/src/core/db/__generated__/client/models/File.js +1 -2
- package/src/core/db/__generated__/client/models/Invitation.d.ts +0 -628
- package/src/core/db/__generated__/client/models/Invitation.js +1 -2
- package/src/core/db/__generated__/client/models/LegalEntity.d.ts +0 -652
- package/src/core/db/__generated__/client/models/LegalEntity.js +1 -2
- package/src/core/db/__generated__/client/models/Manufacturer.d.ts +0 -679
- package/src/core/db/__generated__/client/models/Manufacturer.js +1 -2
- package/src/core/db/__generated__/client/models/ManufacturerTranslation.d.ts +0 -628
- package/src/core/db/__generated__/client/models/ManufacturerTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/Member.d.ts +0 -628
- package/src/core/db/__generated__/client/models/Member.js +1 -2
- package/src/core/db/__generated__/client/models/Modifier.d.ts +0 -662
- package/src/core/db/__generated__/client/models/Modifier.js +1 -2
- package/src/core/db/__generated__/client/models/ModifierGroup.d.ts +0 -686
- package/src/core/db/__generated__/client/models/ModifierGroup.js +1 -2
- package/src/core/db/__generated__/client/models/ModifierGroupTranslation.d.ts +0 -628
- package/src/core/db/__generated__/client/models/ModifierGroupTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/OpeningTimes.d.ts +0 -634
- package/src/core/db/__generated__/client/models/OpeningTimes.js +1 -2
- package/src/core/db/__generated__/client/models/Order.d.ts +0 -700
- package/src/core/db/__generated__/client/models/Order.js +1 -2
- package/src/core/db/__generated__/client/models/OrderItem.d.ts +0 -686
- package/src/core/db/__generated__/client/models/OrderItem.js +1 -2
- package/src/core/db/__generated__/client/models/OrderItemTranslation.d.ts +0 -628
- package/src/core/db/__generated__/client/models/OrderItemTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/Organization.d.ts +0 -811
- package/src/core/db/__generated__/client/models/Organization.js +1 -2
- package/src/core/db/__generated__/client/models/OrganizationConfiguration.d.ts +0 -676
- package/src/core/db/__generated__/client/models/OrganizationConfiguration.js +1 -2
- package/src/core/db/__generated__/client/models/Payment.d.ts +0 -668
- package/src/core/db/__generated__/client/models/Payment.js +1 -2
- package/src/core/db/__generated__/client/models/PaymentSession.d.ts +0 -638
- package/src/core/db/__generated__/client/models/PaymentSession.js +1 -2
- package/src/core/db/__generated__/client/models/Product.d.ts +0 -746
- package/src/core/db/__generated__/client/models/Product.js +1 -2
- package/src/core/db/__generated__/client/models/ProductCategory.d.ts +0 -689
- package/src/core/db/__generated__/client/models/ProductCategory.js +1 -2
- package/src/core/db/__generated__/client/models/ProductCategoryTranslation.d.ts +0 -628
- package/src/core/db/__generated__/client/models/ProductCategoryTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/ProductSnapshot.d.ts +0 -664
- package/src/core/db/__generated__/client/models/ProductSnapshot.js +1 -2
- package/src/core/db/__generated__/client/models/ProductTranslation.d.ts +0 -628
- package/src/core/db/__generated__/client/models/ProductTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/Reservation.d.ts +0 -650
- package/src/core/db/__generated__/client/models/Reservation.js +1 -2
- package/src/core/db/__generated__/client/models/Session.d.ts +0 -628
- package/src/core/db/__generated__/client/models/Session.js +1 -2
- package/src/core/db/__generated__/client/models/ShippingMethod.d.ts +0 -679
- package/src/core/db/__generated__/client/models/ShippingMethod.js +1 -2
- package/src/core/db/__generated__/client/models/ShippingZone.d.ts +0 -638
- package/src/core/db/__generated__/client/models/ShippingZone.js +1 -2
- package/src/core/db/__generated__/client/models/User.d.ts +0 -736
- package/src/core/db/__generated__/client/models/User.js +1 -2
- package/src/core/db/__generated__/client/models/Verification.d.ts +0 -592
- 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.d.ts +9 -1
- package/src/core/lib/prisma.js +1 -11
- package/src/core/logging/pino.js +1 -5
- package/src/core/notifications/email.service.d.ts +0 -15
- 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.d.ts +0 -10
- package/src/core/utils/object.util.js +1 -39
- package/src/core/utils/translations.util.js +0 -2
- package/src/core/utils/zod.util.d.ts +0 -12
- 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.d.ts +0 -7
- 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.d.ts +0 -6
- 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.d.ts +0 -3
- 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.d.ts +0 -19
- 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.d.ts +0 -15
- 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.d.ts +0 -15
- 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.d.ts +0 -25
- 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.d.ts +0 -22
- 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.d.ts +0 -18
- 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.d.ts +0 -7
- 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.d.ts +0 -25
- 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.d.ts +0 -8
- package/src/schemas/address.schema.js +1 -112
- package/src/schemas/currency.schema.d.ts +0 -42
- 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.d.ts +1 -0
- package/src/test/global-setup.js +1 -0
- package/src/test/integration/api-fixtures.d.ts +4 -16
- package/src/test/integration/api-fixtures.js +1 -225
- package/src/test/integration/seed.d.ts +81 -0
- package/src/test/integration/seed.js +1 -0
- package/src/test/integration/test-helpers.d.ts +107 -924
- package/src/test/integration/test-helpers.js +1 -1100
- package/src/test/setup-test-env.d.ts +1 -1
- package/src/test/setup-test-env.js +1 -29
- package/src/app.js.map +0 -1
- package/src/core/auth/auth.schema.js.map +0 -1
- package/src/core/auth/auth.util.js.map +0 -1
- package/src/core/auth/better-auth.lib.js.map +0 -1
- package/src/core/auth/generate-password-hash.util.js.map +0 -1
- package/src/core/auth/headers.schema.js.map +0 -1
- package/src/core/auth/user.schema.js.map +0 -1
- package/src/core/db/__generated__/client/browser.js.map +0 -1
- package/src/core/db/__generated__/client/client.js.map +0 -1
- package/src/core/db/__generated__/client/commonInputTypes.js.map +0 -1
- package/src/core/db/__generated__/client/enums.js.map +0 -1
- package/src/core/db/__generated__/client/internal/class.js.map +0 -1
- package/src/core/db/__generated__/client/internal/prismaNamespace.js.map +0 -1
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js.map +0 -1
- package/src/core/db/__generated__/client/models/Account.js.map +0 -1
- package/src/core/db/__generated__/client/models/Address.js.map +0 -1
- package/src/core/db/__generated__/client/models/Campaign.js.map +0 -1
- package/src/core/db/__generated__/client/models/ClosingTimes.js.map +0 -1
- package/src/core/db/__generated__/client/models/File.js.map +0 -1
- package/src/core/db/__generated__/client/models/Invitation.js.map +0 -1
- package/src/core/db/__generated__/client/models/LegalEntity.js.map +0 -1
- package/src/core/db/__generated__/client/models/Manufacturer.js.map +0 -1
- package/src/core/db/__generated__/client/models/ManufacturerTranslation.js.map +0 -1
- package/src/core/db/__generated__/client/models/Member.js.map +0 -1
- package/src/core/db/__generated__/client/models/Modifier.js.map +0 -1
- package/src/core/db/__generated__/client/models/ModifierGroup.js.map +0 -1
- package/src/core/db/__generated__/client/models/ModifierGroupTranslation.js.map +0 -1
- package/src/core/db/__generated__/client/models/OpeningTimes.js.map +0 -1
- package/src/core/db/__generated__/client/models/Order.js.map +0 -1
- package/src/core/db/__generated__/client/models/OrderItem.js.map +0 -1
- package/src/core/db/__generated__/client/models/OrderItemTranslation.js.map +0 -1
- package/src/core/db/__generated__/client/models/Organization.js.map +0 -1
- package/src/core/db/__generated__/client/models/OrganizationConfiguration.js.map +0 -1
- package/src/core/db/__generated__/client/models/Payment.js.map +0 -1
- package/src/core/db/__generated__/client/models/PaymentSession.js.map +0 -1
- package/src/core/db/__generated__/client/models/Product.js.map +0 -1
- package/src/core/db/__generated__/client/models/ProductCategory.js.map +0 -1
- package/src/core/db/__generated__/client/models/ProductCategoryTranslation.js.map +0 -1
- package/src/core/db/__generated__/client/models/ProductSnapshot.js.map +0 -1
- package/src/core/db/__generated__/client/models/ProductTranslation.js.map +0 -1
- package/src/core/db/__generated__/client/models/Reservation.js.map +0 -1
- package/src/core/db/__generated__/client/models/Session.js.map +0 -1
- package/src/core/db/__generated__/client/models/ShippingMethod.js.map +0 -1
- package/src/core/db/__generated__/client/models/ShippingZone.js.map +0 -1
- package/src/core/db/__generated__/client/models/User.js.map +0 -1
- package/src/core/db/__generated__/client/models/Verification.js.map +0 -1
- package/src/core/db/__generated__/client/models.js.map +0 -1
- package/src/core/db/index.js.map +0 -1
- package/src/core/exceptions/http-exception.js.map +0 -1
- package/src/core/hono/hono.js.map +0 -1
- package/src/core/lib/prisma.js.map +0 -1
- package/src/core/logging/pino.js.map +0 -1
- package/src/core/notifications/email.service.js.map +0 -1
- package/src/core/openapi/openapi.lib.js.map +0 -1
- package/src/core/types/google-maps.types.js.map +0 -1
- package/src/core/utils/currency.util.js.map +0 -1
- package/src/core/utils/env.util.js.map +0 -1
- package/src/core/utils/object.util.js.map +0 -1
- package/src/core/utils/translations.util.js.map +0 -1
- package/src/core/utils/zod.util.js.map +0 -1
- package/src/db.js.map +0 -1
- package/src/features/access/access.handler.js.map +0 -1
- package/src/features/access/access.route.js.map +0 -1
- package/src/features/access/access.schema.js.map +0 -1
- package/src/features/access/access.service.js.map +0 -1
- package/src/features/cart/cart.handler.js.map +0 -1
- package/src/features/cart/cart.route.js.map +0 -1
- package/src/features/cart/cart.schema.js.map +0 -1
- package/src/features/cart/cart.service.js.map +0 -1
- package/src/features/cart/cart.util.js.map +0 -1
- package/src/features/file/file.handler.js.map +0 -1
- package/src/features/file/file.route.js.map +0 -1
- package/src/features/file/file.schema.js.map +0 -1
- package/src/features/file/file.service.js.map +0 -1
- package/src/features/health/health.handler.js.map +0 -1
- package/src/features/health/health.route.js.map +0 -1
- package/src/features/index.js.map +0 -1
- package/src/features/location/location.handler.js.map +0 -1
- package/src/features/location/location.route.js.map +0 -1
- package/src/features/location/location.schema.js.map +0 -1
- package/src/features/location/location.service.js.map +0 -1
- package/src/features/manufacturer/manufacturer.handler.js.map +0 -1
- package/src/features/manufacturer/manufacturer.route.js.map +0 -1
- package/src/features/manufacturer/manufacturer.schema.js.map +0 -1
- package/src/features/manufacturer/manufacturer.service.js.map +0 -1
- package/src/features/order/emails/order-confirmation.email.js.map +0 -1
- package/src/features/order/emails/order-notification.email.js.map +0 -1
- package/src/features/order/fulfilment.schema.js.map +0 -1
- package/src/features/order/order.handler.js.map +0 -1
- package/src/features/order/order.route.js.map +0 -1
- package/src/features/order/order.schema.js.map +0 -1
- package/src/features/order/order.service.js.map +0 -1
- package/src/features/order/recipient.schema.js.map +0 -1
- package/src/features/organization/legal-entity.schema.js.map +0 -1
- package/src/features/organization/organization-configuration.schema.js.map +0 -1
- package/src/features/organization/organization.handler.js.map +0 -1
- package/src/features/organization/organization.route.js.map +0 -1
- package/src/features/organization/organization.schema.js.map +0 -1
- package/src/features/organization/organization.service.js.map +0 -1
- package/src/features/payment/payment.handler.js.map +0 -1
- package/src/features/payment/payment.route.js.map +0 -1
- package/src/features/payment/payment.schema.js.map +0 -1
- package/src/features/payment/payment.service.js.map +0 -1
- package/src/features/payment/stripe.service.js.map +0 -1
- package/src/features/product/product-modifier.schema.js.map +0 -1
- package/src/features/product/product.handler.js.map +0 -1
- package/src/features/product/product.route.js.map +0 -1
- package/src/features/product/product.schema.js.map +0 -1
- package/src/features/product/product.service.js.map +0 -1
- package/src/features/product-category/product-category.handler.js.map +0 -1
- package/src/features/product-category/product-category.route.js.map +0 -1
- package/src/features/product-category/product-category.schema.js.map +0 -1
- package/src/features/product-category/product-category.service.js.map +0 -1
- package/src/features/reservation/emails/reservation-cancellation.email.js.map +0 -1
- package/src/features/reservation/emails/reservation-confirmation.email.js.map +0 -1
- package/src/features/reservation/emails/reservation-notification.email.js.map +0 -1
- package/src/features/reservation/reservation.handler.js.map +0 -1
- package/src/features/reservation/reservation.route.js.map +0 -1
- package/src/features/reservation/reservation.schema.js.map +0 -1
- package/src/features/reservation/reservation.service.js.map +0 -1
- package/src/features/shipping/shipping.handler.js.map +0 -1
- package/src/features/shipping/shipping.route.js.map +0 -1
- package/src/features/shipping/shipping.service.js.map +0 -1
- package/src/features/shipping-method/shipping-method.handler.js.map +0 -1
- package/src/features/shipping-method/shipping-method.route.js.map +0 -1
- package/src/features/shipping-method/shipping-method.schema.js.map +0 -1
- package/src/features/shipping-method/shipping-method.service.js.map +0 -1
- package/src/features/shipping-method/shipping-zone.schema.js.map +0 -1
- package/src/features/webhook/webhook.handler.js.map +0 -1
- package/src/features/webhook/webhook.route.js.map +0 -1
- package/src/index.js.map +0 -1
- package/src/integrations/next.js.map +0 -1
- package/src/schemas/address.schema.js.map +0 -1
- package/src/schemas/currency.schema.js.map +0 -1
- package/src/schemas/error.schema.js.map +0 -1
- package/src/schemas/index.js.map +0 -1
- package/src/schemas/locales.schema.js.map +0 -1
- package/src/schemas/number.schema.js.map +0 -1
- package/src/schemas/pagination.schema.js.map +0 -1
- package/src/schemas/params.schema.js.map +0 -1
- package/src/schemas/queries.schema.js.map +0 -1
- package/src/test/integration/api-fixtures.js.map +0 -1
- package/src/test/integration/test-helpers.js.map +0 -1
- package/src/test/setup-test-env.js.map +0 -1
|
@@ -1,144 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createApiRoute } from "../../core/hono/hono";
|
|
3
|
-
import { CreateShippingMethodSchema, ErrorSchema, HeaderSchema, OrganizationParams, OrganizationWithIdParams, PaginationMetaSchema, PaginationQuerySchema, ShippingMethodSchema, UpdateShippingMethodSchema, } from "../../schemas";
|
|
4
|
-
const shippingMethodPathParams = z.object({
|
|
5
|
-
id: z.string().openapi({
|
|
6
|
-
description: "ID of the shipping method",
|
|
7
|
-
example: "clf9876543210abcdef",
|
|
8
|
-
param: {
|
|
9
|
-
in: "path",
|
|
10
|
-
name: "id",
|
|
11
|
-
},
|
|
12
|
-
}),
|
|
13
|
-
organizationId: z.string().openapi({
|
|
14
|
-
description: "ID of the organization",
|
|
15
|
-
example: "cju0z9k4z0000l1qg5z1z1z1z",
|
|
16
|
-
param: {
|
|
17
|
-
in: "path",
|
|
18
|
-
name: "organizationId",
|
|
19
|
-
},
|
|
20
|
-
}),
|
|
21
|
-
});
|
|
22
|
-
const getShippingMethodRoute = createApiRoute({
|
|
23
|
-
headers: HeaderSchema,
|
|
24
|
-
method: "GET",
|
|
25
|
-
operationId: "getShippingMethod",
|
|
26
|
-
path: "/:organizationId/shipping-methods/:id",
|
|
27
|
-
pathParams: OrganizationWithIdParams,
|
|
28
|
-
responses: {
|
|
29
|
-
200: ShippingMethodSchema,
|
|
30
|
-
401: ErrorSchema,
|
|
31
|
-
404: ErrorSchema,
|
|
32
|
-
},
|
|
33
|
-
summary: "Get Shipping Method",
|
|
34
|
-
tags: ["ShippingMethod"],
|
|
35
|
-
});
|
|
36
|
-
const accessEligibilityRoute = createApiRoute({
|
|
37
|
-
description: "Fetches a list of published shipping methods a user can use",
|
|
38
|
-
headers: HeaderSchema,
|
|
39
|
-
method: "GET",
|
|
40
|
-
operationId: "accessEligibility",
|
|
41
|
-
path: "/:organizationId/shipping-methods/access/eligibility",
|
|
42
|
-
pathParams: OrganizationParams,
|
|
43
|
-
responses: {
|
|
44
|
-
200: z.array(ShippingMethodSchema),
|
|
45
|
-
},
|
|
46
|
-
summary: "Get Eligible Shipping Methods",
|
|
47
|
-
tags: ["ShippingMethod"],
|
|
48
|
-
});
|
|
49
|
-
const getShippingMethodsRoute = createApiRoute({
|
|
50
|
-
description: "Fetches a paginated list of shipping methods for an organization",
|
|
51
|
-
headers: HeaderSchema,
|
|
52
|
-
method: "GET",
|
|
53
|
-
operationId: "getShippingMethods",
|
|
54
|
-
path: "/:organizationId/shipping-methods",
|
|
55
|
-
pathParams: z.object({
|
|
56
|
-
organizationId: z.string().openapi({
|
|
57
|
-
description: "ID of the organization",
|
|
58
|
-
example: "cju0z9k4z0000l1qg5z1z1z1z",
|
|
59
|
-
param: {
|
|
60
|
-
in: "path",
|
|
61
|
-
name: "organizationId",
|
|
62
|
-
},
|
|
63
|
-
}),
|
|
64
|
-
}),
|
|
65
|
-
query: PaginationQuerySchema,
|
|
66
|
-
responses: {
|
|
67
|
-
200: z.object({
|
|
68
|
-
list: z.array(ShippingMethodSchema),
|
|
69
|
-
meta: PaginationMetaSchema,
|
|
70
|
-
}),
|
|
71
|
-
400: ErrorSchema,
|
|
72
|
-
401: ErrorSchema,
|
|
73
|
-
},
|
|
74
|
-
summary: "Get Shipping Methods",
|
|
75
|
-
tags: ["ShippingMethod"],
|
|
76
|
-
});
|
|
77
|
-
const createShippingMethodRoute = createApiRoute({
|
|
78
|
-
body: CreateShippingMethodSchema,
|
|
79
|
-
description: "Creates a new shipping method for an organization",
|
|
80
|
-
headers: HeaderSchema,
|
|
81
|
-
method: "POST",
|
|
82
|
-
operationId: "createShippingMethod",
|
|
83
|
-
path: "/:organizationId/shipping-methods",
|
|
84
|
-
pathParams: z.object({
|
|
85
|
-
organizationId: z.string().openapi({
|
|
86
|
-
description: "ID of the organization",
|
|
87
|
-
example: "cju0z9k4z0000l1qg5z1z1z1z",
|
|
88
|
-
param: {
|
|
89
|
-
in: "path",
|
|
90
|
-
name: "organizationId",
|
|
91
|
-
},
|
|
92
|
-
}),
|
|
93
|
-
}),
|
|
94
|
-
responses: {
|
|
95
|
-
201: ShippingMethodSchema,
|
|
96
|
-
400: ErrorSchema,
|
|
97
|
-
401: ErrorSchema,
|
|
98
|
-
404: ErrorSchema,
|
|
99
|
-
},
|
|
100
|
-
summary: "Create Shipping Method",
|
|
101
|
-
tags: ["ShippingMethod"],
|
|
102
|
-
});
|
|
103
|
-
const updateShippingMethodRoute = createApiRoute({
|
|
104
|
-
body: UpdateShippingMethodSchema,
|
|
105
|
-
description: "Updates an existing shipping method",
|
|
106
|
-
headers: HeaderSchema,
|
|
107
|
-
method: "PUT",
|
|
108
|
-
operationId: "updateShippingMethod",
|
|
109
|
-
path: "/:organizationId/shipping-methods/:id",
|
|
110
|
-
pathParams: shippingMethodPathParams,
|
|
111
|
-
responses: {
|
|
112
|
-
200: ShippingMethodSchema,
|
|
113
|
-
400: ErrorSchema,
|
|
114
|
-
401: ErrorSchema,
|
|
115
|
-
404: ErrorSchema,
|
|
116
|
-
},
|
|
117
|
-
summary: "Update Shipping Method",
|
|
118
|
-
tags: ["ShippingMethod"],
|
|
119
|
-
});
|
|
120
|
-
const deleteShippingMethodRoute = createApiRoute({
|
|
121
|
-
description: "Soft deletes a shipping method",
|
|
122
|
-
headers: HeaderSchema,
|
|
123
|
-
method: "DELETE",
|
|
124
|
-
operationId: "deleteShippingMethod",
|
|
125
|
-
path: "/:organizationId/shipping-methods/:id",
|
|
126
|
-
pathParams: shippingMethodPathParams,
|
|
127
|
-
responses: {
|
|
128
|
-
204: null,
|
|
129
|
-
400: ErrorSchema,
|
|
130
|
-
401: ErrorSchema,
|
|
131
|
-
404: ErrorSchema,
|
|
132
|
-
},
|
|
133
|
-
summary: "Delete Shipping Method",
|
|
134
|
-
tags: ["ShippingMethod"],
|
|
135
|
-
});
|
|
136
|
-
export const shippingMethodRoute = {
|
|
137
|
-
getShippingMethod: getShippingMethodRoute,
|
|
138
|
-
accessEligibility: accessEligibilityRoute,
|
|
139
|
-
getShippingMethods: getShippingMethodsRoute,
|
|
140
|
-
createShippingMethod: createShippingMethodRoute,
|
|
141
|
-
updateShippingMethod: updateShippingMethodRoute,
|
|
142
|
-
deleteShippingMethod: deleteShippingMethodRoute,
|
|
143
|
-
};
|
|
144
|
-
//# sourceMappingURL=shipping-method.route.js.map
|
|
1
|
+
import{z as i}from"@hono/zod-openapi";import{createApiRoute as e}from"../../core/hono/hono";import{CreateShippingMethodSchema as t,ErrorSchema as o,HeaderSchema as a,OrganizationParams as p,OrganizationWithIdParams as n,PaginationMetaSchema as h,PaginationQuerySchema as s,ShippingMethodSchema as d,UpdateShippingMethodSchema as r}from"../../schemas";const g=i.object({id:i.string().openapi({description:"ID of the shipping method",example:"clf9876543210abcdef",param:{in:"path",name:"id"}}),organizationId:i.string().openapi({description:"ID of the organization",example:"cju0z9k4z0000l1qg5z1z1z1z",param:{in:"path",name:"organizationId"}})}),m=e({headers:a,method:"GET",operationId:"getShippingMethod",path:"/:organizationId/shipping-methods/:id",pathParams:n,responses:{200:d,401:o,404:o},summary:"Get Shipping Method",tags:["ShippingMethod"]}),z=e({description:"Fetches a list of published shipping methods a user can use",headers:a,method:"GET",operationId:"accessEligibility",path:"/:organizationId/shipping-methods/access/eligibility",pathParams:p,responses:{200:i.array(d)},summary:"Get Eligible Shipping Methods",tags:["ShippingMethod"]}),c=e({description:"Fetches a paginated list of shipping methods for an organization",headers:a,method:"GET",operationId:"getShippingMethods",path:"/:organizationId/shipping-methods",pathParams:i.object({organizationId:i.string().openapi({description:"ID of the organization",example:"cju0z9k4z0000l1qg5z1z1z1z",param:{in:"path",name:"organizationId"}})}),query:s,responses:{200:i.object({list:i.array(d),meta:h}),400:o,401:o},summary:"Get Shipping Methods",tags:["ShippingMethod"]}),l=e({body:t,description:"Creates a new shipping method for an organization",headers:a,method:"POST",operationId:"createShippingMethod",path:"/:organizationId/shipping-methods",pathParams:i.object({organizationId:i.string().openapi({description:"ID of the organization",example:"cju0z9k4z0000l1qg5z1z1z1z",param:{in:"path",name:"organizationId"}})}),responses:{201:d,400:o,401:o,404:o},summary:"Create Shipping Method",tags:["ShippingMethod"]}),S=e({body:r,description:"Updates an existing shipping method",headers:a,method:"PUT",operationId:"updateShippingMethod",path:"/:organizationId/shipping-methods/:id",pathParams:g,responses:{200:d,400:o,401:o,404:o},summary:"Update Shipping Method",tags:["ShippingMethod"]}),M=e({description:"Soft deletes a shipping method",headers:a,method:"DELETE",operationId:"deleteShippingMethod",path:"/:organizationId/shipping-methods/:id",pathParams:g,responses:{204:null,400:o,401:o,404:o},summary:"Delete Shipping Method",tags:["ShippingMethod"]});export const shippingMethodRoute={getShippingMethod:m,accessEligibility:z,getShippingMethods:c,createShippingMethod:l,updateShippingMethod:S,deleteShippingMethod:M};
|
|
@@ -1,48 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { FileSchema } from "../file/file.schema";
|
|
3
|
-
import { ShippingZoneSchema } from "./shipping-zone.schema";
|
|
4
|
-
export const ShippingMethodSchema = z
|
|
5
|
-
.object({
|
|
6
|
-
id: z.string().openapi({
|
|
7
|
-
example: "clf9876543210abcdef",
|
|
8
|
-
description: "ID of the shipping method",
|
|
9
|
-
}),
|
|
10
|
-
title: z.string().min(1, "Title is required").openapi({
|
|
11
|
-
example: "Standard Shipping",
|
|
12
|
-
description: "Title of the shipping method",
|
|
13
|
-
}),
|
|
14
|
-
providerName: z.string().min(1, "Provider name is required").openapi({
|
|
15
|
-
example: "FedEx",
|
|
16
|
-
description: "Name of the shipping provider",
|
|
17
|
-
}),
|
|
18
|
-
providerLogo: FileSchema.nullable().optional().openapi({
|
|
19
|
-
description: "Logo of the shipping provider",
|
|
20
|
-
}),
|
|
21
|
-
requireDateOfDelivery: z.coerce.boolean().optional().openapi({
|
|
22
|
-
example: true,
|
|
23
|
-
description: "Whether the delivery time should be selected",
|
|
24
|
-
}),
|
|
25
|
-
shippingZones: z.array(ShippingZoneSchema).openapi({
|
|
26
|
-
description: "List of shipping zones for this shipping method",
|
|
27
|
-
}),
|
|
28
|
-
eligibleShippingZone: ShippingZoneSchema.optional(),
|
|
29
|
-
createdAt: z.date(),
|
|
30
|
-
updatedAt: z.date(),
|
|
31
|
-
})
|
|
32
|
-
.openapi("ShippingMethod");
|
|
33
|
-
export const CreateShippingMethodSchema = ShippingMethodSchema.pick({
|
|
34
|
-
title: true,
|
|
35
|
-
providerName: true,
|
|
36
|
-
providerLogo: true,
|
|
37
|
-
requireDateOfDelivery: true,
|
|
38
|
-
shippingZones: true,
|
|
39
|
-
})
|
|
40
|
-
.extend({
|
|
41
|
-
providerLogoId: z.string().cuid().optional().openapi({
|
|
42
|
-
example: "clf9876543210abcdef",
|
|
43
|
-
description: "ID reference to the provider logo file",
|
|
44
|
-
}),
|
|
45
|
-
})
|
|
46
|
-
.openapi("CreateShippingMethod");
|
|
47
|
-
export const UpdateShippingMethodSchema = CreateShippingMethodSchema.partial().openapi("UpdateShippingMethod");
|
|
48
|
-
//# sourceMappingURL=shipping-method.schema.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{FileSchema as i}from"../file/file.schema";import{ShippingZoneSchema as p}from"./shipping-zone.schema";export const ShippingMethodSchema=e.object({id:e.string().openapi({example:"clf9876543210abcdef",description:"ID of the shipping method"}),title:e.string().min(1,"Title is required").openapi({example:"Standard Shipping",description:"Title of the shipping method"}),providerName:e.string().min(1,"Provider name is required").openapi({example:"FedEx",description:"Name of the shipping provider"}),providerLogo:i.nullable().optional().openapi({description:"Logo of the shipping provider"}),requireDateOfDelivery:e.coerce.boolean().optional().openapi({example:!0,description:"Whether the delivery time should be selected"}),shippingZones:e.array(p).openapi({description:"List of shipping zones for this shipping method"}),eligibleShippingZone:p.optional(),createdAt:e.date(),updatedAt:e.date()}).openapi("ShippingMethod");export const CreateShippingMethodSchema=ShippingMethodSchema.pick({title:!0,providerName:!0,providerLogo:!0,requireDateOfDelivery:!0,shippingZones:!0}).extend({providerLogoId:e.string().cuid().optional().openapi({example:"clf9876543210abcdef",description:"ID reference to the provider logo file"})}).openapi("CreateShippingMethod");export const UpdateShippingMethodSchema=CreateShippingMethodSchema.partial().openapi("UpdateShippingMethod");
|
|
@@ -4,18 +4,8 @@ import { CreateShippingMethodSchema, UpdateShippingMethodSchema, User } from "..
|
|
|
4
4
|
declare class ShippingMethodService {
|
|
5
5
|
private readonly prisma;
|
|
6
6
|
constructor(prisma: PrismaClientType);
|
|
7
|
-
/**
|
|
8
|
-
* Find a shipping method by ID and organization ID
|
|
9
|
-
* @throws HttpException with 404 status if shipping method is not found
|
|
10
|
-
*/
|
|
11
7
|
private findShippingMethod;
|
|
12
|
-
/**
|
|
13
|
-
* Find the distance between two coordinates
|
|
14
|
-
*/
|
|
15
8
|
private findDistanceBetweenCoordinates;
|
|
16
|
-
/**
|
|
17
|
-
* Get a list of eligible shipping methods for a user
|
|
18
|
-
*/
|
|
19
9
|
accessEligibility(user: User, organizationId: string): Promise<{
|
|
20
10
|
id: string;
|
|
21
11
|
title: string;
|
|
@@ -47,9 +37,6 @@ declare class ShippingMethodService {
|
|
|
47
37
|
id?: string | undefined;
|
|
48
38
|
} | undefined;
|
|
49
39
|
}[]>;
|
|
50
|
-
/**
|
|
51
|
-
* Create a new shipping method
|
|
52
|
-
*/
|
|
53
40
|
createShippingMethod(organizationId: string, userId: string, body: z.infer<typeof CreateShippingMethodSchema>): Promise<{
|
|
54
41
|
id: string;
|
|
55
42
|
title: string;
|
|
@@ -81,9 +68,6 @@ declare class ShippingMethodService {
|
|
|
81
68
|
id?: string | undefined;
|
|
82
69
|
} | undefined;
|
|
83
70
|
}>;
|
|
84
|
-
/**
|
|
85
|
-
* Get a shipping method by ID
|
|
86
|
-
*/
|
|
87
71
|
getShippingMethod(organizationId: string, id: string): Promise<{
|
|
88
72
|
id: string;
|
|
89
73
|
title: string;
|
|
@@ -115,9 +99,6 @@ declare class ShippingMethodService {
|
|
|
115
99
|
id?: string | undefined;
|
|
116
100
|
} | undefined;
|
|
117
101
|
}>;
|
|
118
|
-
/**
|
|
119
|
-
* Get a paginated list of shipping methods
|
|
120
|
-
*/
|
|
121
102
|
getShippingMethods(organizationId: string, query: {
|
|
122
103
|
page?: number;
|
|
123
104
|
limit?: number;
|
|
@@ -164,9 +145,6 @@ declare class ShippingMethodService {
|
|
|
164
145
|
} | undefined;
|
|
165
146
|
}[];
|
|
166
147
|
}>;
|
|
167
|
-
/**
|
|
168
|
-
* Update a shipping method
|
|
169
|
-
*/
|
|
170
148
|
updateShippingMethod(organizationId: string, id: string, userId: string, body: z.infer<typeof UpdateShippingMethodSchema>): Promise<{
|
|
171
149
|
id: string;
|
|
172
150
|
title: string;
|
|
@@ -198,9 +176,6 @@ declare class ShippingMethodService {
|
|
|
198
176
|
id?: string | undefined;
|
|
199
177
|
} | undefined;
|
|
200
178
|
}>;
|
|
201
|
-
/**
|
|
202
|
-
* Delete a shipping method (soft delete)
|
|
203
|
-
*/
|
|
204
179
|
deleteShippingMethod(organizationId: string, id: string, userId: string): Promise<void>;
|
|
205
180
|
}
|
|
206
181
|
export { ShippingMethodService };
|
|
@@ -1,229 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { z } from "@hono/zod-openapi";
|
|
3
|
-
import { HttpException } from "../../core/exceptions/http-exception";
|
|
4
|
-
import { PaginationMetaSchema, ShippingMethodSchema, } from "../../schemas";
|
|
5
|
-
class ShippingMethodService {
|
|
6
|
-
constructor(prisma) {
|
|
7
|
-
this.prisma = prisma;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Find a shipping method by ID and organization ID
|
|
11
|
-
* @throws HttpException with 404 status if shipping method is not found
|
|
12
|
-
*/
|
|
13
|
-
findShippingMethod(id, organizationId, options) {
|
|
14
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
const shippingMethod = yield this.prisma.shippingMethod.findUnique({
|
|
16
|
-
where: {
|
|
17
|
-
id,
|
|
18
|
-
organizationId,
|
|
19
|
-
},
|
|
20
|
-
include: options === null || options === void 0 ? void 0 : options.include,
|
|
21
|
-
});
|
|
22
|
-
if (!shippingMethod) {
|
|
23
|
-
throw new HttpException(404, "Shipping method not found");
|
|
24
|
-
}
|
|
25
|
-
return shippingMethod;
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Find the distance between two coordinates
|
|
30
|
-
*/
|
|
31
|
-
findDistanceBetweenCoordinates(from, to) {
|
|
32
|
-
// Helper function to convert degrees to radians
|
|
33
|
-
const toRadians = (degrees) => degrees * (Math.PI / 180);
|
|
34
|
-
// Earth's radius in kilometers
|
|
35
|
-
const earthRadiusKm = 6371;
|
|
36
|
-
// Convert latitude and longitude differences to radians
|
|
37
|
-
const dLat = toRadians(to.latitude - from.latitude);
|
|
38
|
-
const dLon = toRadians(to.longitude - from.longitude);
|
|
39
|
-
// Convert starting coordinates to radians
|
|
40
|
-
const lat1 = toRadians(from.latitude);
|
|
41
|
-
const lat2 = toRadians(to.latitude);
|
|
42
|
-
// Haversine formula
|
|
43
|
-
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
|
|
44
|
-
Math.cos(lat1) * Math.cos(lat2) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
|
|
45
|
-
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
46
|
-
// Calculate the distance
|
|
47
|
-
const distance = earthRadiusKm * c;
|
|
48
|
-
return distance;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Get a list of eligible shipping methods for a user
|
|
52
|
-
*/
|
|
53
|
-
accessEligibility(user, organizationId) {
|
|
54
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
const organization = yield this.prisma.organization.findUnique({
|
|
56
|
-
where: {
|
|
57
|
-
id: organizationId,
|
|
58
|
-
},
|
|
59
|
-
include: {
|
|
60
|
-
address: true,
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
if (!organization) {
|
|
64
|
-
throw new HttpException(404, "Organization not found");
|
|
65
|
-
}
|
|
66
|
-
const userShippingAddress = yield this.prisma.address.findFirst({
|
|
67
|
-
where: {
|
|
68
|
-
users: {
|
|
69
|
-
some: { id: user.id },
|
|
70
|
-
},
|
|
71
|
-
isDefault: true,
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
if (!userShippingAddress) {
|
|
75
|
-
throw new HttpException(404, "User shipping address not found");
|
|
76
|
-
}
|
|
77
|
-
const shippingMethods = yield this.prisma.shippingMethod.findMany({
|
|
78
|
-
where: {
|
|
79
|
-
organizationId,
|
|
80
|
-
},
|
|
81
|
-
include: {
|
|
82
|
-
shippingZones: true,
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
return shippingMethods.map((shippingMethod) => {
|
|
86
|
-
const distance = this.findDistanceBetweenCoordinates({
|
|
87
|
-
latitude: organization.address.latitude,
|
|
88
|
-
longitude: organization.address.longitude,
|
|
89
|
-
}, {
|
|
90
|
-
latitude: userShippingAddress.latitude,
|
|
91
|
-
longitude: userShippingAddress.longitude,
|
|
92
|
-
});
|
|
93
|
-
const eligibleShippingZone = shippingMethod.shippingZones.find(({ distanceUpto }) => {
|
|
94
|
-
return distance <= distanceUpto;
|
|
95
|
-
});
|
|
96
|
-
return ShippingMethodSchema.parse(Object.assign(Object.assign({}, shippingMethod), { eligibleShippingZone }));
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Create a new shipping method
|
|
102
|
-
*/
|
|
103
|
-
createShippingMethod(organizationId, userId, body) {
|
|
104
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
const shippingMethod = yield this.prisma.shippingMethod.create({
|
|
106
|
-
data: {
|
|
107
|
-
title: body.title,
|
|
108
|
-
providerName: body.providerName,
|
|
109
|
-
providerLogoId: body.providerLogoId,
|
|
110
|
-
requireDateOfDelivery: body.requireDateOfDelivery,
|
|
111
|
-
organizationId,
|
|
112
|
-
shippingZones: {
|
|
113
|
-
create: body.shippingZones,
|
|
114
|
-
},
|
|
115
|
-
createdBy: userId,
|
|
116
|
-
},
|
|
117
|
-
include: {
|
|
118
|
-
shippingZones: true,
|
|
119
|
-
providerLogo: true,
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
return ShippingMethodSchema.parse(shippingMethod);
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Get a shipping method by ID
|
|
127
|
-
*/
|
|
128
|
-
getShippingMethod(organizationId, id) {
|
|
129
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
-
const shippingMethod = yield this.findShippingMethod(id, organizationId, {
|
|
131
|
-
include: {
|
|
132
|
-
providerLogo: true,
|
|
133
|
-
shippingZones: true,
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
return ShippingMethodSchema.parse(shippingMethod);
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Get a paginated list of shipping methods
|
|
141
|
-
*/
|
|
142
|
-
getShippingMethods(organizationId, query) {
|
|
143
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
-
const { page = 1, limit = 10, search } = query;
|
|
145
|
-
const [list, meta] = yield this.prisma.shippingMethod
|
|
146
|
-
.paginate({
|
|
147
|
-
orderBy: {
|
|
148
|
-
createdAt: "desc",
|
|
149
|
-
},
|
|
150
|
-
where: Object.assign({ organizationId }, (search && {
|
|
151
|
-
title: {
|
|
152
|
-
contains: search,
|
|
153
|
-
mode: "insensitive",
|
|
154
|
-
},
|
|
155
|
-
})),
|
|
156
|
-
include: {
|
|
157
|
-
shippingZones: true,
|
|
158
|
-
providerLogo: true,
|
|
159
|
-
},
|
|
160
|
-
})
|
|
161
|
-
.withPages({
|
|
162
|
-
page,
|
|
163
|
-
limit,
|
|
164
|
-
});
|
|
165
|
-
return z
|
|
166
|
-
.object({
|
|
167
|
-
meta: PaginationMetaSchema,
|
|
168
|
-
list: z.array(ShippingMethodSchema),
|
|
169
|
-
})
|
|
170
|
-
.parse({
|
|
171
|
-
meta,
|
|
172
|
-
list,
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Update a shipping method
|
|
178
|
-
*/
|
|
179
|
-
updateShippingMethod(organizationId, id, userId, body) {
|
|
180
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
-
// Ensure the shipping method exists
|
|
182
|
-
yield this.findShippingMethod(id, organizationId);
|
|
183
|
-
const updatedShippingMethod = yield this.prisma.shippingMethod.update({
|
|
184
|
-
where: {
|
|
185
|
-
id,
|
|
186
|
-
organizationId,
|
|
187
|
-
},
|
|
188
|
-
data: {
|
|
189
|
-
title: body.title,
|
|
190
|
-
providerName: body.providerName,
|
|
191
|
-
providerLogoId: body.providerLogoId,
|
|
192
|
-
requireDateOfDelivery: body.requireDateOfDelivery,
|
|
193
|
-
shippingZones: {
|
|
194
|
-
deleteMany: {},
|
|
195
|
-
create: body.shippingZones,
|
|
196
|
-
},
|
|
197
|
-
updatedBy: userId,
|
|
198
|
-
},
|
|
199
|
-
include: {
|
|
200
|
-
providerLogo: true,
|
|
201
|
-
shippingZones: true,
|
|
202
|
-
},
|
|
203
|
-
});
|
|
204
|
-
return ShippingMethodSchema.parse(updatedShippingMethod);
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Delete a shipping method (soft delete)
|
|
209
|
-
*/
|
|
210
|
-
deleteShippingMethod(organizationId, id, userId) {
|
|
211
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
212
|
-
// Ensure the shipping method exists
|
|
213
|
-
yield this.findShippingMethod(id, organizationId);
|
|
214
|
-
yield this.prisma.shippingMethod.update({
|
|
215
|
-
where: {
|
|
216
|
-
id,
|
|
217
|
-
organizationId,
|
|
218
|
-
},
|
|
219
|
-
data: {
|
|
220
|
-
archivedAt: new Date(),
|
|
221
|
-
archivedBy: userId,
|
|
222
|
-
},
|
|
223
|
-
});
|
|
224
|
-
return;
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
export { ShippingMethodService };
|
|
229
|
-
//# sourceMappingURL=shipping-method.service.js.map
|
|
1
|
+
import{__awaiter as i}from"tslib";import{z as e}from"@hono/zod-openapi";import{HttpException as t}from"../../core/exceptions/http-exception";import{PaginationMetaSchema as n,ShippingMethodSchema as o}from"../../schemas";class d{constructor(i){this.prisma=i}findShippingMethod(e,n,o){return i(this,void 0,void 0,function*(){const i=yield this.prisma.shippingMethod.findUnique({where:{id:e,organizationId:n},include:null==o?void 0:o.include});if(!i)throw new t(404,"Shipping method not found");return i})}findDistanceBetweenCoordinates(i,e){const t=i=>i*(Math.PI/180),n=t(e.latitude-i.latitude),o=t(e.longitude-i.longitude),d=t(i.latitude),r=t(e.latitude),s=Math.sin(n/2)*Math.sin(n/2)+Math.cos(d)*Math.cos(r)*Math.sin(o/2)*Math.sin(o/2);return 2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s))*6371}accessEligibility(e,n){return i(this,void 0,void 0,function*(){const i=yield this.prisma.organization.findUnique({where:{id:n},include:{address:!0}});if(!i)throw new t(404,"Organization not found");const d=yield this.prisma.address.findFirst({where:{users:{some:{id:e.id}},isDefault:!0}});if(!d)throw new t(404,"User shipping address not found");return(yield this.prisma.shippingMethod.findMany({where:{organizationId:n},include:{shippingZones:!0}})).map(e=>{const t=this.findDistanceBetweenCoordinates({latitude:i.address.latitude,longitude:i.address.longitude},{latitude:d.latitude,longitude:d.longitude}),n=e.shippingZones.find(({distanceUpto:i})=>t<=i);return o.parse(Object.assign(Object.assign({},e),{eligibleShippingZone:n}))})})}createShippingMethod(e,t,n){return i(this,void 0,void 0,function*(){const i=yield this.prisma.shippingMethod.create({data:{title:n.title,providerName:n.providerName,providerLogoId:n.providerLogoId,requireDateOfDelivery:n.requireDateOfDelivery,organizationId:e,shippingZones:{create:n.shippingZones},createdBy:t},include:{shippingZones:!0,providerLogo:!0}});return o.parse(i)})}getShippingMethod(e,t){return i(this,void 0,void 0,function*(){const i=yield this.findShippingMethod(t,e,{include:{providerLogo:!0,shippingZones:!0}});return o.parse(i)})}getShippingMethods(t,d){return i(this,void 0,void 0,function*(){const{page:i=1,limit:r=10,search:s}=d,[a,p]=yield this.prisma.shippingMethod.paginate({orderBy:{createdAt:"desc"},where:Object.assign({organizationId:t},s&&{title:{contains:s,mode:"insensitive"}}),include:{shippingZones:!0,providerLogo:!0}}).withPages({page:i,limit:r});return e.object({meta:n,list:e.array(o)}).parse({meta:p,list:a})})}updateShippingMethod(e,t,n,d){return i(this,void 0,void 0,function*(){yield this.findShippingMethod(t,e);const i=yield this.prisma.shippingMethod.update({where:{id:t,organizationId:e},data:{title:d.title,providerName:d.providerName,providerLogoId:d.providerLogoId,requireDateOfDelivery:d.requireDateOfDelivery,shippingZones:{deleteMany:{},create:d.shippingZones},updatedBy:n},include:{providerLogo:!0,shippingZones:!0}});return o.parse(i)})}deleteShippingMethod(e,t,n){return i(this,void 0,void 0,function*(){yield this.findShippingMethod(t,e),yield this.prisma.shippingMethod.update({where:{id:t,organizationId:e},data:{archivedAt:new Date,archivedBy:n}})})}}export{d as ShippingMethodService};
|
|
@@ -1,31 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { optionalNumber, requiredNumber } from "../../schemas/number.schema";
|
|
3
|
-
export const ShippingZoneSchema = z
|
|
4
|
-
.object({
|
|
5
|
-
id: z.string().optional().openapi({
|
|
6
|
-
example: "clf9876543210abcdef",
|
|
7
|
-
description: "ID of the shipping zone",
|
|
8
|
-
}),
|
|
9
|
-
title: z.string().min(1, "Title is required").openapi({
|
|
10
|
-
example: "Zone 1",
|
|
11
|
-
description: "Title of the shipping zone",
|
|
12
|
-
}),
|
|
13
|
-
distanceUpto: requiredNumber.openapi({
|
|
14
|
-
example: 10,
|
|
15
|
-
description: "Ending distance for the shipping zone",
|
|
16
|
-
}),
|
|
17
|
-
price: requiredNumber.openapi({
|
|
18
|
-
example: 5.99,
|
|
19
|
-
description: "Price for shipping in this zone",
|
|
20
|
-
}),
|
|
21
|
-
minimumOrderAmount: optionalNumber.openapi({
|
|
22
|
-
example: 50,
|
|
23
|
-
description: "Minimum order amount for this shipping zone",
|
|
24
|
-
}),
|
|
25
|
-
eta: z.string().min(1, "ETA is required").openapi({
|
|
26
|
-
example: "2-3 days",
|
|
27
|
-
description: "Estimated time of arrival for this shipping zone",
|
|
28
|
-
}),
|
|
29
|
-
})
|
|
30
|
-
.openapi("ShippingZone");
|
|
31
|
-
//# sourceMappingURL=shipping-zone.schema.js.map
|
|
1
|
+
import{z as i}from"@hono/zod-openapi";import{optionalNumber as e,requiredNumber as p}from"../../schemas/number.schema";export const ShippingZoneSchema=i.object({id:i.string().optional().openapi({example:"clf9876543210abcdef",description:"ID of the shipping zone"}),title:i.string().min(1,"Title is required").openapi({example:"Zone 1",description:"Title of the shipping zone"}),distanceUpto:p.openapi({example:10,description:"Ending distance for the shipping zone"}),price:p.openapi({example:5.99,description:"Price for shipping in this zone"}),minimumOrderAmount:e.openapi({example:50,description:"Minimum order amount for this shipping zone"}),eta:i.string().min(1,"ETA is required").openapi({example:"2-3 days",description:"Estimated time of arrival for this shipping zone"})}).openapi("ShippingZone");
|
|
@@ -1,50 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HttpException } from "../../core/exceptions/http-exception";
|
|
3
|
-
import { createApiRouter } from "../../core/hono/hono";
|
|
4
|
-
import { PaymentService, } from "../payment/payment.service";
|
|
5
|
-
import { webhookRoutes } from "./webhook.route";
|
|
6
|
-
export const webhookHandler = (request, prisma, options, provider) => __awaiter(void 0, void 0, void 0, function* () {
|
|
7
|
-
try {
|
|
8
|
-
const signature = request.headers.get("stripe-signature");
|
|
9
|
-
const body = yield request.text();
|
|
10
|
-
const paymentProvider = provider !== null && provider !== void 0 ? provider : (request.url.includes("stripe")
|
|
11
|
-
? "stripe"
|
|
12
|
-
: request.url.includes("revolut")
|
|
13
|
-
? "revolut"
|
|
14
|
-
: null);
|
|
15
|
-
if (!paymentProvider) {
|
|
16
|
-
throw new HttpException(400, "Payment provider not supported");
|
|
17
|
-
}
|
|
18
|
-
const paymentService = new PaymentService(prisma, options);
|
|
19
|
-
yield paymentService.processWebhookEvent(paymentProvider, signature, body);
|
|
20
|
-
return Response.json({
|
|
21
|
-
received: true,
|
|
22
|
-
}, {
|
|
23
|
-
status: 200,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
console.error(error);
|
|
28
|
-
if (error instanceof HttpException) {
|
|
29
|
-
return Response.json({
|
|
30
|
-
error: error.message,
|
|
31
|
-
}, {
|
|
32
|
-
status: error.status,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return Response.json({
|
|
36
|
-
error: "Internal Server Error",
|
|
37
|
-
}, {
|
|
38
|
-
status: 500,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
export const buildWebhookHandler = (prisma, options) => {
|
|
43
|
-
const app = createApiRouter();
|
|
44
|
-
app.openapi(webhookRoutes.webhook, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
-
const params = c.req.valid("param");
|
|
46
|
-
return webhookHandler(c.req.raw, prisma, options, params.provider);
|
|
47
|
-
}));
|
|
48
|
-
return app;
|
|
49
|
-
};
|
|
50
|
-
//# sourceMappingURL=webhook.handler.js.map
|
|
1
|
+
import{__awaiter as e}from"tslib";import{HttpException as o}from"../../core/exceptions/http-exception";import{createApiRouter as r}from"../../core/hono/hono";import{PaymentService as t}from"../payment/payment.service";import{webhookRoutes as n}from"./webhook.route";export const webhookHandler=(r,n,s,i)=>e(void 0,void 0,void 0,function*(){try{const e=r.headers.get("stripe-signature"),p=yield r.text(),u=null!=i?i:r.url.includes("stripe")?"stripe":r.url.includes("revolut")?"revolut":null;if(!u)throw new o(400,"Payment provider not supported");const a=new t(n,s);return yield a.processWebhookEvent(u,e,p),Response.json({received:!0},{status:200})}catch(e){return console.error(e),e instanceof o?Response.json({error:e.message},{status:e.status}):Response.json({error:"Internal Server Error"},{status:500})}});export const buildWebhookHandler=(o,t)=>{const s=r();return s.openapi(n.webhook,r=>e(void 0,void 0,void 0,function*(){const e=r.req.valid("param");return webhookHandler(r.req.raw,o,t,e.provider)})),s};
|
|
@@ -1,33 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createApiRoute } from "../../core/hono/hono";
|
|
3
|
-
import { ErrorSchema } from "../../schemas";
|
|
4
|
-
const webhookRoute = createApiRoute({
|
|
5
|
-
description: "Receive webhook events from payment providers",
|
|
6
|
-
method: "POST",
|
|
7
|
-
operationId: "webhook",
|
|
8
|
-
path: "/webhook/payment/:provider",
|
|
9
|
-
pathParams: z.object({
|
|
10
|
-
provider: z.enum(["stripe", "revolut"]).openapi({
|
|
11
|
-
description: "Payment provider",
|
|
12
|
-
example: "stripe",
|
|
13
|
-
param: {
|
|
14
|
-
in: "path",
|
|
15
|
-
name: "provider",
|
|
16
|
-
},
|
|
17
|
-
}),
|
|
18
|
-
}),
|
|
19
|
-
responses: {
|
|
20
|
-
200: z.object({
|
|
21
|
-
received: z.boolean(),
|
|
22
|
-
}),
|
|
23
|
-
400: ErrorSchema,
|
|
24
|
-
401: ErrorSchema,
|
|
25
|
-
500: ErrorSchema,
|
|
26
|
-
},
|
|
27
|
-
summary: "Process Event",
|
|
28
|
-
tags: ["Webhook"],
|
|
29
|
-
});
|
|
30
|
-
export const webhookRoutes = {
|
|
31
|
-
webhook: webhookRoute,
|
|
32
|
-
};
|
|
33
|
-
//# sourceMappingURL=webhook.route.js.map
|
|
1
|
+
import{z as o}from"@hono/zod-openapi";import{createApiRoute as e}from"../../core/hono/hono";import{ErrorSchema as r}from"../../schemas";const p=e({description:"Receive webhook events from payment providers",method:"POST",operationId:"webhook",path:"/webhook/payment/:provider",pathParams:o.object({provider:o.enum(["stripe","revolut"]).openapi({description:"Payment provider",example:"stripe",param:{in:"path",name:"provider"}})}),responses:{200:o.object({received:o.boolean()}),400:r,401:r,500:r},summary:"Process Event",tags:["Webhook"]});export const webhookRoutes={webhook:p};
|
package/src/index.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./features";
|
|
3
|
-
export { buildApiApp } from "./app";
|
|
4
|
-
export { generateOpenApiSpec } from "./core/openapi/openapi.lib";
|
|
5
|
-
export { CartItemSchema } from "./features/cart/cart.schema";
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export*from"./schemas";export*from"./features";export{buildApiApp}from"./app";export{generateOpenApiSpec}from"./core/openapi/openapi.lib";export{CartItemSchema}from"./features/cart/cart.schema";
|