@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
|
@@ -5,9 +5,6 @@ declare class ReservationService {
|
|
|
5
5
|
private readonly prisma;
|
|
6
6
|
private emailService;
|
|
7
7
|
constructor(prisma: PrismaClientType, resendApiKey: string);
|
|
8
|
-
/**
|
|
9
|
-
* Create a new reservation
|
|
10
|
-
*/
|
|
11
8
|
createReservation(organizationId: string, user: User | null, body: z.infer<typeof CreateReservationSchema>): Promise<{
|
|
12
9
|
id: string;
|
|
13
10
|
firstname: string;
|
|
@@ -20,9 +17,6 @@ declare class ReservationService {
|
|
|
20
17
|
cancelledAt?: Date | null | undefined;
|
|
21
18
|
createdAt?: Date | null | undefined;
|
|
22
19
|
}>;
|
|
23
|
-
/**
|
|
24
|
-
* Get a specific reservation by ID
|
|
25
|
-
*/
|
|
26
20
|
getReservation(user: User, organizationId: string, reservationId: string): Promise<{
|
|
27
21
|
id: string;
|
|
28
22
|
firstname: string;
|
|
@@ -35,9 +29,6 @@ declare class ReservationService {
|
|
|
35
29
|
cancelledAt?: Date | null | undefined;
|
|
36
30
|
createdAt?: Date | null | undefined;
|
|
37
31
|
}>;
|
|
38
|
-
/**
|
|
39
|
-
* Get all reservations for an organization
|
|
40
|
-
*/
|
|
41
32
|
getReservations(organizationId: string, query: {
|
|
42
33
|
page?: number;
|
|
43
34
|
limit?: number;
|
|
@@ -66,9 +57,6 @@ declare class ReservationService {
|
|
|
66
57
|
createdAt?: Date | null | undefined;
|
|
67
58
|
}[];
|
|
68
59
|
}>;
|
|
69
|
-
/**
|
|
70
|
-
* Get all reservations for a user
|
|
71
|
-
*/
|
|
72
60
|
getUserReservations(userId: string, organizationId: string): Promise<{
|
|
73
61
|
id: string;
|
|
74
62
|
firstname: string;
|
|
@@ -81,9 +69,6 @@ declare class ReservationService {
|
|
|
81
69
|
cancelledAt?: Date | null | undefined;
|
|
82
70
|
createdAt?: Date | null | undefined;
|
|
83
71
|
}[]>;
|
|
84
|
-
/**
|
|
85
|
-
* Update reservation status
|
|
86
|
-
*/
|
|
87
72
|
updateStatus(organizationId: string, reservationId: string, operation: "accept" | "cancel"): Promise<{
|
|
88
73
|
id: string;
|
|
89
74
|
firstname: string;
|
|
@@ -96,9 +81,6 @@ declare class ReservationService {
|
|
|
96
81
|
cancelledAt?: Date | null | undefined;
|
|
97
82
|
createdAt?: Date | null | undefined;
|
|
98
83
|
}>;
|
|
99
|
-
/**
|
|
100
|
-
* Delete a reservation
|
|
101
|
-
*/
|
|
102
84
|
deleteReservation(organizationId: string, reservationId: string): Promise<void>;
|
|
103
85
|
}
|
|
104
86
|
export { ReservationService };
|
|
@@ -1,231 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { z } from "@hono/zod-openapi";
|
|
3
|
-
import { customAlphabet } from "nanoid";
|
|
4
|
-
import { HttpException } from "../../core/exceptions/http-exception";
|
|
5
|
-
import { EmailService } from "../../core/notifications/email.service";
|
|
6
|
-
import { PaginationMetaSchema, ReservationSchema, } from "../../schemas";
|
|
7
|
-
const nanoid = customAlphabet("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ", 6);
|
|
8
|
-
class ReservationService {
|
|
9
|
-
constructor(prisma, resendApiKey) {
|
|
10
|
-
this.prisma = prisma;
|
|
11
|
-
this.emailService = new EmailService(resendApiKey);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Create a new reservation
|
|
15
|
-
*/
|
|
16
|
-
createReservation(organizationId, user, body) {
|
|
17
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
const organization = yield this.prisma.organization.findFirst({
|
|
19
|
-
where: {
|
|
20
|
-
id: organizationId,
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
if (!organization) {
|
|
24
|
-
throw new HttpException(404, "Organization not found");
|
|
25
|
-
}
|
|
26
|
-
// Create the reservation
|
|
27
|
-
const reservation = yield this.prisma.reservation.create({
|
|
28
|
-
data: Object.assign({ referenceId: nanoid(), firstname: body.firstname, lastname: body.lastname, guests: body.guests, phone: body.phone, date: body.date, organization: {
|
|
29
|
-
connect: {
|
|
30
|
-
id: organizationId,
|
|
31
|
-
},
|
|
32
|
-
} }, (user
|
|
33
|
-
? {
|
|
34
|
-
user: {
|
|
35
|
-
connect: {
|
|
36
|
-
id: user.id,
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
}
|
|
40
|
-
: {})),
|
|
41
|
-
include: {
|
|
42
|
-
organization: {
|
|
43
|
-
include: {
|
|
44
|
-
address: true,
|
|
45
|
-
configuration: true,
|
|
46
|
-
logoFile: true,
|
|
47
|
-
members: {
|
|
48
|
-
include: {
|
|
49
|
-
user: true,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
user: true,
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
for (const member of reservation.organization.members) {
|
|
58
|
-
yield this.emailService.sendReservationNotificationEmail(member.user, reservation);
|
|
59
|
-
}
|
|
60
|
-
return ReservationSchema.parse(reservation);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Get a specific reservation by ID
|
|
65
|
-
*/
|
|
66
|
-
getReservation(user, organizationId, reservationId) {
|
|
67
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
const reservation = yield this.prisma.reservation.findUnique({
|
|
69
|
-
where: {
|
|
70
|
-
id: reservationId,
|
|
71
|
-
organizationId: organizationId,
|
|
72
|
-
user: {
|
|
73
|
-
id: user.id,
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
if (!reservation) {
|
|
78
|
-
throw new HttpException(404, "Reservation not found");
|
|
79
|
-
}
|
|
80
|
-
return ReservationSchema.parse(reservation);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Get all reservations for an organization
|
|
85
|
-
*/
|
|
86
|
-
getReservations(organizationId, query) {
|
|
87
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
const { page = 1, limit = 10, search } = query;
|
|
89
|
-
// Fetch reservations with pagination
|
|
90
|
-
const [list, meta] = yield this.prisma.reservation
|
|
91
|
-
.paginate({
|
|
92
|
-
orderBy: {
|
|
93
|
-
createdAt: "desc",
|
|
94
|
-
},
|
|
95
|
-
where: Object.assign({ organizationId }, (search && {
|
|
96
|
-
OR: [
|
|
97
|
-
{
|
|
98
|
-
firstname: {
|
|
99
|
-
contains: search,
|
|
100
|
-
mode: "insensitive",
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
lastname: {
|
|
105
|
-
contains: search,
|
|
106
|
-
mode: "insensitive",
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
referenceId: {
|
|
111
|
-
contains: search,
|
|
112
|
-
mode: "insensitive",
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
})),
|
|
117
|
-
include: {
|
|
118
|
-
user: true,
|
|
119
|
-
},
|
|
120
|
-
})
|
|
121
|
-
.withPages({
|
|
122
|
-
page,
|
|
123
|
-
limit,
|
|
124
|
-
});
|
|
125
|
-
return z
|
|
126
|
-
.object({
|
|
127
|
-
meta: PaginationMetaSchema,
|
|
128
|
-
list: z.array(ReservationSchema),
|
|
129
|
-
})
|
|
130
|
-
.parse({
|
|
131
|
-
meta,
|
|
132
|
-
list,
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Get all reservations for a user
|
|
138
|
-
*/
|
|
139
|
-
getUserReservations(userId, organizationId) {
|
|
140
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
-
const reservations = yield this.prisma.reservation.findMany({
|
|
142
|
-
where: {
|
|
143
|
-
organizationId: organizationId,
|
|
144
|
-
userId: userId,
|
|
145
|
-
},
|
|
146
|
-
});
|
|
147
|
-
return z.array(ReservationSchema).parse(reservations);
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Update reservation status
|
|
152
|
-
*/
|
|
153
|
-
updateStatus(organizationId, reservationId, operation) {
|
|
154
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
-
const reservation = yield this.prisma.reservation.findUnique({
|
|
156
|
-
where: {
|
|
157
|
-
id: reservationId,
|
|
158
|
-
organizationId: organizationId,
|
|
159
|
-
},
|
|
160
|
-
});
|
|
161
|
-
if (!reservation) {
|
|
162
|
-
throw new HttpException(404, "Reservation not found");
|
|
163
|
-
}
|
|
164
|
-
let updateData = {};
|
|
165
|
-
switch (operation) {
|
|
166
|
-
case "accept":
|
|
167
|
-
updateData = {
|
|
168
|
-
acceptedAt: new Date(),
|
|
169
|
-
};
|
|
170
|
-
break;
|
|
171
|
-
case "cancel":
|
|
172
|
-
updateData = {
|
|
173
|
-
cancelledAt: new Date(),
|
|
174
|
-
};
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
const updatedReservation = yield this.prisma.reservation.update({
|
|
178
|
-
where: {
|
|
179
|
-
id: reservationId,
|
|
180
|
-
},
|
|
181
|
-
data: updateData,
|
|
182
|
-
include: {
|
|
183
|
-
organization: {
|
|
184
|
-
include: {
|
|
185
|
-
address: true,
|
|
186
|
-
configuration: true,
|
|
187
|
-
logoFile: true,
|
|
188
|
-
members: {
|
|
189
|
-
include: {
|
|
190
|
-
user: true,
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
user: true,
|
|
196
|
-
},
|
|
197
|
-
});
|
|
198
|
-
if (operation === "cancel") {
|
|
199
|
-
yield this.emailService.sendReservationCancellationEmail(updatedReservation);
|
|
200
|
-
}
|
|
201
|
-
if (operation === "accept") {
|
|
202
|
-
yield this.emailService.sendReservationConfirmationEmail(updatedReservation);
|
|
203
|
-
}
|
|
204
|
-
return ReservationSchema.parse(updatedReservation);
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Delete a reservation
|
|
209
|
-
*/
|
|
210
|
-
deleteReservation(organizationId, reservationId) {
|
|
211
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
212
|
-
const reservation = yield this.prisma.reservation.findUnique({
|
|
213
|
-
where: {
|
|
214
|
-
id: reservationId,
|
|
215
|
-
organizationId: organizationId,
|
|
216
|
-
},
|
|
217
|
-
});
|
|
218
|
-
if (!reservation) {
|
|
219
|
-
throw new HttpException(404, "Reservation not found");
|
|
220
|
-
}
|
|
221
|
-
yield this.prisma.reservation.delete({
|
|
222
|
-
where: {
|
|
223
|
-
id: reservationId,
|
|
224
|
-
},
|
|
225
|
-
});
|
|
226
|
-
return;
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
export { ReservationService };
|
|
231
|
-
//# sourceMappingURL=reservation.service.js.map
|
|
1
|
+
import{__awaiter as e}from"tslib";import{z as i}from"@hono/zod-openapi";import{customAlphabet as t}from"nanoid";import{HttpException as n}from"../../core/exceptions/http-exception";import{EmailService as r}from"../../core/notifications/email.service";import{PaginationMetaSchema as o,ReservationSchema as a}from"../../schemas";const s=t("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ",6);class d{constructor(e,i){this.prisma=e,this.emailService=new r(i)}createReservation(i,t,r){return e(this,void 0,void 0,function*(){if(!(yield this.prisma.organization.findFirst({where:{id:i}})))throw new n(404,"Organization not found");const e=yield this.prisma.reservation.create({data:Object.assign({referenceId:s(),firstname:r.firstname,lastname:r.lastname,guests:r.guests,phone:r.phone,date:r.date,organization:{connect:{id:i}}},t?{user:{connect:{id:t.id}}}:{}),include:{organization:{include:{address:!0,configuration:!0,logoFile:!0,members:{include:{user:!0}}}},user:!0}});for(const i of e.organization.members)yield this.emailService.sendReservationNotificationEmail(i.user,e);return a.parse(e)})}getReservation(i,t,r){return e(this,void 0,void 0,function*(){const e=yield this.prisma.reservation.findUnique({where:{id:r,organizationId:t,user:{id:i.id}}});if(!e)throw new n(404,"Reservation not found");return a.parse(e)})}getReservations(t,n){return e(this,void 0,void 0,function*(){const{page:e=1,limit:r=10,search:s}=n,[d,c]=yield this.prisma.reservation.paginate({orderBy:{createdAt:"desc"},where:Object.assign({organizationId:t},s&&{OR:[{firstname:{contains:s,mode:"insensitive"}},{lastname:{contains:s,mode:"insensitive"}},{referenceId:{contains:s,mode:"insensitive"}}]}),include:{user:!0}}).withPages({page:e,limit:r});return i.object({meta:o,list:i.array(a)}).parse({meta:c,list:d})})}getUserReservations(t,n){return e(this,void 0,void 0,function*(){const e=yield this.prisma.reservation.findMany({where:{organizationId:n,userId:t}});return i.array(a).parse(e)})}updateStatus(i,t,r){return e(this,void 0,void 0,function*(){if(!(yield this.prisma.reservation.findUnique({where:{id:t,organizationId:i}})))throw new n(404,"Reservation not found");let e={};switch(r){case"accept":e={acceptedAt:new Date};break;case"cancel":e={cancelledAt:new Date}}const o=yield this.prisma.reservation.update({where:{id:t},data:e,include:{organization:{include:{address:!0,configuration:!0,logoFile:!0,members:{include:{user:!0}}}},user:!0}});return"cancel"===r&&(yield this.emailService.sendReservationCancellationEmail(o)),"accept"===r&&(yield this.emailService.sendReservationConfirmationEmail(o)),a.parse(o)})}deleteReservation(i,t){return e(this,void 0,void 0,function*(){if(!(yield this.prisma.reservation.findUnique({where:{id:t,organizationId:i}})))throw new n(404,"Reservation not found");yield this.prisma.reservation.delete({where:{id:t}})})}}export{d as ReservationService};
|
|
@@ -1,32 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createApiRouter } from "../../core/hono/hono";
|
|
3
|
-
import { shippingRoute } from "./shipping.route";
|
|
4
|
-
import { ShippingService } from "./shipping.service";
|
|
5
|
-
export const buildShippingHandler = (prisma, googleMapsApiKey) => {
|
|
6
|
-
const app = createApiRouter();
|
|
7
|
-
app.openapi(shippingRoute.createShippingAddress, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
-
const auth = c.get("auth");
|
|
9
|
-
const body = c.req.valid("json");
|
|
10
|
-
const user = yield auth.getCurrentUser();
|
|
11
|
-
const service = new ShippingService(prisma, googleMapsApiKey);
|
|
12
|
-
const shippingAddress = yield service.createShippingAddress(user.id, body, true);
|
|
13
|
-
return c.json(shippingAddress, 201);
|
|
14
|
-
}));
|
|
15
|
-
app.openapi(shippingRoute.getShippingAddress, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
const auth = c.get("auth");
|
|
17
|
-
const user = yield auth.getCurrentUser();
|
|
18
|
-
const service = new ShippingService(prisma, googleMapsApiKey);
|
|
19
|
-
const shippingAddress = yield service.findShippingAddress(user.id, true);
|
|
20
|
-
return c.json(shippingAddress, 200);
|
|
21
|
-
}));
|
|
22
|
-
app.openapi(shippingRoute.updateShippingAddress, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
-
const auth = c.get("auth");
|
|
24
|
-
const body = c.req.valid("json");
|
|
25
|
-
const user = yield auth.getCurrentUser();
|
|
26
|
-
const service = new ShippingService(prisma, googleMapsApiKey);
|
|
27
|
-
const shippingAddress = yield service.updateShippingAddress(user.id, body);
|
|
28
|
-
return c.json(shippingAddress, 200);
|
|
29
|
-
}));
|
|
30
|
-
return app;
|
|
31
|
-
};
|
|
32
|
-
//# sourceMappingURL=shipping.handler.js.map
|
|
1
|
+
import{__awaiter as i}from"tslib";import{createApiRouter as e}from"../../core/hono/hono";import{shippingRoute as n}from"./shipping.route";import{ShippingService as o}from"./shipping.service";export const buildShippingHandler=(r,d)=>{const t=e();return t.openapi(n.createShippingAddress,e=>i(void 0,void 0,void 0,function*(){const i=e.get("auth"),n=e.req.valid("json"),t=yield i.getCurrentUser(),p=new o(r,d),s=yield p.createShippingAddress(t.id,n,!0);return e.json(s,201)})),t.openapi(n.getShippingAddress,e=>i(void 0,void 0,void 0,function*(){const i=e.get("auth"),n=yield i.getCurrentUser(),t=new o(r,d),p=yield t.findShippingAddress(n.id,!0);return e.json(p,200)})),t.openapi(n.updateShippingAddress,e=>i(void 0,void 0,void 0,function*(){const i=e.get("auth"),n=e.req.valid("json"),t=yield i.getCurrentUser(),p=new o(r,d),s=yield p.updateShippingAddress(t.id,n);return e.json(s,200)})),t};
|
|
@@ -1,51 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { CreateShippingAddressSchema, ErrorSchema, HeaderSchema, ShippingAddressSchema, UpdateShippingAddressSchema, } from "../../schemas";
|
|
3
|
-
const getShippingAddressRoute = createApiRoute({
|
|
4
|
-
description: "Get the default shipping address for the user",
|
|
5
|
-
headers: HeaderSchema,
|
|
6
|
-
method: "GET",
|
|
7
|
-
operationId: "getShippingAddress",
|
|
8
|
-
path: "/shipping",
|
|
9
|
-
responses: {
|
|
10
|
-
200: ShippingAddressSchema.nullable(),
|
|
11
|
-
401: ErrorSchema,
|
|
12
|
-
},
|
|
13
|
-
summary: "Get Shipping Address",
|
|
14
|
-
tags: ["Shipping"],
|
|
15
|
-
});
|
|
16
|
-
const createShippingAddressRoute = createApiRoute({
|
|
17
|
-
body: CreateShippingAddressSchema,
|
|
18
|
-
description: "Creates a new shipping address for the user",
|
|
19
|
-
headers: HeaderSchema,
|
|
20
|
-
method: "POST",
|
|
21
|
-
operationId: "createShippingAddress",
|
|
22
|
-
path: "/shipping",
|
|
23
|
-
responses: {
|
|
24
|
-
201: ShippingAddressSchema,
|
|
25
|
-
400: ErrorSchema,
|
|
26
|
-
401: ErrorSchema,
|
|
27
|
-
},
|
|
28
|
-
summary: "Create Shipping Address",
|
|
29
|
-
tags: ["Shipping"],
|
|
30
|
-
});
|
|
31
|
-
const updateShippingAddressRoute = createApiRoute({
|
|
32
|
-
body: UpdateShippingAddressSchema,
|
|
33
|
-
description: "Updates the shipping address for the user",
|
|
34
|
-
headers: HeaderSchema,
|
|
35
|
-
method: "PUT",
|
|
36
|
-
operationId: "updateShippingAddress",
|
|
37
|
-
path: "/shipping",
|
|
38
|
-
responses: {
|
|
39
|
-
200: ShippingAddressSchema,
|
|
40
|
-
400: ErrorSchema,
|
|
41
|
-
401: ErrorSchema,
|
|
42
|
-
},
|
|
43
|
-
summary: "Update Shipping Address",
|
|
44
|
-
tags: ["Shipping"],
|
|
45
|
-
});
|
|
46
|
-
export const shippingRoute = {
|
|
47
|
-
getShippingAddress: getShippingAddressRoute,
|
|
48
|
-
createShippingAddress: createShippingAddressRoute,
|
|
49
|
-
updateShippingAddress: updateShippingAddressRoute,
|
|
50
|
-
};
|
|
51
|
-
//# sourceMappingURL=shipping.route.js.map
|
|
1
|
+
import{createApiRoute as e}from"../../core/hono/hono";import{CreateShippingAddressSchema as s,ErrorSchema as p,HeaderSchema as i,ShippingAddressSchema as d,UpdateShippingAddressSchema as r}from"../../schemas";const t=e({description:"Get the default shipping address for the user",headers:i,method:"GET",operationId:"getShippingAddress",path:"/shipping",responses:{200:d.nullable(),401:p},summary:"Get Shipping Address",tags:["Shipping"]}),h=e({body:s,description:"Creates a new shipping address for the user",headers:i,method:"POST",operationId:"createShippingAddress",path:"/shipping",responses:{201:d,400:p,401:p},summary:"Create Shipping Address",tags:["Shipping"]}),n=e({body:r,description:"Updates the shipping address for the user",headers:i,method:"PUT",operationId:"updateShippingAddress",path:"/shipping",responses:{200:d,400:p,401:p},summary:"Update Shipping Address",tags:["Shipping"]});export const shippingRoute={getShippingAddress:t,createShippingAddress:h,updateShippingAddress:n};
|
|
@@ -4,10 +4,6 @@ declare class ShippingService {
|
|
|
4
4
|
private readonly prisma;
|
|
5
5
|
private locationService;
|
|
6
6
|
constructor(prisma: PrismaClientType, googleMapsApiKey: string);
|
|
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
|
findShippingAddress(userId: string, isDefault?: boolean): Promise<{
|
|
12
8
|
id: string;
|
|
13
9
|
addressLineOne: string;
|
|
@@ -22,9 +18,6 @@ declare class ShippingService {
|
|
|
22
18
|
zipCode?: string | undefined;
|
|
23
19
|
deliveryInstructions?: string | null | undefined;
|
|
24
20
|
} | null>;
|
|
25
|
-
/**
|
|
26
|
-
* Create a new shipping address for the user
|
|
27
|
-
*/
|
|
28
21
|
createShippingAddress(userId: string, body: CreateShippingAddressInput, isDefault?: boolean): Promise<{
|
|
29
22
|
id: string;
|
|
30
23
|
addressLineOne: string;
|
|
@@ -1,96 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HttpException } from "../../core/exceptions/http-exception";
|
|
3
|
-
import { ShippingAddressSchema, } from "../../schemas";
|
|
4
|
-
import { LocationService } from "../location/location.service";
|
|
5
|
-
class ShippingService {
|
|
6
|
-
constructor(prisma, googleMapsApiKey) {
|
|
7
|
-
this.prisma = prisma;
|
|
8
|
-
this.locationService = new LocationService(googleMapsApiKey);
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Find a shipping method by ID and organization ID
|
|
12
|
-
* @throws HttpException with 404 status if shipping method is not found
|
|
13
|
-
*/
|
|
14
|
-
findShippingAddress(userId, isDefault) {
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const shippingAddress = yield this.prisma.address.findFirst({
|
|
17
|
-
where: {
|
|
18
|
-
users: {
|
|
19
|
-
some: {
|
|
20
|
-
id: userId,
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
isDefault,
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
if (!shippingAddress) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
return ShippingAddressSchema.parse(shippingAddress);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Create a new shipping address for the user
|
|
34
|
-
*/
|
|
35
|
-
createShippingAddress(userId, body, isDefault) {
|
|
36
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
const placeDetails = yield this.locationService.getPlaceDetails(body.placeId);
|
|
38
|
-
const shippingMethod = yield this.prisma.address.create({
|
|
39
|
-
data: {
|
|
40
|
-
firstname: body.firstname,
|
|
41
|
-
lastname: body.lastname,
|
|
42
|
-
phone: body.phone,
|
|
43
|
-
addressLineOne: body.addressLineOne,
|
|
44
|
-
addressLineTwo: body.addressLineTwo,
|
|
45
|
-
doorNumber: body.doorNumber,
|
|
46
|
-
placeId: body.placeId,
|
|
47
|
-
deliveryInstructions: body.deliveryInstructions,
|
|
48
|
-
city: body.city,
|
|
49
|
-
country: body.country,
|
|
50
|
-
zipCode: body.zipCode,
|
|
51
|
-
createdBy: userId,
|
|
52
|
-
latitude: placeDetails.latitude,
|
|
53
|
-
longitude: placeDetails.longitude,
|
|
54
|
-
isDefault,
|
|
55
|
-
users: {
|
|
56
|
-
connect: {
|
|
57
|
-
id: userId,
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
return ShippingAddressSchema.parse(shippingMethod);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
updateShippingAddress(userId, body) {
|
|
66
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
const defaultShippingAddress = yield this.findShippingAddress(userId, true);
|
|
68
|
-
if (!defaultShippingAddress) {
|
|
69
|
-
throw new HttpException(400, "No default shipping address found");
|
|
70
|
-
}
|
|
71
|
-
const placeDetails = yield this.locationService.getPlaceDetails(body.placeId);
|
|
72
|
-
const shippingAddress = yield this.prisma.address.update({
|
|
73
|
-
where: { id: defaultShippingAddress.id },
|
|
74
|
-
data: {
|
|
75
|
-
firstname: body.firstname,
|
|
76
|
-
lastname: body.lastname,
|
|
77
|
-
phone: body.phone,
|
|
78
|
-
addressLineOne: body.addressLineOne,
|
|
79
|
-
addressLineTwo: body.addressLineTwo,
|
|
80
|
-
doorNumber: body.doorNumber,
|
|
81
|
-
placeId: body.placeId,
|
|
82
|
-
deliveryInstructions: body.deliveryInstructions,
|
|
83
|
-
city: body.city,
|
|
84
|
-
country: body.country,
|
|
85
|
-
zipCode: body.zipCode,
|
|
86
|
-
latitude: placeDetails.latitude,
|
|
87
|
-
longitude: placeDetails.longitude,
|
|
88
|
-
createdBy: userId,
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
return ShippingAddressSchema.parse(shippingAddress);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
export { ShippingService };
|
|
96
|
-
//# sourceMappingURL=shipping.service.js.map
|
|
1
|
+
import{__awaiter as e}from"tslib";import{HttpException as i}from"../../core/exceptions/http-exception";import{ShippingAddressSchema as t}from"../../schemas";import{LocationService as s}from"../location/location.service";class d{constructor(e,i){this.prisma=e,this.locationService=new s(i)}findShippingAddress(i,s){return e(this,void 0,void 0,function*(){const e=yield this.prisma.address.findFirst({where:{users:{some:{id:i}},isDefault:s}});return e?t.parse(e):null})}createShippingAddress(i,s,d){return e(this,void 0,void 0,function*(){const e=yield this.locationService.getPlaceDetails(s.placeId),r=yield this.prisma.address.create({data:{firstname:s.firstname,lastname:s.lastname,phone:s.phone,addressLineOne:s.addressLineOne,addressLineTwo:s.addressLineTwo,doorNumber:s.doorNumber,placeId:s.placeId,deliveryInstructions:s.deliveryInstructions,city:s.city,country:s.country,zipCode:s.zipCode,createdBy:i,latitude:e.latitude,longitude:e.longitude,isDefault:d,users:{connect:{id:i}}}});return t.parse(r)})}updateShippingAddress(s,d){return e(this,void 0,void 0,function*(){const e=yield this.findShippingAddress(s,!0);if(!e)throw new i(400,"No default shipping address found");const r=yield this.locationService.getPlaceDetails(d.placeId),n=yield this.prisma.address.update({where:{id:e.id},data:{firstname:d.firstname,lastname:d.lastname,phone:d.phone,addressLineOne:d.addressLineOne,addressLineTwo:d.addressLineTwo,doorNumber:d.doorNumber,placeId:d.placeId,deliveryInstructions:d.deliveryInstructions,city:d.city,country:d.country,zipCode:d.zipCode,latitude:r.latitude,longitude:r.longitude,createdBy:s}});return t.parse(n)})}}export{d as ShippingService};
|
|
@@ -1,60 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createApiRouter } from "../../core/hono/hono";
|
|
3
|
-
import { shippingMethodRoute } from "./shipping-method.route";
|
|
4
|
-
import { ShippingMethodService } from "./shipping-method.service";
|
|
5
|
-
export const buildShippingMethodHandler = (prisma) => {
|
|
6
|
-
const app = createApiRouter();
|
|
7
|
-
app.openapi(shippingMethodRoute.createShippingMethod, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
-
const auth = c.get("auth");
|
|
9
|
-
const params = c.req.valid("param");
|
|
10
|
-
const body = c.req.valid("json");
|
|
11
|
-
const user = yield auth.isGranted("create");
|
|
12
|
-
const service = new ShippingMethodService(prisma);
|
|
13
|
-
const shippingMethod = yield service.createShippingMethod(params.organizationId, user.id, body);
|
|
14
|
-
return c.json(shippingMethod, 201);
|
|
15
|
-
}));
|
|
16
|
-
app.openapi(shippingMethodRoute.getShippingMethod, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
-
const auth = c.get("auth");
|
|
18
|
-
const params = c.req.valid("param");
|
|
19
|
-
yield auth.isGranted("read");
|
|
20
|
-
const service = new ShippingMethodService(prisma);
|
|
21
|
-
const shippingMethod = yield service.getShippingMethod(params.organizationId, params.id);
|
|
22
|
-
return c.json(shippingMethod, 200);
|
|
23
|
-
}));
|
|
24
|
-
app.openapi(shippingMethodRoute.accessEligibility, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
-
const auth = c.get("auth");
|
|
26
|
-
const params = c.req.valid("param");
|
|
27
|
-
const user = yield auth.getCurrentUser();
|
|
28
|
-
const service = new ShippingMethodService(prisma);
|
|
29
|
-
const shippingMethods = yield service.accessEligibility(user, params.organizationId);
|
|
30
|
-
return c.json(shippingMethods, 200);
|
|
31
|
-
}));
|
|
32
|
-
app.openapi(shippingMethodRoute.getShippingMethods, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
-
const auth = c.get("auth");
|
|
34
|
-
const params = c.req.valid("param");
|
|
35
|
-
const query = c.req.valid("query");
|
|
36
|
-
yield auth.isGranted("read");
|
|
37
|
-
const service = new ShippingMethodService(prisma);
|
|
38
|
-
const result = yield service.getShippingMethods(params.organizationId, Object.assign({}, query));
|
|
39
|
-
return c.json(result, 200);
|
|
40
|
-
}));
|
|
41
|
-
app.openapi(shippingMethodRoute.updateShippingMethod, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
-
const auth = c.get("auth");
|
|
43
|
-
const params = c.req.valid("param");
|
|
44
|
-
const body = c.req.valid("json");
|
|
45
|
-
const user = yield auth.isGranted("update");
|
|
46
|
-
const service = new ShippingMethodService(prisma);
|
|
47
|
-
const updatedShippingMethod = yield service.updateShippingMethod(params.organizationId, params.id, user.id, body);
|
|
48
|
-
return c.json(updatedShippingMethod, 200);
|
|
49
|
-
}));
|
|
50
|
-
app.openapi(shippingMethodRoute.deleteShippingMethod, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
-
const auth = c.get("auth");
|
|
52
|
-
const params = c.req.valid("param");
|
|
53
|
-
const user = yield auth.isGranted("delete");
|
|
54
|
-
const service = new ShippingMethodService(prisma);
|
|
55
|
-
yield service.deleteShippingMethod(params.organizationId, params.id, user.id);
|
|
56
|
-
return c.body(null, 204);
|
|
57
|
-
}));
|
|
58
|
-
return app;
|
|
59
|
-
};
|
|
60
|
-
//# sourceMappingURL=shipping-method.handler.js.map
|
|
1
|
+
import{__awaiter as i}from"tslib";import{createApiRouter as e}from"../../core/hono/hono";import{shippingMethodRoute as o}from"./shipping-method.route";import{ShippingMethodService as n}from"./shipping-method.service";export const buildShippingMethodHandler=t=>{const d=e();return d.openapi(o.createShippingMethod,e=>i(void 0,void 0,void 0,function*(){const i=e.get("auth"),o=e.req.valid("param"),d=e.req.valid("json"),a=yield i.isGranted("create"),r=new n(t),p=yield r.createShippingMethod(o.organizationId,a.id,d);return e.json(p,201)})),d.openapi(o.getShippingMethod,e=>i(void 0,void 0,void 0,function*(){const i=e.get("auth"),o=e.req.valid("param");yield i.isGranted("read");const d=new n(t),a=yield d.getShippingMethod(o.organizationId,o.id);return e.json(a,200)})),d.openapi(o.accessEligibility,e=>i(void 0,void 0,void 0,function*(){const i=e.get("auth"),o=e.req.valid("param"),d=yield i.getCurrentUser(),a=new n(t),r=yield a.accessEligibility(d,o.organizationId);return e.json(r,200)})),d.openapi(o.getShippingMethods,e=>i(void 0,void 0,void 0,function*(){const i=e.get("auth"),o=e.req.valid("param"),d=e.req.valid("query");yield i.isGranted("read");const a=new n(t),r=yield a.getShippingMethods(o.organizationId,Object.assign({},d));return e.json(r,200)})),d.openapi(o.updateShippingMethod,e=>i(void 0,void 0,void 0,function*(){const i=e.get("auth"),o=e.req.valid("param"),d=e.req.valid("json"),a=yield i.isGranted("update"),r=new n(t),p=yield r.updateShippingMethod(o.organizationId,o.id,a.id,d);return e.json(p,200)})),d.openapi(o.deleteShippingMethod,e=>i(void 0,void 0,void 0,function*(){const i=e.get("auth"),o=e.req.valid("param"),d=yield i.isGranted("delete"),a=new n(t);return yield a.deleteShippingMethod(o.organizationId,o.id,d.id),e.body(null,204)})),d};
|