@shophost/rest-api 2.0.29 → 2.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +18 -13
- package/scripts/minify.mjs +110 -0
- package/src/app.js +1 -53
- package/src/core/auth/auth.schema.js +1 -41
- package/src/core/auth/auth.util.js +1 -44
- package/src/core/auth/better-auth.lib.js +1 -100
- package/src/core/auth/generate-password-hash.util.d.ts +0 -3
- package/src/core/auth/generate-password-hash.util.js +1 -30
- package/src/core/auth/headers.schema.js +1 -22
- package/src/core/auth/user.schema.js +1 -30
- package/src/core/db/__generated__/client/browser.d.ts +0 -128
- package/src/core/db/__generated__/client/browser.js +1 -18
- package/src/core/db/__generated__/client/client.d.ts +0 -143
- package/src/core/db/__generated__/client/client.js +1 -35
- package/src/core/db/__generated__/client/commonInputTypes.js +1 -11
- package/src/core/db/__generated__/client/enums.js +1 -200
- package/src/core/db/__generated__/client/internal/class.d.ts +0 -343
- package/src/core/db/__generated__/client/internal/class.js +1 -55
- package/src/core/db/__generated__/client/internal/prismaNamespace.d.ts +0 -234
- package/src/core/db/__generated__/client/internal/prismaNamespace.js +1 -541
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.d.ts +0 -15
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js +1 -512
- package/src/core/db/__generated__/client/models/Account.d.ts +0 -628
- package/src/core/db/__generated__/client/models/Account.js +1 -2
- package/src/core/db/__generated__/client/models/Address.d.ts +0 -701
- package/src/core/db/__generated__/client/models/Address.js +1 -2
- package/src/core/db/__generated__/client/models/Campaign.d.ts +0 -638
- package/src/core/db/__generated__/client/models/Campaign.js +1 -2
- package/src/core/db/__generated__/client/models/ClosingTimes.d.ts +0 -634
- package/src/core/db/__generated__/client/models/ClosingTimes.js +1 -2
- package/src/core/db/__generated__/client/models/File.d.ts +0 -752
- package/src/core/db/__generated__/client/models/File.js +1 -2
- package/src/core/db/__generated__/client/models/Invitation.d.ts +0 -628
- package/src/core/db/__generated__/client/models/Invitation.js +1 -2
- package/src/core/db/__generated__/client/models/LegalEntity.d.ts +0 -652
- package/src/core/db/__generated__/client/models/LegalEntity.js +1 -2
- package/src/core/db/__generated__/client/models/Manufacturer.d.ts +0 -679
- package/src/core/db/__generated__/client/models/Manufacturer.js +1 -2
- package/src/core/db/__generated__/client/models/ManufacturerTranslation.d.ts +0 -628
- package/src/core/db/__generated__/client/models/ManufacturerTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/Member.d.ts +0 -628
- package/src/core/db/__generated__/client/models/Member.js +1 -2
- package/src/core/db/__generated__/client/models/Modifier.d.ts +0 -662
- package/src/core/db/__generated__/client/models/Modifier.js +1 -2
- package/src/core/db/__generated__/client/models/ModifierGroup.d.ts +0 -686
- package/src/core/db/__generated__/client/models/ModifierGroup.js +1 -2
- package/src/core/db/__generated__/client/models/ModifierGroupTranslation.d.ts +0 -628
- package/src/core/db/__generated__/client/models/ModifierGroupTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/OpeningTimes.d.ts +0 -634
- package/src/core/db/__generated__/client/models/OpeningTimes.js +1 -2
- package/src/core/db/__generated__/client/models/Order.d.ts +0 -700
- package/src/core/db/__generated__/client/models/Order.js +1 -2
- package/src/core/db/__generated__/client/models/OrderItem.d.ts +0 -686
- package/src/core/db/__generated__/client/models/OrderItem.js +1 -2
- package/src/core/db/__generated__/client/models/OrderItemTranslation.d.ts +0 -628
- package/src/core/db/__generated__/client/models/OrderItemTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/Organization.d.ts +0 -811
- package/src/core/db/__generated__/client/models/Organization.js +1 -2
- package/src/core/db/__generated__/client/models/OrganizationConfiguration.d.ts +0 -676
- package/src/core/db/__generated__/client/models/OrganizationConfiguration.js +1 -2
- package/src/core/db/__generated__/client/models/Payment.d.ts +0 -668
- package/src/core/db/__generated__/client/models/Payment.js +1 -2
- package/src/core/db/__generated__/client/models/PaymentSession.d.ts +0 -638
- package/src/core/db/__generated__/client/models/PaymentSession.js +1 -2
- package/src/core/db/__generated__/client/models/Product.d.ts +0 -746
- package/src/core/db/__generated__/client/models/Product.js +1 -2
- package/src/core/db/__generated__/client/models/ProductCategory.d.ts +0 -689
- package/src/core/db/__generated__/client/models/ProductCategory.js +1 -2
- package/src/core/db/__generated__/client/models/ProductCategoryTranslation.d.ts +0 -628
- package/src/core/db/__generated__/client/models/ProductCategoryTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/ProductSnapshot.d.ts +0 -664
- package/src/core/db/__generated__/client/models/ProductSnapshot.js +1 -2
- package/src/core/db/__generated__/client/models/ProductTranslation.d.ts +0 -628
- package/src/core/db/__generated__/client/models/ProductTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/Reservation.d.ts +0 -650
- package/src/core/db/__generated__/client/models/Reservation.js +1 -2
- package/src/core/db/__generated__/client/models/Session.d.ts +0 -628
- package/src/core/db/__generated__/client/models/Session.js +1 -2
- package/src/core/db/__generated__/client/models/ShippingMethod.d.ts +0 -679
- package/src/core/db/__generated__/client/models/ShippingMethod.js +1 -2
- package/src/core/db/__generated__/client/models/ShippingZone.d.ts +0 -638
- package/src/core/db/__generated__/client/models/ShippingZone.js +1 -2
- package/src/core/db/__generated__/client/models/User.d.ts +0 -736
- package/src/core/db/__generated__/client/models/User.js +1 -2
- package/src/core/db/__generated__/client/models/Verification.d.ts +0 -592
- package/src/core/db/__generated__/client/models/Verification.js +1 -2
- package/src/core/db/__generated__/client/models.js +1 -2
- package/src/core/db/index.js +1 -2
- package/src/core/exceptions/http-exception.js +1 -9
- package/src/core/hono/hono.js +1 -123
- package/src/core/lib/prisma.d.ts +9 -1
- package/src/core/lib/prisma.js +1 -11
- package/src/core/logging/pino.js +1 -5
- package/src/core/notifications/email.service.d.ts +0 -15
- package/src/core/notifications/email.service.js +1 -116
- package/src/core/openapi/openapi.lib.js +1 -26
- package/src/core/types/google-maps.types.js +1 -2
- package/src/core/utils/currency.util.js +1 -11
- package/src/core/utils/env.util.js +1 -8
- package/src/core/utils/object.util.d.ts +0 -10
- package/src/core/utils/object.util.js +1 -39
- package/src/core/utils/translations.util.js +0 -2
- package/src/core/utils/zod.util.d.ts +0 -12
- package/src/core/utils/zod.util.js +1 -85
- package/src/db.js +1 -3
- package/src/features/access/access.handler.js +1 -91
- package/src/features/access/access.route.js +1 -220
- package/src/features/access/access.schema.js +1 -108
- package/src/features/access/access.service.js +1 -294
- package/src/features/cart/cart.handler.js +1 -17
- package/src/features/cart/cart.route.js +1 -32
- package/src/features/cart/cart.schema.js +1 -39
- package/src/features/cart/cart.service.d.ts +0 -7
- package/src/features/cart/cart.service.js +1 -97
- package/src/features/cart/cart.util.js +1 -76
- package/src/features/file/file.handler.js +1 -23
- package/src/features/file/file.route.js +1 -34
- package/src/features/file/file.schema.js +1 -77
- package/src/features/file/file.service.d.ts +0 -6
- package/src/features/file/file.service.js +1 -66
- package/src/features/health/health.handler.js +1 -10
- package/src/features/health/health.route.js +1 -25
- package/src/features/index.js +1 -16
- package/src/features/location/location.handler.js +1 -25
- package/src/features/location/location.route.js +1 -56
- package/src/features/location/location.schema.js +1 -50
- package/src/features/location/location.service.d.ts +0 -3
- package/src/features/location/location.service.js +1 -141
- package/src/features/manufacturer/manufacturer.handler.js +1 -53
- package/src/features/manufacturer/manufacturer.route.js +1 -97
- package/src/features/manufacturer/manufacturer.schema.js +1 -125
- package/src/features/manufacturer/manufacturer.service.d.ts +0 -19
- package/src/features/manufacturer/manufacturer.service.js +1 -190
- package/src/features/order/emails/order-confirmation.email.js +1 -229
- package/src/features/order/emails/order-notification.email.js +1 -229
- package/src/features/order/fulfilment.schema.js +1 -3
- package/src/features/order/order.handler.js +1 -54
- package/src/features/order/order.route.js +1 -111
- package/src/features/order/order.schema.js +1 -158
- package/src/features/order/order.service.d.ts +0 -15
- package/src/features/order/order.service.js +1 -306
- package/src/features/order/recipient.schema.js +1 -38
- package/src/features/organization/legal-entity.schema.js +1 -83
- package/src/features/organization/organization-configuration.schema.js +1 -115
- package/src/features/organization/organization.handler.js +1 -48
- package/src/features/organization/organization.route.js +1 -84
- package/src/features/organization/organization.schema.js +1 -64
- package/src/features/organization/organization.service.d.ts +0 -15
- package/src/features/organization/organization.service.js +1 -334
- package/src/features/payment/payment.handler.js +1 -16
- package/src/features/payment/payment.route.js +1 -22
- package/src/features/payment/payment.schema.js +1 -46
- package/src/features/payment/payment.service.js +1 -100
- package/src/features/payment/stripe.service.js +1 -164
- package/src/features/product/product-modifier.schema.js +1 -84
- package/src/features/product/product.handler.js +1 -87
- package/src/features/product/product.route.js +1 -179
- package/src/features/product/product.schema.js +1 -143
- package/src/features/product/product.service.d.ts +0 -25
- package/src/features/product/product.service.js +1 -440
- package/src/features/product-category/product-category.handler.js +1 -59
- package/src/features/product-category/product-category.route.js +1 -139
- package/src/features/product-category/product-category.schema.js +1 -86
- package/src/features/product-category/product-category.service.d.ts +0 -22
- package/src/features/product-category/product-category.service.js +1 -220
- package/src/features/reservation/emails/reservation-cancellation.email.js +1 -82
- package/src/features/reservation/emails/reservation-confirmation.email.js +1 -82
- package/src/features/reservation/emails/reservation-notification.email.js +1 -93
- package/src/features/reservation/reservation.handler.js +1 -65
- package/src/features/reservation/reservation.route.js +1 -167
- package/src/features/reservation/reservation.schema.js +1 -51
- package/src/features/reservation/reservation.service.d.ts +0 -18
- package/src/features/reservation/reservation.service.js +1 -231
- package/src/features/shipping/shipping.handler.js +1 -32
- package/src/features/shipping/shipping.route.js +1 -51
- package/src/features/shipping/shipping.service.d.ts +0 -7
- package/src/features/shipping/shipping.service.js +1 -96
- package/src/features/shipping-method/shipping-method.handler.js +1 -60
- package/src/features/shipping-method/shipping-method.route.js +1 -144
- package/src/features/shipping-method/shipping-method.schema.js +1 -48
- package/src/features/shipping-method/shipping-method.service.d.ts +0 -25
- package/src/features/shipping-method/shipping-method.service.js +1 -229
- package/src/features/shipping-method/shipping-zone.schema.js +1 -31
- package/src/features/webhook/webhook.handler.js +1 -50
- package/src/features/webhook/webhook.route.js +1 -33
- package/src/index.js +1 -6
- package/src/integrations/next.js +1 -82
- package/src/schemas/address.schema.d.ts +0 -8
- package/src/schemas/address.schema.js +1 -112
- package/src/schemas/currency.schema.d.ts +0 -42
- package/src/schemas/currency.schema.js +1 -118
- package/src/schemas/error.schema.js +1 -12
- package/src/schemas/index.js +1 -29
- package/src/schemas/locales.schema.js +1 -238
- package/src/schemas/number.schema.js +1 -29
- package/src/schemas/pagination.schema.js +1 -54
- package/src/schemas/params.schema.js +1 -20
- package/src/schemas/queries.schema.js +1 -6
- package/src/test/global-setup.d.ts +1 -0
- package/src/test/global-setup.js +1 -0
- package/src/test/integration/api-fixtures.d.ts +4 -16
- package/src/test/integration/api-fixtures.js +1 -225
- package/src/test/integration/seed.d.ts +81 -0
- package/src/test/integration/seed.js +1 -0
- package/src/test/integration/test-helpers.d.ts +107 -924
- package/src/test/integration/test-helpers.js +1 -1100
- package/src/test/setup-test-env.d.ts +1 -1
- package/src/test/setup-test-env.js +1 -29
- package/src/app.js.map +0 -1
- package/src/core/auth/auth.schema.js.map +0 -1
- package/src/core/auth/auth.util.js.map +0 -1
- package/src/core/auth/better-auth.lib.js.map +0 -1
- package/src/core/auth/generate-password-hash.util.js.map +0 -1
- package/src/core/auth/headers.schema.js.map +0 -1
- package/src/core/auth/user.schema.js.map +0 -1
- package/src/core/db/__generated__/client/browser.js.map +0 -1
- package/src/core/db/__generated__/client/client.js.map +0 -1
- package/src/core/db/__generated__/client/commonInputTypes.js.map +0 -1
- package/src/core/db/__generated__/client/enums.js.map +0 -1
- package/src/core/db/__generated__/client/internal/class.js.map +0 -1
- package/src/core/db/__generated__/client/internal/prismaNamespace.js.map +0 -1
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js.map +0 -1
- package/src/core/db/__generated__/client/models/Account.js.map +0 -1
- package/src/core/db/__generated__/client/models/Address.js.map +0 -1
- package/src/core/db/__generated__/client/models/Campaign.js.map +0 -1
- package/src/core/db/__generated__/client/models/ClosingTimes.js.map +0 -1
- package/src/core/db/__generated__/client/models/File.js.map +0 -1
- package/src/core/db/__generated__/client/models/Invitation.js.map +0 -1
- package/src/core/db/__generated__/client/models/LegalEntity.js.map +0 -1
- package/src/core/db/__generated__/client/models/Manufacturer.js.map +0 -1
- package/src/core/db/__generated__/client/models/ManufacturerTranslation.js.map +0 -1
- package/src/core/db/__generated__/client/models/Member.js.map +0 -1
- package/src/core/db/__generated__/client/models/Modifier.js.map +0 -1
- package/src/core/db/__generated__/client/models/ModifierGroup.js.map +0 -1
- package/src/core/db/__generated__/client/models/ModifierGroupTranslation.js.map +0 -1
- package/src/core/db/__generated__/client/models/OpeningTimes.js.map +0 -1
- package/src/core/db/__generated__/client/models/Order.js.map +0 -1
- package/src/core/db/__generated__/client/models/OrderItem.js.map +0 -1
- package/src/core/db/__generated__/client/models/OrderItemTranslation.js.map +0 -1
- package/src/core/db/__generated__/client/models/Organization.js.map +0 -1
- package/src/core/db/__generated__/client/models/OrganizationConfiguration.js.map +0 -1
- package/src/core/db/__generated__/client/models/Payment.js.map +0 -1
- package/src/core/db/__generated__/client/models/PaymentSession.js.map +0 -1
- package/src/core/db/__generated__/client/models/Product.js.map +0 -1
- package/src/core/db/__generated__/client/models/ProductCategory.js.map +0 -1
- package/src/core/db/__generated__/client/models/ProductCategoryTranslation.js.map +0 -1
- package/src/core/db/__generated__/client/models/ProductSnapshot.js.map +0 -1
- package/src/core/db/__generated__/client/models/ProductTranslation.js.map +0 -1
- package/src/core/db/__generated__/client/models/Reservation.js.map +0 -1
- package/src/core/db/__generated__/client/models/Session.js.map +0 -1
- package/src/core/db/__generated__/client/models/ShippingMethod.js.map +0 -1
- package/src/core/db/__generated__/client/models/ShippingZone.js.map +0 -1
- package/src/core/db/__generated__/client/models/User.js.map +0 -1
- package/src/core/db/__generated__/client/models/Verification.js.map +0 -1
- package/src/core/db/__generated__/client/models.js.map +0 -1
- package/src/core/db/index.js.map +0 -1
- package/src/core/exceptions/http-exception.js.map +0 -1
- package/src/core/hono/hono.js.map +0 -1
- package/src/core/lib/prisma.js.map +0 -1
- package/src/core/logging/pino.js.map +0 -1
- package/src/core/notifications/email.service.js.map +0 -1
- package/src/core/openapi/openapi.lib.js.map +0 -1
- package/src/core/types/google-maps.types.js.map +0 -1
- package/src/core/utils/currency.util.js.map +0 -1
- package/src/core/utils/env.util.js.map +0 -1
- package/src/core/utils/object.util.js.map +0 -1
- package/src/core/utils/translations.util.js.map +0 -1
- package/src/core/utils/zod.util.js.map +0 -1
- package/src/db.js.map +0 -1
- package/src/features/access/access.handler.js.map +0 -1
- package/src/features/access/access.route.js.map +0 -1
- package/src/features/access/access.schema.js.map +0 -1
- package/src/features/access/access.service.js.map +0 -1
- package/src/features/cart/cart.handler.js.map +0 -1
- package/src/features/cart/cart.route.js.map +0 -1
- package/src/features/cart/cart.schema.js.map +0 -1
- package/src/features/cart/cart.service.js.map +0 -1
- package/src/features/cart/cart.util.js.map +0 -1
- package/src/features/file/file.handler.js.map +0 -1
- package/src/features/file/file.route.js.map +0 -1
- package/src/features/file/file.schema.js.map +0 -1
- package/src/features/file/file.service.js.map +0 -1
- package/src/features/health/health.handler.js.map +0 -1
- package/src/features/health/health.route.js.map +0 -1
- package/src/features/index.js.map +0 -1
- package/src/features/location/location.handler.js.map +0 -1
- package/src/features/location/location.route.js.map +0 -1
- package/src/features/location/location.schema.js.map +0 -1
- package/src/features/location/location.service.js.map +0 -1
- package/src/features/manufacturer/manufacturer.handler.js.map +0 -1
- package/src/features/manufacturer/manufacturer.route.js.map +0 -1
- package/src/features/manufacturer/manufacturer.schema.js.map +0 -1
- package/src/features/manufacturer/manufacturer.service.js.map +0 -1
- package/src/features/order/emails/order-confirmation.email.js.map +0 -1
- package/src/features/order/emails/order-notification.email.js.map +0 -1
- package/src/features/order/fulfilment.schema.js.map +0 -1
- package/src/features/order/order.handler.js.map +0 -1
- package/src/features/order/order.route.js.map +0 -1
- package/src/features/order/order.schema.js.map +0 -1
- package/src/features/order/order.service.js.map +0 -1
- package/src/features/order/recipient.schema.js.map +0 -1
- package/src/features/organization/legal-entity.schema.js.map +0 -1
- package/src/features/organization/organization-configuration.schema.js.map +0 -1
- package/src/features/organization/organization.handler.js.map +0 -1
- package/src/features/organization/organization.route.js.map +0 -1
- package/src/features/organization/organization.schema.js.map +0 -1
- package/src/features/organization/organization.service.js.map +0 -1
- package/src/features/payment/payment.handler.js.map +0 -1
- package/src/features/payment/payment.route.js.map +0 -1
- package/src/features/payment/payment.schema.js.map +0 -1
- package/src/features/payment/payment.service.js.map +0 -1
- package/src/features/payment/stripe.service.js.map +0 -1
- package/src/features/product/product-modifier.schema.js.map +0 -1
- package/src/features/product/product.handler.js.map +0 -1
- package/src/features/product/product.route.js.map +0 -1
- package/src/features/product/product.schema.js.map +0 -1
- package/src/features/product/product.service.js.map +0 -1
- package/src/features/product-category/product-category.handler.js.map +0 -1
- package/src/features/product-category/product-category.route.js.map +0 -1
- package/src/features/product-category/product-category.schema.js.map +0 -1
- package/src/features/product-category/product-category.service.js.map +0 -1
- package/src/features/reservation/emails/reservation-cancellation.email.js.map +0 -1
- package/src/features/reservation/emails/reservation-confirmation.email.js.map +0 -1
- package/src/features/reservation/emails/reservation-notification.email.js.map +0 -1
- package/src/features/reservation/reservation.handler.js.map +0 -1
- package/src/features/reservation/reservation.route.js.map +0 -1
- package/src/features/reservation/reservation.schema.js.map +0 -1
- package/src/features/reservation/reservation.service.js.map +0 -1
- package/src/features/shipping/shipping.handler.js.map +0 -1
- package/src/features/shipping/shipping.route.js.map +0 -1
- package/src/features/shipping/shipping.service.js.map +0 -1
- package/src/features/shipping-method/shipping-method.handler.js.map +0 -1
- package/src/features/shipping-method/shipping-method.route.js.map +0 -1
- package/src/features/shipping-method/shipping-method.schema.js.map +0 -1
- package/src/features/shipping-method/shipping-method.service.js.map +0 -1
- package/src/features/shipping-method/shipping-zone.schema.js.map +0 -1
- package/src/features/webhook/webhook.handler.js.map +0 -1
- package/src/features/webhook/webhook.route.js.map +0 -1
- package/src/index.js.map +0 -1
- package/src/integrations/next.js.map +0 -1
- package/src/schemas/address.schema.js.map +0 -1
- package/src/schemas/currency.schema.js.map +0 -1
- package/src/schemas/error.schema.js.map +0 -1
- package/src/schemas/index.js.map +0 -1
- package/src/schemas/locales.schema.js.map +0 -1
- package/src/schemas/number.schema.js.map +0 -1
- package/src/schemas/pagination.schema.js.map +0 -1
- package/src/schemas/params.schema.js.map +0 -1
- package/src/schemas/queries.schema.js.map +0 -1
- package/src/test/integration/api-fixtures.js.map +0 -1
- package/src/test/integration/test-helpers.js.map +0 -1
- package/src/test/setup-test-env.js.map +0 -1
|
@@ -1,59 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createApiRouter } from "../../core/hono/hono";
|
|
3
|
-
import { productCategoryRoute } from "./product-category.route";
|
|
4
|
-
import { ProductCategoryService } from "./product-category.service";
|
|
5
|
-
export const buildProductCategoryHandler = (prisma) => {
|
|
6
|
-
const app = createApiRouter();
|
|
7
|
-
app.openapi(productCategoryRoute.createProductCategory, (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 ProductCategoryService(prisma);
|
|
13
|
-
const productCategory = yield service.createProductCategory(params.organizationId, user.id, body);
|
|
14
|
-
return c.json(productCategory, 201);
|
|
15
|
-
}));
|
|
16
|
-
app.openapi(productCategoryRoute.getProductCategory, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
-
const auth = c.get("auth");
|
|
18
|
-
const params = c.req.valid("param");
|
|
19
|
-
const query = c.req.valid("query");
|
|
20
|
-
yield auth.isGranted("read");
|
|
21
|
-
const service = new ProductCategoryService(prisma);
|
|
22
|
-
const productCategory = yield service.getProductCategory(params.organizationId, params.id, { locale: query.locale || null });
|
|
23
|
-
return c.json(productCategory, 200);
|
|
24
|
-
}));
|
|
25
|
-
app.openapi(productCategoryRoute.getProductCategories, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
-
const params = c.req.valid("param");
|
|
27
|
-
const query = c.req.valid("query");
|
|
28
|
-
const service = new ProductCategoryService(prisma);
|
|
29
|
-
const result = yield service.getProductCategories(params.organizationId, Object.assign(Object.assign({}, query), { locale: query.locale || null, published: query.published }));
|
|
30
|
-
return c.json(result, 200);
|
|
31
|
-
}));
|
|
32
|
-
app.openapi(productCategoryRoute.updateProductCategory, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
-
const auth = c.get("auth");
|
|
34
|
-
const params = c.req.valid("param");
|
|
35
|
-
const body = c.req.valid("json");
|
|
36
|
-
const user = yield auth.isGranted("update");
|
|
37
|
-
const service = new ProductCategoryService(prisma);
|
|
38
|
-
const updatedProductCategory = yield service.updateProductCategory(params.organizationId, params.id, user.id, body);
|
|
39
|
-
return c.json(updatedProductCategory, 200);
|
|
40
|
-
}));
|
|
41
|
-
app.openapi(productCategoryRoute.updateProductCategoryStatus, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
-
const auth = c.get("auth");
|
|
43
|
-
const params = c.req.valid("param");
|
|
44
|
-
const user = yield auth.isGranted("update");
|
|
45
|
-
const service = new ProductCategoryService(prisma);
|
|
46
|
-
const updatedProductCategory = yield service.updateProductCategoryStatus(params.organizationId, params.id, params.operation, user.id);
|
|
47
|
-
return c.json(updatedProductCategory, 200);
|
|
48
|
-
}));
|
|
49
|
-
app.openapi(productCategoryRoute.deleteProductCategory, (c) => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
-
const auth = c.get("auth");
|
|
51
|
-
const params = c.req.valid("param");
|
|
52
|
-
const user = yield auth.isGranted("delete");
|
|
53
|
-
const service = new ProductCategoryService(prisma);
|
|
54
|
-
yield service.deleteProductCategory(params.organizationId, params.id, user.id);
|
|
55
|
-
return c.body(null, 204);
|
|
56
|
-
}));
|
|
57
|
-
return app;
|
|
58
|
-
};
|
|
59
|
-
//# sourceMappingURL=product-category.handler.js.map
|
|
1
|
+
import{__awaiter as e}from"tslib";import{createApiRouter as o}from"../../core/hono/hono";import{productCategoryRoute as t}from"./product-category.route";import{ProductCategoryService as r}from"./product-category.service";export const buildProductCategoryHandler=i=>{const d=o();return d.openapi(t.createProductCategory,o=>e(void 0,void 0,void 0,function*(){const e=o.get("auth"),t=o.req.valid("param"),d=o.req.valid("json"),a=yield e.isGranted("create"),n=new r(i),u=yield n.createProductCategory(t.organizationId,a.id,d);return o.json(u,201)})),d.openapi(t.getProductCategory,o=>e(void 0,void 0,void 0,function*(){const e=o.get("auth"),t=o.req.valid("param"),d=o.req.valid("query");yield e.isGranted("read");const a=new r(i),n=yield a.getProductCategory(t.organizationId,t.id,{locale:d.locale||null});return o.json(n,200)})),d.openapi(t.getProductCategories,o=>e(void 0,void 0,void 0,function*(){const e=o.req.valid("param"),t=o.req.valid("query"),d=new r(i),a=yield d.getProductCategories(e.organizationId,Object.assign(Object.assign({},t),{locale:t.locale||null,published:t.published}));return o.json(a,200)})),d.openapi(t.updateProductCategory,o=>e(void 0,void 0,void 0,function*(){const e=o.get("auth"),t=o.req.valid("param"),d=o.req.valid("json"),a=yield e.isGranted("update"),n=new r(i),u=yield n.updateProductCategory(t.organizationId,t.id,a.id,d);return o.json(u,200)})),d.openapi(t.updateProductCategoryStatus,o=>e(void 0,void 0,void 0,function*(){const e=o.get("auth"),t=o.req.valid("param"),d=yield e.isGranted("update"),a=new r(i),n=yield a.updateProductCategoryStatus(t.organizationId,t.id,t.operation,d.id);return o.json(n,200)})),d.openapi(t.deleteProductCategory,o=>e(void 0,void 0,void 0,function*(){const e=o.get("auth"),t=o.req.valid("param"),d=yield e.isGranted("delete"),a=new r(i);return yield a.deleteProductCategory(t.organizationId,t.id,d.id),o.body(null,204)})),d};
|
|
@@ -1,139 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createApiRoute } from "../../core/hono/hono";
|
|
3
|
-
import { CreateProductCategorySchema, ErrorSchema, HeaderSchema, LocalizedProductCategorySchema, OrganizationParams, OrganizationWithIdParams, PaginationMetaSchema, PaginationQuerySchema, ProductCategorySchema, UpdateProductCategorySchema, } from "../../schemas";
|
|
4
|
-
import { GetResourceQuerySchema } from "../../schemas/queries.schema";
|
|
5
|
-
const getProductCategoriesRoute = createApiRoute({
|
|
6
|
-
description: "Fetches a paginated list of product categories for a specific organization",
|
|
7
|
-
headers: HeaderSchema,
|
|
8
|
-
method: "GET",
|
|
9
|
-
operationId: "getProductCategories",
|
|
10
|
-
path: "/:organizationId/product-categories",
|
|
11
|
-
pathParams: OrganizationParams,
|
|
12
|
-
query: PaginationQuerySchema,
|
|
13
|
-
responses: {
|
|
14
|
-
200: z.object({
|
|
15
|
-
list: z.array(z.union([ProductCategorySchema, LocalizedProductCategorySchema])),
|
|
16
|
-
meta: PaginationMetaSchema,
|
|
17
|
-
}),
|
|
18
|
-
400: ErrorSchema,
|
|
19
|
-
401: ErrorSchema,
|
|
20
|
-
},
|
|
21
|
-
summary: "Get Product Categories",
|
|
22
|
-
tags: ["ProductCategory"],
|
|
23
|
-
});
|
|
24
|
-
const createProductCategoryRoute = createApiRoute({
|
|
25
|
-
body: CreateProductCategorySchema,
|
|
26
|
-
description: "Creates a new product category for a specific organization",
|
|
27
|
-
headers: HeaderSchema,
|
|
28
|
-
method: "POST",
|
|
29
|
-
operationId: "createProductCategory",
|
|
30
|
-
path: "/:organizationId/product-categories",
|
|
31
|
-
pathParams: OrganizationParams,
|
|
32
|
-
responses: {
|
|
33
|
-
201: ProductCategorySchema,
|
|
34
|
-
400: ErrorSchema,
|
|
35
|
-
401: ErrorSchema,
|
|
36
|
-
404: ErrorSchema,
|
|
37
|
-
},
|
|
38
|
-
summary: "Create Product Category",
|
|
39
|
-
tags: ["ProductCategory"],
|
|
40
|
-
});
|
|
41
|
-
const getProductCategoryRoute = createApiRoute({
|
|
42
|
-
description: "Fetches a specific product category by ID",
|
|
43
|
-
headers: HeaderSchema,
|
|
44
|
-
method: "GET",
|
|
45
|
-
operationId: "getProductCategory",
|
|
46
|
-
path: "/:organizationId/product-categories/:id",
|
|
47
|
-
pathParams: OrganizationWithIdParams,
|
|
48
|
-
query: GetResourceQuerySchema,
|
|
49
|
-
responses: {
|
|
50
|
-
200: z.union([ProductCategorySchema, LocalizedProductCategorySchema]),
|
|
51
|
-
401: ErrorSchema,
|
|
52
|
-
404: ErrorSchema,
|
|
53
|
-
},
|
|
54
|
-
summary: "Get Product Category",
|
|
55
|
-
tags: ["ProductCategory"],
|
|
56
|
-
});
|
|
57
|
-
const updateProductCategoryRoute = createApiRoute({
|
|
58
|
-
body: UpdateProductCategorySchema,
|
|
59
|
-
description: "Updates a specific product category by ID",
|
|
60
|
-
headers: HeaderSchema,
|
|
61
|
-
method: "PATCH",
|
|
62
|
-
operationId: "updateProductCategory",
|
|
63
|
-
path: "/:organizationId/product-categories/:id",
|
|
64
|
-
pathParams: OrganizationWithIdParams,
|
|
65
|
-
responses: {
|
|
66
|
-
200: ProductCategorySchema,
|
|
67
|
-
400: ErrorSchema,
|
|
68
|
-
401: ErrorSchema,
|
|
69
|
-
404: ErrorSchema,
|
|
70
|
-
},
|
|
71
|
-
summary: "Update Product Category",
|
|
72
|
-
tags: ["ProductCategory"],
|
|
73
|
-
});
|
|
74
|
-
const updateProductCategoryStatusRoute = createApiRoute({
|
|
75
|
-
description: "Sets the published status of an existing product category based on the operation (publish or unpublish)",
|
|
76
|
-
headers: HeaderSchema,
|
|
77
|
-
method: "POST",
|
|
78
|
-
operationId: "updateProductCategoryStatus",
|
|
79
|
-
path: "/:organizationId/product-categories/:id/status/:operation",
|
|
80
|
-
pathParams: z.object({
|
|
81
|
-
id: z.string().openapi({
|
|
82
|
-
description: "The organization ID",
|
|
83
|
-
example: "ckel0e8qw00004n5p5w6fznym",
|
|
84
|
-
param: {
|
|
85
|
-
in: "path",
|
|
86
|
-
name: "id",
|
|
87
|
-
},
|
|
88
|
-
}),
|
|
89
|
-
operation: z.enum(["publish", "unpublish"]).openapi({
|
|
90
|
-
description: "The operation to perform on the product category",
|
|
91
|
-
example: "publish",
|
|
92
|
-
param: {
|
|
93
|
-
in: "path",
|
|
94
|
-
name: "operation",
|
|
95
|
-
},
|
|
96
|
-
}),
|
|
97
|
-
organizationId: z.string().openapi({
|
|
98
|
-
description: "The organization ID",
|
|
99
|
-
example: "ckel0e8qw00004n5p5w6fznym",
|
|
100
|
-
param: {
|
|
101
|
-
in: "path",
|
|
102
|
-
name: "organizationId",
|
|
103
|
-
},
|
|
104
|
-
}),
|
|
105
|
-
}),
|
|
106
|
-
responses: {
|
|
107
|
-
200: ProductCategorySchema,
|
|
108
|
-
400: ErrorSchema,
|
|
109
|
-
401: ErrorSchema,
|
|
110
|
-
404: ErrorSchema,
|
|
111
|
-
},
|
|
112
|
-
summary: "Publish or Unpublish Product Category",
|
|
113
|
-
tags: ["ProductCategory"],
|
|
114
|
-
});
|
|
115
|
-
const deleteProductCategoryRoute = createApiRoute({
|
|
116
|
-
description: "Deletes a specific product category by ID",
|
|
117
|
-
headers: HeaderSchema,
|
|
118
|
-
method: "DELETE",
|
|
119
|
-
operationId: "deleteProductCategory",
|
|
120
|
-
path: "/:organizationId/product-categories/:id",
|
|
121
|
-
pathParams: OrganizationWithIdParams,
|
|
122
|
-
responses: {
|
|
123
|
-
204: null,
|
|
124
|
-
400: ErrorSchema,
|
|
125
|
-
401: ErrorSchema,
|
|
126
|
-
404: ErrorSchema,
|
|
127
|
-
},
|
|
128
|
-
summary: "Delete Product Category",
|
|
129
|
-
tags: ["ProductCategory"],
|
|
130
|
-
});
|
|
131
|
-
export const productCategoryRoute = {
|
|
132
|
-
getProductCategories: getProductCategoriesRoute,
|
|
133
|
-
createProductCategory: createProductCategoryRoute,
|
|
134
|
-
getProductCategory: getProductCategoryRoute,
|
|
135
|
-
updateProductCategory: updateProductCategoryRoute,
|
|
136
|
-
updateProductCategoryStatus: updateProductCategoryStatusRoute,
|
|
137
|
-
deleteProductCategory: deleteProductCategoryRoute,
|
|
138
|
-
};
|
|
139
|
-
//# sourceMappingURL=product-category.route.js.map
|
|
1
|
+
import{z as t}from"@hono/zod-openapi";import{createApiRoute as e}from"../../core/hono/hono";import{CreateProductCategorySchema as o,ErrorSchema as a,HeaderSchema as r,LocalizedProductCategorySchema as i,OrganizationParams as s,OrganizationWithIdParams as p,PaginationMetaSchema as d,PaginationQuerySchema as n,ProductCategorySchema as c,UpdateProductCategorySchema as u}from"../../schemas";import{GetResourceQuerySchema as g}from"../../schemas/queries.schema";const h=e({description:"Fetches a paginated list of product categories for a specific organization",headers:r,method:"GET",operationId:"getProductCategories",path:"/:organizationId/product-categories",pathParams:s,query:n,responses:{200:t.object({list:t.array(t.union([c,i])),meta:d}),400:a,401:a},summary:"Get Product Categories",tags:["ProductCategory"]}),m=e({body:o,description:"Creates a new product category for a specific organization",headers:r,method:"POST",operationId:"createProductCategory",path:"/:organizationId/product-categories",pathParams:s,responses:{201:c,400:a,401:a,404:a},summary:"Create Product Category",tags:["ProductCategory"]}),y=e({description:"Fetches a specific product category by ID",headers:r,method:"GET",operationId:"getProductCategory",path:"/:organizationId/product-categories/:id",pathParams:p,query:g,responses:{200:t.union([c,i]),401:a,404:a},summary:"Get Product Category",tags:["ProductCategory"]}),P=e({body:u,description:"Updates a specific product category by ID",headers:r,method:"PATCH",operationId:"updateProductCategory",path:"/:organizationId/product-categories/:id",pathParams:p,responses:{200:c,400:a,401:a,404:a},summary:"Update Product Category",tags:["ProductCategory"]}),C=e({description:"Sets the published status of an existing product category based on the operation (publish or unpublish)",headers:r,method:"POST",operationId:"updateProductCategoryStatus",path:"/:organizationId/product-categories/:id/status/:operation",pathParams:t.object({id:t.string().openapi({description:"The organization ID",example:"ckel0e8qw00004n5p5w6fznym",param:{in:"path",name:"id"}}),operation:t.enum(["publish","unpublish"]).openapi({description:"The operation to perform on the product category",example:"publish",param:{in:"path",name:"operation"}}),organizationId:t.string().openapi({description:"The organization ID",example:"ckel0e8qw00004n5p5w6fznym",param:{in:"path",name:"organizationId"}})}),responses:{200:c,400:a,401:a,404:a},summary:"Publish or Unpublish Product Category",tags:["ProductCategory"]}),l=e({description:"Deletes a specific product category by ID",headers:r,method:"DELETE",operationId:"deleteProductCategory",path:"/:organizationId/product-categories/:id",pathParams:p,responses:{204:null,400:a,401:a,404:a},summary:"Delete Product Category",tags:["ProductCategory"]});export const productCategoryRoute={getProductCategories:h,createProductCategory:m,getProductCategory:y,updateProductCategory:P,updateProductCategoryStatus:C,deleteProductCategory:l};
|
|
@@ -1,86 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { validateRequiredForDefaultLocale } from "../../core/utils/zod.util";
|
|
3
|
-
import { FileSchema } from "../file/file.schema";
|
|
4
|
-
export const ProductCategorySchema = z
|
|
5
|
-
.object({
|
|
6
|
-
id: z.string().openapi({
|
|
7
|
-
example: "clf9876543210abcdef",
|
|
8
|
-
description: "ID of the product category",
|
|
9
|
-
}),
|
|
10
|
-
slug: z.string().openapi({
|
|
11
|
-
example: "electronics",
|
|
12
|
-
description: "Slug of the product category",
|
|
13
|
-
}),
|
|
14
|
-
image: FileSchema.nullable().optional().openapi({
|
|
15
|
-
description: "Image of the product category",
|
|
16
|
-
}),
|
|
17
|
-
createdAt: z.date(),
|
|
18
|
-
publishedAt: z.date().nullable().optional().openapi({
|
|
19
|
-
description: "Timestamp when the product category was published",
|
|
20
|
-
}),
|
|
21
|
-
translations: z
|
|
22
|
-
.array(z.object({
|
|
23
|
-
locale: z.string().min(1, "Locale is required").openapi({
|
|
24
|
-
example: "en-US",
|
|
25
|
-
description: "Locale code for the translation",
|
|
26
|
-
}),
|
|
27
|
-
title: z.string().default("").openapi({
|
|
28
|
-
example: "Electronics",
|
|
29
|
-
description: "Name of the product category in the specified locale",
|
|
30
|
-
}),
|
|
31
|
-
description: z
|
|
32
|
-
.string()
|
|
33
|
-
.max(6000, "Maximum character limit is 6000")
|
|
34
|
-
.nullable()
|
|
35
|
-
.default("")
|
|
36
|
-
.optional()
|
|
37
|
-
.openapi({
|
|
38
|
-
example: "A category for electronic devices.",
|
|
39
|
-
description: "Description of the product category in the specified locale",
|
|
40
|
-
}),
|
|
41
|
-
}))
|
|
42
|
-
.openapi({
|
|
43
|
-
description: "List of translations for the product category",
|
|
44
|
-
}),
|
|
45
|
-
})
|
|
46
|
-
.openapi("ProductCategory");
|
|
47
|
-
export const LocalizedProductCategorySchema = ProductCategorySchema.omit({
|
|
48
|
-
translations: true,
|
|
49
|
-
})
|
|
50
|
-
.extend({
|
|
51
|
-
title: z.string().default(""),
|
|
52
|
-
description: z.string().default(""),
|
|
53
|
-
})
|
|
54
|
-
.openapi("LocalizedProductCategory");
|
|
55
|
-
export const CreateProductCategorySchema = ProductCategorySchema.pick({
|
|
56
|
-
slug: true,
|
|
57
|
-
image: true,
|
|
58
|
-
translations: true,
|
|
59
|
-
})
|
|
60
|
-
.extend({
|
|
61
|
-
defaultLocale: z.string().min(1, "Default locale is required").openapi({
|
|
62
|
-
description: "The default locale for the product category",
|
|
63
|
-
}),
|
|
64
|
-
imageId: z.string().cuid().optional().openapi({
|
|
65
|
-
description: "ID of the image for the product category",
|
|
66
|
-
}),
|
|
67
|
-
})
|
|
68
|
-
.superRefine(validateRequiredForDefaultLocale("title"))
|
|
69
|
-
.openapi("CreateProductCategory");
|
|
70
|
-
export const UpdateProductCategorySchema = ProductCategorySchema.pick({
|
|
71
|
-
slug: true,
|
|
72
|
-
image: true,
|
|
73
|
-
translations: true,
|
|
74
|
-
})
|
|
75
|
-
.extend({
|
|
76
|
-
defaultLocale: z.string().min(1, "Default locale is required").openapi({
|
|
77
|
-
description: "The default locale for the product category",
|
|
78
|
-
}),
|
|
79
|
-
imageId: z.string().cuid().optional().nullable().openapi({
|
|
80
|
-
description: "ID of the image for the product category",
|
|
81
|
-
}),
|
|
82
|
-
})
|
|
83
|
-
.partial()
|
|
84
|
-
.superRefine(validateRequiredForDefaultLocale("title"))
|
|
85
|
-
.openapi("UpdateProductCategory");
|
|
86
|
-
//# sourceMappingURL=product-category.schema.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{validateRequiredForDefaultLocale as t}from"../../core/utils/zod.util";import{FileSchema as o}from"../file/file.schema";export const ProductCategorySchema=e.object({id:e.string().openapi({example:"clf9876543210abcdef",description:"ID of the product category"}),slug:e.string().openapi({example:"electronics",description:"Slug of the product category"}),image:o.nullable().optional().openapi({description:"Image of the product category"}),createdAt:e.date(),publishedAt:e.date().nullable().optional().openapi({description:"Timestamp when the product category was published"}),translations:e.array(e.object({locale:e.string().min(1,"Locale is required").openapi({example:"en-US",description:"Locale code for the translation"}),title:e.string().default("").openapi({example:"Electronics",description:"Name of the product category in the specified locale"}),description:e.string().max(6e3,"Maximum character limit is 6000").nullable().default("").optional().openapi({example:"A category for electronic devices.",description:"Description of the product category in the specified locale"})})).openapi({description:"List of translations for the product category"})}).openapi("ProductCategory");export const LocalizedProductCategorySchema=ProductCategorySchema.omit({translations:!0}).extend({title:e.string().default(""),description:e.string().default("")}).openapi("LocalizedProductCategory");export const CreateProductCategorySchema=ProductCategorySchema.pick({slug:!0,image:!0,translations:!0}).extend({defaultLocale:e.string().min(1,"Default locale is required").openapi({description:"The default locale for the product category"}),imageId:e.string().cuid().optional().openapi({description:"ID of the image for the product category"})}).superRefine(t("title")).openapi("CreateProductCategory");export const UpdateProductCategorySchema=ProductCategorySchema.pick({slug:!0,image:!0,translations:!0}).extend({defaultLocale:e.string().min(1,"Default locale is required").openapi({description:"The default locale for the product category"}),imageId:e.string().cuid().optional().nullable().openapi({description:"ID of the image for the product category"})}).partial().superRefine(t("title")).openapi("UpdateProductCategory");
|
|
@@ -4,14 +4,7 @@ import { CreateProductCategorySchema, UpdateProductCategorySchema } from "../../
|
|
|
4
4
|
declare class ProductCategoryService {
|
|
5
5
|
private readonly prisma;
|
|
6
6
|
constructor(prisma: PrismaClientType);
|
|
7
|
-
/**
|
|
8
|
-
* Find a product category by ID and organization ID
|
|
9
|
-
* @throws HttpException with 404 status if product category is not found
|
|
10
|
-
*/
|
|
11
7
|
private findProductCategory;
|
|
12
|
-
/**
|
|
13
|
-
* Create a new product category
|
|
14
|
-
*/
|
|
15
8
|
createProductCategory(organizationId: string, userId: string, body: z.infer<typeof CreateProductCategorySchema>): Promise<{
|
|
16
9
|
id: string;
|
|
17
10
|
slug: string;
|
|
@@ -30,9 +23,6 @@ declare class ProductCategoryService {
|
|
|
30
23
|
} | null | undefined;
|
|
31
24
|
publishedAt?: Date | null | undefined;
|
|
32
25
|
}>;
|
|
33
|
-
/**
|
|
34
|
-
* Get a product category by ID
|
|
35
|
-
*/
|
|
36
26
|
getProductCategory(organizationId: string, id: string, query: {
|
|
37
27
|
locale?: string | null;
|
|
38
28
|
}): Promise<{
|
|
@@ -67,9 +57,6 @@ declare class ProductCategoryService {
|
|
|
67
57
|
} | null | undefined;
|
|
68
58
|
publishedAt?: Date | null | undefined;
|
|
69
59
|
}>;
|
|
70
|
-
/**
|
|
71
|
-
* Get a paginated list of product categories
|
|
72
|
-
*/
|
|
73
60
|
getProductCategories(organizationId: string, query: {
|
|
74
61
|
page?: number;
|
|
75
62
|
limit?: number;
|
|
@@ -130,9 +117,6 @@ declare class ProductCategoryService {
|
|
|
130
117
|
publishedAt?: Date | null | undefined;
|
|
131
118
|
}[];
|
|
132
119
|
}>;
|
|
133
|
-
/**
|
|
134
|
-
* Update a product category
|
|
135
|
-
*/
|
|
136
120
|
updateProductCategory(organizationId: string, id: string, userId: string, body: z.infer<typeof UpdateProductCategorySchema>): Promise<{
|
|
137
121
|
id: string;
|
|
138
122
|
slug: string;
|
|
@@ -151,9 +135,6 @@ declare class ProductCategoryService {
|
|
|
151
135
|
} | null | undefined;
|
|
152
136
|
publishedAt?: Date | null | undefined;
|
|
153
137
|
}>;
|
|
154
|
-
/**
|
|
155
|
-
* Update product category status (publish/unpublish)
|
|
156
|
-
*/
|
|
157
138
|
updateProductCategoryStatus(organizationId: string, id: string, operation: "publish" | "unpublish", userId: string): Promise<{
|
|
158
139
|
id: string;
|
|
159
140
|
slug: string;
|
|
@@ -172,9 +153,6 @@ declare class ProductCategoryService {
|
|
|
172
153
|
} | null | undefined;
|
|
173
154
|
publishedAt?: Date | null | undefined;
|
|
174
155
|
}>;
|
|
175
|
-
/**
|
|
176
|
-
* Delete a product category (soft delete)
|
|
177
|
-
*/
|
|
178
156
|
deleteProductCategory(organizationId: string, id: string, userId: string): Promise<void>;
|
|
179
157
|
}
|
|
180
158
|
export { ProductCategoryService };
|
|
@@ -1,220 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { z } from "@hono/zod-openapi";
|
|
3
|
-
import { HttpException } from "../../core/exceptions/http-exception";
|
|
4
|
-
import { flattenTranslationData } from "../../core/utils/zod.util";
|
|
5
|
-
import { LocalizedProductCategorySchema, PaginationMetaSchema, ProductCategorySchema, } from "../../schemas";
|
|
6
|
-
class ProductCategoryService {
|
|
7
|
-
constructor(prisma) {
|
|
8
|
-
this.prisma = prisma;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Find a product category by ID and organization ID
|
|
12
|
-
* @throws HttpException with 404 status if product category is not found
|
|
13
|
-
*/
|
|
14
|
-
findProductCategory(id, organizationId, options) {
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const productCategory = yield this.prisma.productCategory.findUnique({
|
|
17
|
-
where: {
|
|
18
|
-
id,
|
|
19
|
-
organizationId,
|
|
20
|
-
deletedAt: null,
|
|
21
|
-
},
|
|
22
|
-
include: options === null || options === void 0 ? void 0 : options.include,
|
|
23
|
-
});
|
|
24
|
-
if (!productCategory) {
|
|
25
|
-
throw new HttpException(404, "Product category not found");
|
|
26
|
-
}
|
|
27
|
-
return productCategory;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Create a new product category
|
|
32
|
-
*/
|
|
33
|
-
createProductCategory(organizationId, userId, body) {
|
|
34
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
// Create new product category
|
|
36
|
-
const productCategory = yield this.prisma.productCategory.create({
|
|
37
|
-
data: {
|
|
38
|
-
slug: body.slug,
|
|
39
|
-
organizationId,
|
|
40
|
-
createdBy: userId,
|
|
41
|
-
imageId: body.imageId,
|
|
42
|
-
translations: {
|
|
43
|
-
create: body.translations,
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
include: {
|
|
47
|
-
translations: true,
|
|
48
|
-
image: true,
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
return ProductCategorySchema.parse(productCategory);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Get a product category by ID
|
|
56
|
-
*/
|
|
57
|
-
getProductCategory(organizationId, id, query) {
|
|
58
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
// Extract locale from query parameter
|
|
60
|
-
const { locale } = query;
|
|
61
|
-
const productCategory = yield this.findProductCategory(id, organizationId, {
|
|
62
|
-
include: {
|
|
63
|
-
image: true,
|
|
64
|
-
translations: locale
|
|
65
|
-
? {
|
|
66
|
-
where: { locale },
|
|
67
|
-
}
|
|
68
|
-
: true,
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
if (!locale) {
|
|
72
|
-
return ProductCategorySchema.parse(productCategory);
|
|
73
|
-
}
|
|
74
|
-
// If locale is provided, flatten the translations data and use LocalizedProductCategorySchema
|
|
75
|
-
return LocalizedProductCategorySchema.parse(flattenTranslationData(productCategory));
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Get a paginated list of product categories
|
|
80
|
-
*/
|
|
81
|
-
getProductCategories(organizationId, query) {
|
|
82
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
const { page = 1, limit = 10, search, locale, published } = query;
|
|
84
|
-
// Fetch product categories with pagination
|
|
85
|
-
const [list, meta] = yield this.prisma.productCategory
|
|
86
|
-
.paginate({
|
|
87
|
-
orderBy: {
|
|
88
|
-
priority: "asc",
|
|
89
|
-
},
|
|
90
|
-
where: Object.assign(Object.assign({ organizationId, deletedAt: null }, (search && {
|
|
91
|
-
slug: {
|
|
92
|
-
contains: search,
|
|
93
|
-
mode: "insensitive",
|
|
94
|
-
},
|
|
95
|
-
})), (published && {
|
|
96
|
-
publishedAt: {
|
|
97
|
-
not: null,
|
|
98
|
-
},
|
|
99
|
-
})),
|
|
100
|
-
include: {
|
|
101
|
-
image: true,
|
|
102
|
-
translations: locale
|
|
103
|
-
? {
|
|
104
|
-
where: { locale },
|
|
105
|
-
}
|
|
106
|
-
: true,
|
|
107
|
-
},
|
|
108
|
-
})
|
|
109
|
-
.withPages({
|
|
110
|
-
page,
|
|
111
|
-
limit,
|
|
112
|
-
});
|
|
113
|
-
if (!locale) {
|
|
114
|
-
// Return standard response with ProductCategorySchema
|
|
115
|
-
return z
|
|
116
|
-
.object({
|
|
117
|
-
meta: PaginationMetaSchema,
|
|
118
|
-
list: z.array(ProductCategorySchema),
|
|
119
|
-
})
|
|
120
|
-
.parse({
|
|
121
|
-
meta,
|
|
122
|
-
list,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
// Process the list for localization
|
|
126
|
-
const localizedList = list.map((item) => flattenTranslationData(item));
|
|
127
|
-
// Return localized response with LocalizedProductCategorySchema
|
|
128
|
-
return z
|
|
129
|
-
.object({
|
|
130
|
-
meta: PaginationMetaSchema,
|
|
131
|
-
list: z.array(LocalizedProductCategorySchema),
|
|
132
|
-
})
|
|
133
|
-
.parse({
|
|
134
|
-
meta,
|
|
135
|
-
list: localizedList,
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Update a product category
|
|
141
|
-
*/
|
|
142
|
-
updateProductCategory(organizationId, id, userId, body) {
|
|
143
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
-
// Fetch product category by id
|
|
145
|
-
yield this.findProductCategory(id, organizationId);
|
|
146
|
-
// Update product category
|
|
147
|
-
const updatedProductCategory = yield this.prisma.productCategory.update({
|
|
148
|
-
where: {
|
|
149
|
-
id,
|
|
150
|
-
organizationId,
|
|
151
|
-
deletedAt: null,
|
|
152
|
-
},
|
|
153
|
-
data: {
|
|
154
|
-
updatedBy: userId,
|
|
155
|
-
slug: body.slug,
|
|
156
|
-
translations: {
|
|
157
|
-
deleteMany: {},
|
|
158
|
-
create: body.translations || [],
|
|
159
|
-
},
|
|
160
|
-
imageId: body.imageId,
|
|
161
|
-
},
|
|
162
|
-
include: {
|
|
163
|
-
image: true,
|
|
164
|
-
translations: true,
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
return ProductCategorySchema.parse(updatedProductCategory);
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Update product category status (publish/unpublish)
|
|
172
|
-
*/
|
|
173
|
-
updateProductCategoryStatus(organizationId, id, operation, userId) {
|
|
174
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
-
// Fetch the product category by id
|
|
176
|
-
yield this.findProductCategory(id, organizationId);
|
|
177
|
-
const updatedProductCategory = yield this.prisma.productCategory.update({
|
|
178
|
-
where: {
|
|
179
|
-
id,
|
|
180
|
-
organizationId,
|
|
181
|
-
deletedAt: null,
|
|
182
|
-
},
|
|
183
|
-
data: {
|
|
184
|
-
publishedAt: operation === "publish" ? new Date() : null,
|
|
185
|
-
publishedBy: operation === "publish" ? userId : null,
|
|
186
|
-
updatedBy: userId,
|
|
187
|
-
},
|
|
188
|
-
include: {
|
|
189
|
-
image: true,
|
|
190
|
-
translations: true,
|
|
191
|
-
},
|
|
192
|
-
});
|
|
193
|
-
return ProductCategorySchema.parse(updatedProductCategory);
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Delete a product category (soft delete)
|
|
198
|
-
*/
|
|
199
|
-
deleteProductCategory(organizationId, id, userId) {
|
|
200
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
-
// Fetch product category by id
|
|
202
|
-
yield this.findProductCategory(id, organizationId);
|
|
203
|
-
// Soft delete product category
|
|
204
|
-
yield this.prisma.productCategory.update({
|
|
205
|
-
where: {
|
|
206
|
-
id,
|
|
207
|
-
organizationId,
|
|
208
|
-
deletedAt: null,
|
|
209
|
-
},
|
|
210
|
-
data: {
|
|
211
|
-
deletedAt: new Date(),
|
|
212
|
-
deletedBy: userId,
|
|
213
|
-
},
|
|
214
|
-
});
|
|
215
|
-
return;
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
export { ProductCategoryService };
|
|
220
|
-
//# sourceMappingURL=product-category.service.js.map
|
|
1
|
+
import{__awaiter as t}from"tslib";import{z as e}from"@hono/zod-openapi";import{HttpException as i}from"../../core/exceptions/http-exception";import{flattenTranslationData as r}from"../../core/utils/zod.util";import{LocalizedProductCategorySchema as o,PaginationMetaSchema as a,ProductCategorySchema as d}from"../../schemas";class n{constructor(t){this.prisma=t}findProductCategory(e,r,o){return t(this,void 0,void 0,function*(){const t=yield this.prisma.productCategory.findUnique({where:{id:e,organizationId:r,deletedAt:null},include:null==o?void 0:o.include});if(!t)throw new i(404,"Product category not found");return t})}createProductCategory(e,i,r){return t(this,void 0,void 0,function*(){const t=yield this.prisma.productCategory.create({data:{slug:r.slug,organizationId:e,createdBy:i,imageId:r.imageId,translations:{create:r.translations}},include:{translations:!0,image:!0}});return d.parse(t)})}getProductCategory(e,i,a){return t(this,void 0,void 0,function*(){const{locale:t}=a,n=yield this.findProductCategory(i,e,{include:{image:!0,translations:!t||{where:{locale:t}}}});return t?o.parse(r(n)):d.parse(n)})}getProductCategories(i,n){return t(this,void 0,void 0,function*(){const{page:t=1,limit:s=10,search:l,locale:u,published:c}=n,[p,g]=yield this.prisma.productCategory.paginate({orderBy:{priority:"asc"},where:Object.assign(Object.assign({organizationId:i,deletedAt:null},l&&{slug:{contains:l,mode:"insensitive"}}),c&&{publishedAt:{not:null}}),include:{image:!0,translations:!u||{where:{locale:u}}}}).withPages({page:t,limit:s});if(!u)return e.object({meta:a,list:e.array(d)}).parse({meta:g,list:p});const h=p.map(t=>r(t));return e.object({meta:a,list:e.array(o)}).parse({meta:g,list:h})})}updateProductCategory(e,i,r,o){return t(this,void 0,void 0,function*(){yield this.findProductCategory(i,e);const t=yield this.prisma.productCategory.update({where:{id:i,organizationId:e,deletedAt:null},data:{updatedBy:r,slug:o.slug,translations:{deleteMany:{},create:o.translations||[]},imageId:o.imageId},include:{image:!0,translations:!0}});return d.parse(t)})}updateProductCategoryStatus(e,i,r,o){return t(this,void 0,void 0,function*(){yield this.findProductCategory(i,e);const t=yield this.prisma.productCategory.update({where:{id:i,organizationId:e,deletedAt:null},data:{publishedAt:"publish"===r?new Date:null,publishedBy:"publish"===r?o:null,updatedBy:o},include:{image:!0,translations:!0}});return d.parse(t)})}deleteProductCategory(e,i,r){return t(this,void 0,void 0,function*(){yield this.findProductCategory(i,e),yield this.prisma.productCategory.update({where:{id:i,organizationId:e,deletedAt:null},data:{deletedAt:new Date,deletedBy:r}})})}}export{n as ProductCategoryService};
|