@shophost/rest-api 2.0.30 → 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,111 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createApiRoute } from "../../core/hono/hono";
|
|
3
|
-
import { CreateOrderSchema, ErrorSchema, HeaderSchema, OrderSchema, OrderStatusSchema, OrganizationParams, OrganizationWithIdParams, PaginationMetaSchema, PaginationQuerySchema, } from "../../schemas";
|
|
4
|
-
const getOrdersRoute = createApiRoute({
|
|
5
|
-
description: "Fetches paginated list of orders",
|
|
6
|
-
headers: HeaderSchema,
|
|
7
|
-
method: "GET",
|
|
8
|
-
operationId: "getOrders",
|
|
9
|
-
path: "/:organizationId/orders",
|
|
10
|
-
pathParams: OrganizationParams,
|
|
11
|
-
query: PaginationQuerySchema,
|
|
12
|
-
responses: {
|
|
13
|
-
200: z.object({
|
|
14
|
-
list: z.array(OrderSchema),
|
|
15
|
-
meta: PaginationMetaSchema,
|
|
16
|
-
}),
|
|
17
|
-
400: ErrorSchema,
|
|
18
|
-
401: ErrorSchema,
|
|
19
|
-
},
|
|
20
|
-
summary: "Get Orders",
|
|
21
|
-
tags: ["Order"],
|
|
22
|
-
});
|
|
23
|
-
const createOrderRoute = createApiRoute({
|
|
24
|
-
body: CreateOrderSchema,
|
|
25
|
-
description: "Creates a new order",
|
|
26
|
-
headers: HeaderSchema,
|
|
27
|
-
method: "POST",
|
|
28
|
-
operationId: "createOrder",
|
|
29
|
-
path: "/:organizationId/orders",
|
|
30
|
-
pathParams: z.object({
|
|
31
|
-
organizationId: z
|
|
32
|
-
.string()
|
|
33
|
-
.cuid()
|
|
34
|
-
.min(1)
|
|
35
|
-
.openapi({
|
|
36
|
-
description: "The organization ID",
|
|
37
|
-
example: "ckel0e8qw00004n5p5w6fznym",
|
|
38
|
-
param: {
|
|
39
|
-
in: "path",
|
|
40
|
-
name: "organizationId",
|
|
41
|
-
},
|
|
42
|
-
}),
|
|
43
|
-
}),
|
|
44
|
-
responses: {
|
|
45
|
-
201: z.object({
|
|
46
|
-
order: OrderSchema,
|
|
47
|
-
redirectUrl: z.string().url().optional(),
|
|
48
|
-
}),
|
|
49
|
-
400: ErrorSchema,
|
|
50
|
-
401: ErrorSchema,
|
|
51
|
-
404: ErrorSchema,
|
|
52
|
-
},
|
|
53
|
-
summary: "Create Order",
|
|
54
|
-
tags: ["Order"],
|
|
55
|
-
});
|
|
56
|
-
const getOrderRoute = createApiRoute({
|
|
57
|
-
headers: HeaderSchema,
|
|
58
|
-
method: "GET",
|
|
59
|
-
operationId: "getOrder",
|
|
60
|
-
path: "/:organizationId/orders/:id",
|
|
61
|
-
pathParams: OrganizationWithIdParams,
|
|
62
|
-
responses: {
|
|
63
|
-
200: OrderSchema,
|
|
64
|
-
401: ErrorSchema,
|
|
65
|
-
404: ErrorSchema,
|
|
66
|
-
},
|
|
67
|
-
summary: "Get Order",
|
|
68
|
-
tags: ["Order"],
|
|
69
|
-
});
|
|
70
|
-
const updateStatusRoute = createApiRoute({
|
|
71
|
-
description: "Changes the status of an existing order based on the operation",
|
|
72
|
-
headers: HeaderSchema,
|
|
73
|
-
method: "POST",
|
|
74
|
-
operationId: "updateOrderStatus",
|
|
75
|
-
path: "/:organizationId/orders/:id/status/:operation",
|
|
76
|
-
pathParams: OrganizationWithIdParams.extend({
|
|
77
|
-
operation: OrderStatusSchema,
|
|
78
|
-
}),
|
|
79
|
-
responses: {
|
|
80
|
-
200: OrderSchema,
|
|
81
|
-
400: ErrorSchema,
|
|
82
|
-
401: ErrorSchema,
|
|
83
|
-
404: ErrorSchema,
|
|
84
|
-
},
|
|
85
|
-
summary: "Change Order Status",
|
|
86
|
-
tags: ["Order"],
|
|
87
|
-
});
|
|
88
|
-
const deleteOrderRoute = createApiRoute({
|
|
89
|
-
description: "Soft deletes order",
|
|
90
|
-
headers: HeaderSchema,
|
|
91
|
-
method: "DELETE",
|
|
92
|
-
operationId: "deleteOrder",
|
|
93
|
-
path: "/:organizationId/orders/:id",
|
|
94
|
-
pathParams: OrganizationWithIdParams,
|
|
95
|
-
responses: {
|
|
96
|
-
204: null,
|
|
97
|
-
400: ErrorSchema,
|
|
98
|
-
401: ErrorSchema,
|
|
99
|
-
404: ErrorSchema,
|
|
100
|
-
},
|
|
101
|
-
summary: "Delete Order",
|
|
102
|
-
tags: ["Order"],
|
|
103
|
-
});
|
|
104
|
-
export const orderRoute = {
|
|
105
|
-
getOrders: getOrdersRoute,
|
|
106
|
-
createOrder: createOrderRoute,
|
|
107
|
-
getOrder: getOrderRoute,
|
|
108
|
-
updateStatus: updateStatusRoute,
|
|
109
|
-
deleteOrder: deleteOrderRoute,
|
|
110
|
-
};
|
|
111
|
-
//# sourceMappingURL=order.route.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{createApiRoute as r}from"../../core/hono/hono";import{CreateOrderSchema as t,ErrorSchema as a,HeaderSchema as o,OrderSchema as d,OrderStatusSchema as s,OrganizationParams as n,OrganizationWithIdParams as i,PaginationMetaSchema as p,PaginationQuerySchema as m}from"../../schemas";const h=r({description:"Fetches paginated list of orders",headers:o,method:"GET",operationId:"getOrders",path:"/:organizationId/orders",pathParams:n,query:m,responses:{200:e.object({list:e.array(d),meta:p}),400:a,401:a},summary:"Get Orders",tags:["Order"]}),g=r({body:t,description:"Creates a new order",headers:o,method:"POST",operationId:"createOrder",path:"/:organizationId/orders",pathParams:e.object({organizationId:e.string().cuid().min(1).openapi({description:"The organization ID",example:"ckel0e8qw00004n5p5w6fznym",param:{in:"path",name:"organizationId"}})}),responses:{201:e.object({order:d,redirectUrl:e.string().url().optional()}),400:a,401:a,404:a},summary:"Create Order",tags:["Order"]}),O=r({headers:o,method:"GET",operationId:"getOrder",path:"/:organizationId/orders/:id",pathParams:i,responses:{200:d,401:a,404:a},summary:"Get Order",tags:["Order"]}),c=r({description:"Changes the status of an existing order based on the operation",headers:o,method:"POST",operationId:"updateOrderStatus",path:"/:organizationId/orders/:id/status/:operation",pathParams:i.extend({operation:s}),responses:{200:d,400:a,401:a,404:a},summary:"Change Order Status",tags:["Order"]}),u=r({description:"Soft deletes order",headers:o,method:"DELETE",operationId:"deleteOrder",path:"/:organizationId/orders/:id",pathParams:i,responses:{204:null,400:a,401:a,404:a},summary:"Delete Order",tags:["Order"]});export const orderRoute={getOrders:h,createOrder:g,getOrder:O,updateStatus:c,deleteOrder:u};
|
|
@@ -1,158 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { AddressSchema } from "../../schemas/address.schema";
|
|
3
|
-
import { currency } from "../../schemas/currency.schema";
|
|
4
|
-
import { locale } from "../../schemas/locales.schema";
|
|
5
|
-
import { CartItemSchema, CartSchema } from "../cart/cart.schema";
|
|
6
|
-
import { FileSchema } from "../file/file.schema";
|
|
7
|
-
import { PaymentMethodSchema, PaymentProviderSchema, PaymentSchema, } from "../payment/payment.schema";
|
|
8
|
-
import { ShippingMethodSchema } from "../shipping-method/shipping-method.schema";
|
|
9
|
-
import { fulfilmentMethod } from "./fulfilment.schema";
|
|
10
|
-
export const OrderStatusSchema = z
|
|
11
|
-
.enum([
|
|
12
|
-
"draft",
|
|
13
|
-
"pending",
|
|
14
|
-
"accepted",
|
|
15
|
-
"ready-for-dispatch",
|
|
16
|
-
"dispatched",
|
|
17
|
-
"completed",
|
|
18
|
-
"cancelled",
|
|
19
|
-
])
|
|
20
|
-
.openapi({
|
|
21
|
-
description: "Status of the order",
|
|
22
|
-
example: "accepted",
|
|
23
|
-
});
|
|
24
|
-
export const OrderItemSchema = z
|
|
25
|
-
.object({
|
|
26
|
-
translations: z
|
|
27
|
-
.array(z.object({
|
|
28
|
-
locale: locale.openapi({
|
|
29
|
-
description: "Locale of the translation",
|
|
30
|
-
example: "en-US",
|
|
31
|
-
}),
|
|
32
|
-
title: z.string().openapi({
|
|
33
|
-
description: "Title of the ordered product",
|
|
34
|
-
example: "Premium Watch",
|
|
35
|
-
}),
|
|
36
|
-
subtitle: z.string().openapi({
|
|
37
|
-
description: "Additional details about the ordered item, including modifiers",
|
|
38
|
-
example: "Color: Silver, Size: Large",
|
|
39
|
-
}),
|
|
40
|
-
}))
|
|
41
|
-
.openapi({
|
|
42
|
-
description: "Translations for the order item",
|
|
43
|
-
}),
|
|
44
|
-
rawData: CartItemSchema,
|
|
45
|
-
unitPrice: z.number().min(0).openapi({
|
|
46
|
-
description: "Price per unit of the item",
|
|
47
|
-
example: 299.99,
|
|
48
|
-
}),
|
|
49
|
-
image: FileSchema.nullable().optional(),
|
|
50
|
-
totalPrice: z.number().min(0).openapi({
|
|
51
|
-
description: "Total price for this item (unitPrice × quantity)",
|
|
52
|
-
example: 599.98,
|
|
53
|
-
}),
|
|
54
|
-
quantity: z.number().min(1).openapi({
|
|
55
|
-
description: "Number of units ordered",
|
|
56
|
-
example: 2,
|
|
57
|
-
}),
|
|
58
|
-
productSnapshotId: z.string().cuid(),
|
|
59
|
-
})
|
|
60
|
-
.openapi("OrderItem");
|
|
61
|
-
export const OrderSchema = z
|
|
62
|
-
.object({
|
|
63
|
-
id: z.string().openapi({
|
|
64
|
-
description: "Unique identifier for the order",
|
|
65
|
-
example: "clj1234567890abcdef",
|
|
66
|
-
}),
|
|
67
|
-
referenceId: z.string().openapi({
|
|
68
|
-
description: "External reference ID for the order",
|
|
69
|
-
example: "ORD-12345",
|
|
70
|
-
}),
|
|
71
|
-
status: OrderStatusSchema.optional(),
|
|
72
|
-
token: z.string().openapi({
|
|
73
|
-
description: "Security token for order verification",
|
|
74
|
-
example: "a1b2c3d4e5f6g7h8i9j0",
|
|
75
|
-
}),
|
|
76
|
-
expiresAt: z.date().openapi({
|
|
77
|
-
description: "Expiration date for the order",
|
|
78
|
-
example: "2023-12-31T23:59:59Z",
|
|
79
|
-
}),
|
|
80
|
-
items: z.array(OrderItemSchema).min(1).openapi({
|
|
81
|
-
description: "Array of items in the order",
|
|
82
|
-
}),
|
|
83
|
-
shippingMethod: ShippingMethodSchema.nullable().openapi({
|
|
84
|
-
description: "Shipping method selected for the order",
|
|
85
|
-
}),
|
|
86
|
-
acceptedAt: z.date().nullable().optional().openapi({
|
|
87
|
-
description: "Date when the order was accepted",
|
|
88
|
-
example: "2023-06-15T14:30:00Z",
|
|
89
|
-
}),
|
|
90
|
-
dispatchedAt: z.date().nullable().optional().openapi({
|
|
91
|
-
description: "Date when the order was dispatched",
|
|
92
|
-
example: "2023-06-16T09:15:00Z",
|
|
93
|
-
}),
|
|
94
|
-
readyForDispatchAt: z.date().nullable().optional().openapi({
|
|
95
|
-
description: "Date when the order was ready for dispatch",
|
|
96
|
-
example: "2023-06-16T09:15:00Z",
|
|
97
|
-
}),
|
|
98
|
-
createdAt: z.date().openapi({
|
|
99
|
-
description: "Date when the order was created",
|
|
100
|
-
example: "2023-06-15T14:30:00Z",
|
|
101
|
-
}),
|
|
102
|
-
completedAt: z.date().nullable().optional().openapi({
|
|
103
|
-
description: "Date when the order was completed",
|
|
104
|
-
example: "2023-06-18T11:45:00Z",
|
|
105
|
-
}),
|
|
106
|
-
cancelledAt: z.date().nullable().optional().openapi({
|
|
107
|
-
description: "Date when the order was cancelled",
|
|
108
|
-
example: "2023-06-14T16:20:00Z",
|
|
109
|
-
}),
|
|
110
|
-
shippingAddress: AddressSchema.nullable().optional(),
|
|
111
|
-
fulfilmentMethod: fulfilmentMethod.openapi({
|
|
112
|
-
description: "Method of order fulfilment (pickup or delivery)",
|
|
113
|
-
example: "delivery",
|
|
114
|
-
}),
|
|
115
|
-
currency: currency.openapi({
|
|
116
|
-
description: "Currency used for the order",
|
|
117
|
-
example: "USD",
|
|
118
|
-
}),
|
|
119
|
-
payment: PaymentSchema,
|
|
120
|
-
})
|
|
121
|
-
.transform((order) => {
|
|
122
|
-
let status;
|
|
123
|
-
if (order.cancelledAt) {
|
|
124
|
-
status = "cancelled";
|
|
125
|
-
}
|
|
126
|
-
else if (order.completedAt) {
|
|
127
|
-
status = "completed";
|
|
128
|
-
}
|
|
129
|
-
else if (order.dispatchedAt) {
|
|
130
|
-
status = "dispatched";
|
|
131
|
-
}
|
|
132
|
-
else if (order.readyForDispatchAt) {
|
|
133
|
-
status = "ready-for-dispatch";
|
|
134
|
-
}
|
|
135
|
-
else if (order.acceptedAt) {
|
|
136
|
-
status = "accepted";
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
status = "pending";
|
|
140
|
-
}
|
|
141
|
-
return Object.assign(Object.assign({}, order), { status });
|
|
142
|
-
})
|
|
143
|
-
.openapi("Order");
|
|
144
|
-
export const CreateOrderSchema = CartSchema.extend({
|
|
145
|
-
fulfilmentMethod: fulfilmentMethod.default("delivery"),
|
|
146
|
-
payment: z.object({
|
|
147
|
-
provider: PaymentProviderSchema,
|
|
148
|
-
method: PaymentMethodSchema,
|
|
149
|
-
}),
|
|
150
|
-
checkoutBaseUrl: z.string().url(),
|
|
151
|
-
})
|
|
152
|
-
.refine((data) => data.fulfilmentMethod !== "delivery" ||
|
|
153
|
-
data.shippingMethodId !== undefined, {
|
|
154
|
-
message: "shippingMethodId is required when fulfilmentMethod is 'delivery'",
|
|
155
|
-
path: ["shippingMethodId"],
|
|
156
|
-
})
|
|
157
|
-
.openapi("CreateOrder");
|
|
158
|
-
//# sourceMappingURL=order.schema.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{AddressSchema as t}from"../../schemas/address.schema";import{currency as i}from"../../schemas/currency.schema";import{locale as r}from"../../schemas/locales.schema";import{CartItemSchema as a,CartSchema as o}from"../cart/cart.schema";import{FileSchema as p}from"../file/file.schema";import{PaymentMethodSchema as n,PaymentProviderSchema as d,PaymentSchema as c}from"../payment/payment.schema";import{ShippingMethodSchema as l}from"../shipping-method/shipping-method.schema";import{fulfilmentMethod as s}from"./fulfilment.schema";export const OrderStatusSchema=e.enum(["draft","pending","accepted","ready-for-dispatch","dispatched","completed","cancelled"]).openapi({description:"Status of the order",example:"accepted"});export const OrderItemSchema=e.object({translations:e.array(e.object({locale:r.openapi({description:"Locale of the translation",example:"en-US"}),title:e.string().openapi({description:"Title of the ordered product",example:"Premium Watch"}),subtitle:e.string().openapi({description:"Additional details about the ordered item, including modifiers",example:"Color: Silver, Size: Large"})})).openapi({description:"Translations for the order item"}),rawData:a,unitPrice:e.number().min(0).openapi({description:"Price per unit of the item",example:299.99}),image:p.nullable().optional(),totalPrice:e.number().min(0).openapi({description:"Total price for this item (unitPrice × quantity)",example:599.98}),quantity:e.number().min(1).openapi({description:"Number of units ordered",example:2}),productSnapshotId:e.string().cuid()}).openapi("OrderItem");export const OrderSchema=e.object({id:e.string().openapi({description:"Unique identifier for the order",example:"clj1234567890abcdef"}),referenceId:e.string().openapi({description:"External reference ID for the order",example:"ORD-12345"}),status:OrderStatusSchema.optional(),token:e.string().openapi({description:"Security token for order verification",example:"a1b2c3d4e5f6g7h8i9j0"}),expiresAt:e.date().openapi({description:"Expiration date for the order",example:"2023-12-31T23:59:59Z"}),items:e.array(OrderItemSchema).min(1).openapi({description:"Array of items in the order"}),shippingMethod:l.nullable().openapi({description:"Shipping method selected for the order"}),acceptedAt:e.date().nullable().optional().openapi({description:"Date when the order was accepted",example:"2023-06-15T14:30:00Z"}),dispatchedAt:e.date().nullable().optional().openapi({description:"Date when the order was dispatched",example:"2023-06-16T09:15:00Z"}),readyForDispatchAt:e.date().nullable().optional().openapi({description:"Date when the order was ready for dispatch",example:"2023-06-16T09:15:00Z"}),createdAt:e.date().openapi({description:"Date when the order was created",example:"2023-06-15T14:30:00Z"}),completedAt:e.date().nullable().optional().openapi({description:"Date when the order was completed",example:"2023-06-18T11:45:00Z"}),cancelledAt:e.date().nullable().optional().openapi({description:"Date when the order was cancelled",example:"2023-06-14T16:20:00Z"}),shippingAddress:t.nullable().optional(),fulfilmentMethod:s.openapi({description:"Method of order fulfilment (pickup or delivery)",example:"delivery"}),currency:i.openapi({description:"Currency used for the order",example:"USD"}),payment:c}).transform(e=>{let t;return t=e.cancelledAt?"cancelled":e.completedAt?"completed":e.dispatchedAt?"dispatched":e.readyForDispatchAt?"ready-for-dispatch":e.acceptedAt?"accepted":"pending",Object.assign(Object.assign({},e),{status:t})}).openapi("Order");export const CreateOrderSchema=o.extend({fulfilmentMethod:s.default("delivery"),payment:e.object({provider:d,method:n}),checkoutBaseUrl:e.string().url()}).refine(e=>"delivery"!==e.fulfilmentMethod||void 0!==e.shippingMethodId,{message:"shippingMethodId is required when fulfilmentMethod is 'delivery'",path:["shippingMethodId"]}).openapi("CreateOrder");
|
|
@@ -7,9 +7,6 @@ declare class OrderService {
|
|
|
7
7
|
private readonly paymentOptions;
|
|
8
8
|
private paymentService;
|
|
9
9
|
constructor(prisma: PrismaClientType, paymentOptions: PaymentServiceOptions);
|
|
10
|
-
/**
|
|
11
|
-
* Create a draft order
|
|
12
|
-
*/
|
|
13
10
|
createOrder(organizationId: string, user: User, body: z.infer<typeof CreateOrderSchema>): Promise<{
|
|
14
11
|
redirectUrl: string | undefined;
|
|
15
12
|
order: {
|
|
@@ -113,9 +110,6 @@ declare class OrderService {
|
|
|
113
110
|
} | null | undefined;
|
|
114
111
|
};
|
|
115
112
|
}>;
|
|
116
|
-
/**
|
|
117
|
-
* Get a specific order by ID
|
|
118
|
-
*/
|
|
119
113
|
getOrder(user: User, organizationId: string, orderId: string): Promise<{
|
|
120
114
|
status: "pending" | "accepted" | "ready-for-dispatch" | "dispatched" | "completed" | "cancelled";
|
|
121
115
|
id: string;
|
|
@@ -216,9 +210,6 @@ declare class OrderService {
|
|
|
216
210
|
deliveryInstructions?: string | null | undefined;
|
|
217
211
|
} | null | undefined;
|
|
218
212
|
}>;
|
|
219
|
-
/**
|
|
220
|
-
* Get a paginated list of orders
|
|
221
|
-
*/
|
|
222
213
|
getOrders(organizationId: string, query: {
|
|
223
214
|
page: number;
|
|
224
215
|
limit: number;
|
|
@@ -333,13 +324,7 @@ declare class OrderService {
|
|
|
333
324
|
} | null | undefined;
|
|
334
325
|
}[];
|
|
335
326
|
}>;
|
|
336
|
-
/**
|
|
337
|
-
* Delete an order (soft delete)
|
|
338
|
-
*/
|
|
339
327
|
deleteOrder(organizationId: string, orderId: string, userId: string): Promise<void>;
|
|
340
|
-
/**
|
|
341
|
-
* Update order status
|
|
342
|
-
*/
|
|
343
328
|
updateStatus(organizationId: string, orderId: string, operation: OrderStatus): Promise<{
|
|
344
329
|
status: "pending" | "accepted" | "ready-for-dispatch" | "dispatched" | "completed" | "cancelled";
|
|
345
330
|
id: string;
|
|
@@ -1,306 +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 { OrderSchema, PaginationMetaSchema, } from "../../schemas";
|
|
6
|
-
import { transformCartItemToOrderItem } from "../cart/cart.util";
|
|
7
|
-
import { PaymentService, } from "../payment/payment.service";
|
|
8
|
-
const nanoid = customAlphabet("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ", 6);
|
|
9
|
-
class OrderService {
|
|
10
|
-
constructor(prisma, paymentOptions) {
|
|
11
|
-
this.prisma = prisma;
|
|
12
|
-
this.paymentOptions = paymentOptions;
|
|
13
|
-
this.paymentService = new PaymentService(prisma, paymentOptions);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Create a draft order
|
|
17
|
-
*/
|
|
18
|
-
createOrder(organizationId, user, body) {
|
|
19
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
var _a, _b, _c, _d, _e;
|
|
21
|
-
const organization = yield this.prisma.organization.findFirst({
|
|
22
|
-
where: {
|
|
23
|
-
id: organizationId,
|
|
24
|
-
},
|
|
25
|
-
include: {
|
|
26
|
-
configuration: true,
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
if (!organization) {
|
|
30
|
-
throw new HttpException(404, "Organization not found");
|
|
31
|
-
}
|
|
32
|
-
const shippingAddress = yield this.prisma.address.findFirst({
|
|
33
|
-
where: {
|
|
34
|
-
users: {
|
|
35
|
-
some: {
|
|
36
|
-
id: user.id,
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
isDefault: true,
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
if (body.fulfilmentMethod === "delivery" && !shippingAddress) {
|
|
43
|
-
throw new HttpException(400, "This user does not have a default shipping address");
|
|
44
|
-
}
|
|
45
|
-
const items = yield Promise.all(body.items.map(transformCartItemToOrderItem(this.prisma)));
|
|
46
|
-
const shippingMethod = yield this.prisma.shippingMethod.findFirst({
|
|
47
|
-
where: {
|
|
48
|
-
id: body.shippingMethodId,
|
|
49
|
-
},
|
|
50
|
-
include: {
|
|
51
|
-
shippingZones: true,
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
const shipping = (_b = (_a = shippingMethod === null || shippingMethod === void 0 ? void 0 : shippingMethod.shippingZones[0]) === null || _a === void 0 ? void 0 : _a.price) !== null && _b !== void 0 ? _b : 0;
|
|
55
|
-
const subtotal = items.reduce((acc, item) => acc + item.totalPrice, 0);
|
|
56
|
-
const total = subtotal + shipping;
|
|
57
|
-
// Create the order
|
|
58
|
-
const order = yield this.prisma.order.create({
|
|
59
|
-
data: Object.assign(Object.assign({
|
|
60
|
-
// TODO: add guest order flow
|
|
61
|
-
token: nanoid(), referenceId: nanoid(), organization: {
|
|
62
|
-
connect: {
|
|
63
|
-
id: organizationId,
|
|
64
|
-
},
|
|
65
|
-
}, fulfilmentMethod: body.fulfilmentMethod, shippingMethod: body.shippingMethodId
|
|
66
|
-
? {
|
|
67
|
-
connect: {
|
|
68
|
-
id: body.shippingMethodId,
|
|
69
|
-
},
|
|
70
|
-
}
|
|
71
|
-
: undefined, currency: organization.configuration.defaultCurrency,
|
|
72
|
-
// TODO: add user IP address
|
|
73
|
-
sourceIp: "127.0.0.1", items: {
|
|
74
|
-
create: items,
|
|
75
|
-
} }, (shippingAddress
|
|
76
|
-
? {
|
|
77
|
-
shippingAddress: {
|
|
78
|
-
create: Object.assign(Object.assign({}, shippingAddress), { id: undefined }),
|
|
79
|
-
},
|
|
80
|
-
}
|
|
81
|
-
: {})), { user: {
|
|
82
|
-
connect: {
|
|
83
|
-
id: user.id,
|
|
84
|
-
},
|
|
85
|
-
}, payment: {
|
|
86
|
-
create: {
|
|
87
|
-
method: body.payment.method,
|
|
88
|
-
provider: body.payment.provider,
|
|
89
|
-
shipping: (_d = (_c = shippingMethod === null || shippingMethod === void 0 ? void 0 : shippingMethod.shippingZones[0]) === null || _c === void 0 ? void 0 : _c.price) !== null && _d !== void 0 ? _d : 0,
|
|
90
|
-
subtotal,
|
|
91
|
-
total,
|
|
92
|
-
discount: 0,
|
|
93
|
-
currency: organization.configuration.defaultCurrency,
|
|
94
|
-
},
|
|
95
|
-
} }),
|
|
96
|
-
include: {
|
|
97
|
-
items: {
|
|
98
|
-
include: {
|
|
99
|
-
translations: true,
|
|
100
|
-
image: true,
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
payment: true,
|
|
104
|
-
shippingMethod: {
|
|
105
|
-
include: {
|
|
106
|
-
shippingZones: true,
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
const formattedOrder = OrderSchema.parse(order);
|
|
112
|
-
const session = yield this.paymentService.createCheckoutSession(user, formattedOrder, {
|
|
113
|
-
locale: "en",
|
|
114
|
-
successUrl: `${body.checkoutBaseUrl}/account/orders/${order.id}?clearCart=true`,
|
|
115
|
-
cancelUrl: `${body.checkoutBaseUrl}/checkout/shipping-and-payment`,
|
|
116
|
-
});
|
|
117
|
-
return {
|
|
118
|
-
redirectUrl: (_e = session.redirectUrl) !== null && _e !== void 0 ? _e : undefined,
|
|
119
|
-
order: OrderSchema.parse(order),
|
|
120
|
-
};
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Get a specific order by ID
|
|
125
|
-
*/
|
|
126
|
-
getOrder(user, organizationId, orderId) {
|
|
127
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
const order = yield this.prisma.order.findUnique({
|
|
129
|
-
where: {
|
|
130
|
-
id: orderId,
|
|
131
|
-
organizationId: organizationId,
|
|
132
|
-
deletedAt: null,
|
|
133
|
-
user: {
|
|
134
|
-
id: user.id,
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
include: {
|
|
138
|
-
items: {
|
|
139
|
-
include: {
|
|
140
|
-
translations: true,
|
|
141
|
-
image: true,
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
shippingAddress: true,
|
|
145
|
-
shippingMethod: {
|
|
146
|
-
include: {
|
|
147
|
-
shippingZones: true,
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
payment: true,
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
if (!order) {
|
|
154
|
-
throw new HttpException(404, "Order not found");
|
|
155
|
-
}
|
|
156
|
-
return OrderSchema.parse(order);
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Get a paginated list of orders
|
|
161
|
-
*/
|
|
162
|
-
getOrders(organizationId, query) {
|
|
163
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
-
const { page = 1, limit = 10 } = query;
|
|
165
|
-
const [list, meta] = yield this.prisma.order
|
|
166
|
-
.paginate({
|
|
167
|
-
where: {
|
|
168
|
-
organizationId: organizationId,
|
|
169
|
-
deletedAt: null,
|
|
170
|
-
},
|
|
171
|
-
include: {
|
|
172
|
-
items: {
|
|
173
|
-
include: {
|
|
174
|
-
translations: true,
|
|
175
|
-
image: true,
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
shippingAddress: true,
|
|
179
|
-
shippingMethod: {
|
|
180
|
-
include: {
|
|
181
|
-
shippingZones: true,
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
payment: true,
|
|
185
|
-
},
|
|
186
|
-
orderBy: {
|
|
187
|
-
createdAt: "desc",
|
|
188
|
-
},
|
|
189
|
-
})
|
|
190
|
-
.withPages({
|
|
191
|
-
page,
|
|
192
|
-
limit,
|
|
193
|
-
});
|
|
194
|
-
return {
|
|
195
|
-
meta: PaginationMetaSchema.parse(meta),
|
|
196
|
-
list: z.array(OrderSchema).parse(list),
|
|
197
|
-
};
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Delete an order (soft delete)
|
|
202
|
-
*/
|
|
203
|
-
deleteOrder(organizationId, orderId, userId) {
|
|
204
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
-
const order = yield this.prisma.order.findUnique({
|
|
206
|
-
where: {
|
|
207
|
-
id: orderId,
|
|
208
|
-
organizationId: organizationId,
|
|
209
|
-
deletedAt: null,
|
|
210
|
-
},
|
|
211
|
-
});
|
|
212
|
-
if (!order) {
|
|
213
|
-
throw new HttpException(404, "Order not found");
|
|
214
|
-
}
|
|
215
|
-
yield this.prisma.order.update({
|
|
216
|
-
where: {
|
|
217
|
-
id: orderId,
|
|
218
|
-
organizationId: organizationId,
|
|
219
|
-
deletedAt: null,
|
|
220
|
-
},
|
|
221
|
-
data: {
|
|
222
|
-
deletedAt: new Date(),
|
|
223
|
-
deletedBy: userId,
|
|
224
|
-
},
|
|
225
|
-
});
|
|
226
|
-
return;
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Update order status
|
|
231
|
-
*/
|
|
232
|
-
updateStatus(organizationId, orderId, operation) {
|
|
233
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
234
|
-
const order = yield this.prisma.order.findUnique({
|
|
235
|
-
where: {
|
|
236
|
-
id: orderId,
|
|
237
|
-
organizationId: organizationId,
|
|
238
|
-
deletedAt: null,
|
|
239
|
-
},
|
|
240
|
-
include: {
|
|
241
|
-
items: true,
|
|
242
|
-
shippingMethod: {
|
|
243
|
-
include: {
|
|
244
|
-
shippingZones: true,
|
|
245
|
-
},
|
|
246
|
-
},
|
|
247
|
-
},
|
|
248
|
-
});
|
|
249
|
-
if (!order) {
|
|
250
|
-
throw new HttpException(404, "Order not found");
|
|
251
|
-
}
|
|
252
|
-
let updateData = {};
|
|
253
|
-
switch (operation) {
|
|
254
|
-
case "accepted":
|
|
255
|
-
updateData = {
|
|
256
|
-
acceptedAt: new Date(),
|
|
257
|
-
};
|
|
258
|
-
break;
|
|
259
|
-
case "ready-for-dispatch":
|
|
260
|
-
updateData = {
|
|
261
|
-
readyForDispatchAt: new Date(),
|
|
262
|
-
};
|
|
263
|
-
break;
|
|
264
|
-
case "dispatched":
|
|
265
|
-
updateData = {
|
|
266
|
-
dispatchedAt: new Date(),
|
|
267
|
-
};
|
|
268
|
-
break;
|
|
269
|
-
case "completed":
|
|
270
|
-
updateData = {
|
|
271
|
-
completedAt: new Date(),
|
|
272
|
-
};
|
|
273
|
-
break;
|
|
274
|
-
case "cancelled":
|
|
275
|
-
updateData = {
|
|
276
|
-
cancelledAt: new Date(),
|
|
277
|
-
};
|
|
278
|
-
break;
|
|
279
|
-
}
|
|
280
|
-
const updatedOrder = yield this.prisma.order.update({
|
|
281
|
-
where: {
|
|
282
|
-
id: orderId,
|
|
283
|
-
},
|
|
284
|
-
data: updateData,
|
|
285
|
-
include: {
|
|
286
|
-
items: {
|
|
287
|
-
include: {
|
|
288
|
-
translations: true,
|
|
289
|
-
image: true,
|
|
290
|
-
},
|
|
291
|
-
},
|
|
292
|
-
shippingAddress: true,
|
|
293
|
-
shippingMethod: {
|
|
294
|
-
include: {
|
|
295
|
-
shippingZones: true,
|
|
296
|
-
},
|
|
297
|
-
},
|
|
298
|
-
payment: true,
|
|
299
|
-
},
|
|
300
|
-
});
|
|
301
|
-
return OrderSchema.parse(updatedOrder);
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
export { OrderService };
|
|
306
|
-
//# sourceMappingURL=order.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{OrderSchema as r,PaginationMetaSchema as d}from"../../schemas";import{transformCartItemToOrderItem as s}from"../cart/cart.util";import{PaymentService as o}from"../payment/payment.service";const a=t("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ",6);class p{constructor(e,i){this.prisma=e,this.paymentOptions=i,this.paymentService=new o(e,i)}createOrder(i,t,d){return e(this,void 0,void 0,function*(){var e,o,p,c,l;const h=yield this.prisma.organization.findFirst({where:{id:i},include:{configuration:!0}});if(!h)throw new n(404,"Organization not found");const u=yield this.prisma.address.findFirst({where:{users:{some:{id:t.id}},isDefault:!0}});if("delivery"===d.fulfilmentMethod&&!u)throw new n(400,"This user does not have a default shipping address");const m=yield Promise.all(d.items.map(s(this.prisma))),g=yield this.prisma.shippingMethod.findFirst({where:{id:d.shippingMethodId},include:{shippingZones:!0}}),f=null!==(o=null===(e=null==g?void 0:g.shippingZones[0])||void 0===e?void 0:e.price)&&void 0!==o?o:0,y=m.reduce((e,i)=>e+i.totalPrice,0),v=y+f,w=yield this.prisma.order.create({data:Object.assign(Object.assign({token:a(),referenceId:a(),organization:{connect:{id:i}},fulfilmentMethod:d.fulfilmentMethod,shippingMethod:d.shippingMethodId?{connect:{id:d.shippingMethodId}}:void 0,currency:h.configuration.defaultCurrency,sourceIp:"127.0.0.1",items:{create:m}},u?{shippingAddress:{create:Object.assign(Object.assign({},u),{id:void 0})}}:{}),{user:{connect:{id:t.id}},payment:{create:{method:d.payment.method,provider:d.payment.provider,shipping:null!==(c=null===(p=null==g?void 0:g.shippingZones[0])||void 0===p?void 0:p.price)&&void 0!==c?c:0,subtotal:y,total:v,discount:0,currency:h.configuration.defaultCurrency}}}),include:{items:{include:{translations:!0,image:!0}},payment:!0,shippingMethod:{include:{shippingZones:!0}}}}),A=r.parse(w);return{redirectUrl:null!==(l=(yield this.paymentService.createCheckoutSession(t,A,{locale:"en",successUrl:`${d.checkoutBaseUrl}/account/orders/${w.id}?clearCart=true`,cancelUrl:`${d.checkoutBaseUrl}/checkout/shipping-and-payment`})).redirectUrl)&&void 0!==l?l:void 0,order:r.parse(w)}})}getOrder(i,t,d){return e(this,void 0,void 0,function*(){const e=yield this.prisma.order.findUnique({where:{id:d,organizationId:t,deletedAt:null,user:{id:i.id}},include:{items:{include:{translations:!0,image:!0}},shippingAddress:!0,shippingMethod:{include:{shippingZones:!0}},payment:!0}});if(!e)throw new n(404,"Order not found");return r.parse(e)})}getOrders(t,n){return e(this,void 0,void 0,function*(){const{page:e=1,limit:s=10}=n,[o,a]=yield this.prisma.order.paginate({where:{organizationId:t,deletedAt:null},include:{items:{include:{translations:!0,image:!0}},shippingAddress:!0,shippingMethod:{include:{shippingZones:!0}},payment:!0},orderBy:{createdAt:"desc"}}).withPages({page:e,limit:s});return{meta:d.parse(a),list:i.array(r).parse(o)}})}deleteOrder(i,t,r){return e(this,void 0,void 0,function*(){if(!(yield this.prisma.order.findUnique({where:{id:t,organizationId:i,deletedAt:null}})))throw new n(404,"Order not found");yield this.prisma.order.update({where:{id:t,organizationId:i,deletedAt:null},data:{deletedAt:new Date,deletedBy:r}})})}updateStatus(i,t,d){return e(this,void 0,void 0,function*(){if(!(yield this.prisma.order.findUnique({where:{id:t,organizationId:i,deletedAt:null},include:{items:!0,shippingMethod:{include:{shippingZones:!0}}}})))throw new n(404,"Order not found");let e={};switch(d){case"accepted":e={acceptedAt:new Date};break;case"ready-for-dispatch":e={readyForDispatchAt:new Date};break;case"dispatched":e={dispatchedAt:new Date};break;case"completed":e={completedAt:new Date};break;case"cancelled":e={cancelledAt:new Date}}const s=yield this.prisma.order.update({where:{id:t},data:e,include:{items:{include:{translations:!0,image:!0}},shippingAddress:!0,shippingMethod:{include:{shippingZones:!0}},payment:!0}});return r.parse(s)})}}export{p as OrderService};
|
|
@@ -1,38 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { AddressSchema, CreateAddressSchema, } from "../../schemas/address.schema";
|
|
3
|
-
export const RecipientSchema = z
|
|
4
|
-
.object({
|
|
5
|
-
id: z.string().openapi({
|
|
6
|
-
example: "clf9876543210abcdef",
|
|
7
|
-
description: "ID of the customer",
|
|
8
|
-
}),
|
|
9
|
-
firstname: z.string().nullable().optional().openapi({
|
|
10
|
-
example: "John Doe",
|
|
11
|
-
description: "Name of the customer",
|
|
12
|
-
}),
|
|
13
|
-
email: z.string().nullable().optional().openapi({
|
|
14
|
-
example: "john.doe@example.com",
|
|
15
|
-
description: "Email of the customer",
|
|
16
|
-
}),
|
|
17
|
-
phone: z.string().nullable().optional().openapi({
|
|
18
|
-
example: "+1234567890",
|
|
19
|
-
description: "Phone number of the customer",
|
|
20
|
-
}),
|
|
21
|
-
address: AddressSchema.nullable().optional().openapi({
|
|
22
|
-
description: "Address of the customer",
|
|
23
|
-
}),
|
|
24
|
-
createdAt: z.date(),
|
|
25
|
-
updatedAt: z.date(),
|
|
26
|
-
})
|
|
27
|
-
.openapi("Customer");
|
|
28
|
-
export const CreateRecipientSchema = RecipientSchema.pick({
|
|
29
|
-
firstname: true,
|
|
30
|
-
email: true,
|
|
31
|
-
phone: true,
|
|
32
|
-
})
|
|
33
|
-
.extend({
|
|
34
|
-
address: CreateAddressSchema,
|
|
35
|
-
})
|
|
36
|
-
.openapi("Customer");
|
|
37
|
-
export const UpdateCustomerSchema = CreateRecipientSchema.partial().openapi("UpdateCustomer");
|
|
38
|
-
//# sourceMappingURL=recipient.schema.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{AddressSchema as o,CreateAddressSchema as t}from"../../schemas/address.schema";export const RecipientSchema=e.object({id:e.string().openapi({example:"clf9876543210abcdef",description:"ID of the customer"}),firstname:e.string().nullable().optional().openapi({example:"John Doe",description:"Name of the customer"}),email:e.string().nullable().optional().openapi({example:"john.doe@example.com",description:"Email of the customer"}),phone:e.string().nullable().optional().openapi({example:"+1234567890",description:"Phone number of the customer"}),address:o.nullable().optional().openapi({description:"Address of the customer"}),createdAt:e.date(),updatedAt:e.date()}).openapi("Customer");export const CreateRecipientSchema=RecipientSchema.pick({firstname:!0,email:!0,phone:!0}).extend({address:t}).openapi("Customer");export const UpdateCustomerSchema=CreateRecipientSchema.partial().openapi("UpdateCustomer");
|