@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,97 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createApiRoute } from "../../core/hono/hono";
|
|
3
|
-
import { ErrorSchema, HeaderSchema, OrganizationParams, OrganizationWithIdParams, PaginationMetaSchema, PaginationQuerySchema, } from "../../schemas";
|
|
4
|
-
import { GetResourceQuerySchema } from "../../schemas/queries.schema";
|
|
5
|
-
import { CreateManufacturerSchema, LocalizedManufacturerSchema, ManufacturerSchema, UpdateManufacturerSchema, } from "./manufacturer.schema";
|
|
6
|
-
const getManufacturersRoute = createApiRoute({
|
|
7
|
-
description: "Fetches a paginated list of manufacturers for a specific organization",
|
|
8
|
-
headers: HeaderSchema,
|
|
9
|
-
method: "GET",
|
|
10
|
-
operationId: "getManufacturers",
|
|
11
|
-
path: "/:organizationId/manufacturers",
|
|
12
|
-
pathParams: OrganizationParams,
|
|
13
|
-
query: PaginationQuerySchema,
|
|
14
|
-
responses: {
|
|
15
|
-
200: z.object({
|
|
16
|
-
list: z.array(z.union([ManufacturerSchema, LocalizedManufacturerSchema])),
|
|
17
|
-
meta: PaginationMetaSchema,
|
|
18
|
-
}),
|
|
19
|
-
400: ErrorSchema,
|
|
20
|
-
401: ErrorSchema,
|
|
21
|
-
},
|
|
22
|
-
summary: "Get Manufacturers",
|
|
23
|
-
tags: ["Manufacturer"],
|
|
24
|
-
});
|
|
25
|
-
const createManufacturerRoute = createApiRoute({
|
|
26
|
-
body: CreateManufacturerSchema,
|
|
27
|
-
description: "Creates a new manufacturer for a specific organization",
|
|
28
|
-
headers: HeaderSchema,
|
|
29
|
-
method: "POST",
|
|
30
|
-
operationId: "createManufacturer",
|
|
31
|
-
path: "/:organizationId/manufacturers",
|
|
32
|
-
pathParams: OrganizationParams,
|
|
33
|
-
responses: {
|
|
34
|
-
201: ManufacturerSchema,
|
|
35
|
-
400: ErrorSchema,
|
|
36
|
-
401: ErrorSchema,
|
|
37
|
-
404: ErrorSchema,
|
|
38
|
-
},
|
|
39
|
-
summary: "Create Manufacturer",
|
|
40
|
-
tags: ["Manufacturer"],
|
|
41
|
-
});
|
|
42
|
-
const getManufacturerRoute = createApiRoute({
|
|
43
|
-
headers: HeaderSchema,
|
|
44
|
-
method: "GET",
|
|
45
|
-
operationId: "getManufacturer",
|
|
46
|
-
path: "/:organizationId/manufacturers/:id",
|
|
47
|
-
pathParams: OrganizationWithIdParams,
|
|
48
|
-
query: GetResourceQuerySchema,
|
|
49
|
-
responses: {
|
|
50
|
-
200: z.union([ManufacturerSchema, LocalizedManufacturerSchema]),
|
|
51
|
-
401: ErrorSchema,
|
|
52
|
-
404: ErrorSchema,
|
|
53
|
-
},
|
|
54
|
-
summary: "Get Manufacturer",
|
|
55
|
-
tags: ["Manufacturer"],
|
|
56
|
-
});
|
|
57
|
-
const updateManufacturerRoute = createApiRoute({
|
|
58
|
-
body: UpdateManufacturerSchema,
|
|
59
|
-
description: "Updates an existing manufacturer",
|
|
60
|
-
headers: HeaderSchema,
|
|
61
|
-
method: "PUT",
|
|
62
|
-
operationId: "updateManufacturer",
|
|
63
|
-
path: "/:organizationId/manufacturers/:id",
|
|
64
|
-
pathParams: OrganizationWithIdParams,
|
|
65
|
-
responses: {
|
|
66
|
-
200: ManufacturerSchema,
|
|
67
|
-
400: ErrorSchema,
|
|
68
|
-
401: ErrorSchema,
|
|
69
|
-
404: ErrorSchema,
|
|
70
|
-
},
|
|
71
|
-
summary: "Update Manufacturer",
|
|
72
|
-
tags: ["Manufacturer"],
|
|
73
|
-
});
|
|
74
|
-
const deleteManufacturerRoute = createApiRoute({
|
|
75
|
-
description: "Soft deletes a manufacturer",
|
|
76
|
-
headers: HeaderSchema,
|
|
77
|
-
method: "DELETE",
|
|
78
|
-
operationId: "deleteManufacturer",
|
|
79
|
-
path: "/:organizationId/manufacturers/:id",
|
|
80
|
-
pathParams: OrganizationWithIdParams,
|
|
81
|
-
responses: {
|
|
82
|
-
204: null,
|
|
83
|
-
400: ErrorSchema,
|
|
84
|
-
401: ErrorSchema,
|
|
85
|
-
404: ErrorSchema,
|
|
86
|
-
},
|
|
87
|
-
summary: "Delete Manufacturer",
|
|
88
|
-
tags: ["Manufacturer"],
|
|
89
|
-
});
|
|
90
|
-
export const manufacturerRoute = {
|
|
91
|
-
getManufacturers: getManufacturersRoute,
|
|
92
|
-
createManufacturer: createManufacturerRoute,
|
|
93
|
-
getManufacturer: getManufacturerRoute,
|
|
94
|
-
updateManufacturer: updateManufacturerRoute,
|
|
95
|
-
deleteManufacturer: deleteManufacturerRoute,
|
|
96
|
-
};
|
|
97
|
-
//# sourceMappingURL=manufacturer.route.js.map
|
|
1
|
+
import{z as a}from"@hono/zod-openapi";import{createApiRoute as r}from"../../core/hono/hono";import{ErrorSchema as e,HeaderSchema as t,OrganizationParams as u,OrganizationWithIdParams as n,PaginationMetaSchema as o,PaginationQuerySchema as s}from"../../schemas";import{GetResourceQuerySchema as c}from"../../schemas/queries.schema";import{CreateManufacturerSchema as i,LocalizedManufacturerSchema as m,ManufacturerSchema as f,UpdateManufacturerSchema as p}from"./manufacturer.schema";const d=r({description:"Fetches a paginated list of manufacturers for a specific organization",headers:t,method:"GET",operationId:"getManufacturers",path:"/:organizationId/manufacturers",pathParams:u,query:s,responses:{200:a.object({list:a.array(a.union([f,m])),meta:o}),400:e,401:e},summary:"Get Manufacturers",tags:["Manufacturer"]}),h=r({body:i,description:"Creates a new manufacturer for a specific organization",headers:t,method:"POST",operationId:"createManufacturer",path:"/:organizationId/manufacturers",pathParams:u,responses:{201:f,400:e,401:e,404:e},summary:"Create Manufacturer",tags:["Manufacturer"]}),M=r({headers:t,method:"GET",operationId:"getManufacturer",path:"/:organizationId/manufacturers/:id",pathParams:n,query:c,responses:{200:a.union([f,m]),401:e,404:e},summary:"Get Manufacturer",tags:["Manufacturer"]}),g=r({body:p,description:"Updates an existing manufacturer",headers:t,method:"PUT",operationId:"updateManufacturer",path:"/:organizationId/manufacturers/:id",pathParams:n,responses:{200:f,400:e,401:e,404:e},summary:"Update Manufacturer",tags:["Manufacturer"]}),y=r({description:"Soft deletes a manufacturer",headers:t,method:"DELETE",operationId:"deleteManufacturer",path:"/:organizationId/manufacturers/:id",pathParams:n,responses:{204:null,400:e,401:e,404:e},summary:"Delete Manufacturer",tags:["Manufacturer"]});export const manufacturerRoute={getManufacturers:d,createManufacturer:h,getManufacturer:M,updateManufacturer:g,deleteManufacturer:y};
|
|
@@ -1,125 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { validateRequiredForDefaultLocale } from "../../core/utils/zod.util";
|
|
3
|
-
import { FileSchema } from "../file/file.schema";
|
|
4
|
-
export const ManufacturerSchema = z
|
|
5
|
-
.object({
|
|
6
|
-
id: z.string().openapi({
|
|
7
|
-
example: "clf9876543210abcdef",
|
|
8
|
-
description: "ID of the manufacturer",
|
|
9
|
-
}),
|
|
10
|
-
name: z.string().openapi({
|
|
11
|
-
example: "Tech Innovators Inc.",
|
|
12
|
-
description: "Name of the manufacturer",
|
|
13
|
-
}),
|
|
14
|
-
logo: FileSchema.nullable()
|
|
15
|
-
.optional()
|
|
16
|
-
.openapi({ description: "Logo of the manufacturer" }),
|
|
17
|
-
createdAt: z.date(),
|
|
18
|
-
translations: z
|
|
19
|
-
.array(z.object({
|
|
20
|
-
locale: z.string().min(1, "Locale is required").openapi({
|
|
21
|
-
example: "en-US",
|
|
22
|
-
description: "Locale code for the translation",
|
|
23
|
-
}),
|
|
24
|
-
about: z
|
|
25
|
-
.string()
|
|
26
|
-
.max(6000, "Maximum character limit is 6000")
|
|
27
|
-
.nullable()
|
|
28
|
-
.optional()
|
|
29
|
-
.openapi({
|
|
30
|
-
example: "Tech Innovators Inc. is a technology company.",
|
|
31
|
-
description: "Description about the manufacturer in the specified locale",
|
|
32
|
-
}),
|
|
33
|
-
}))
|
|
34
|
-
.optional()
|
|
35
|
-
.openapi({
|
|
36
|
-
description: "List of translations for the manufacturer",
|
|
37
|
-
}),
|
|
38
|
-
})
|
|
39
|
-
.openapi("Manufacturer");
|
|
40
|
-
export const LocalizedManufacturerSchema = ManufacturerSchema.omit({
|
|
41
|
-
translations: true,
|
|
42
|
-
})
|
|
43
|
-
.extend({
|
|
44
|
-
about: z.string().nullable().optional().default(""),
|
|
45
|
-
})
|
|
46
|
-
.openapi("LocalizedManufacturer");
|
|
47
|
-
export const CreateManufacturerSchema = z
|
|
48
|
-
.object({
|
|
49
|
-
name: z.string().min(1, "Name is required").openapi({
|
|
50
|
-
example: "Apple Inc.",
|
|
51
|
-
description: "Name of the manufacturer",
|
|
52
|
-
}),
|
|
53
|
-
defaultLocale: z.string().min(1, "Default locale is required").openapi({
|
|
54
|
-
example: "en-US",
|
|
55
|
-
description: "The default locale for the manufacturer",
|
|
56
|
-
}),
|
|
57
|
-
logo: FileSchema.nullable().optional().openapi({
|
|
58
|
-
description: "Logo of the manufacturer",
|
|
59
|
-
}),
|
|
60
|
-
translations: z
|
|
61
|
-
.array(z.object({
|
|
62
|
-
locale: z.string().min(1, "Locale is required").openapi({
|
|
63
|
-
example: "en-US",
|
|
64
|
-
description: "Locale code for the translation",
|
|
65
|
-
}),
|
|
66
|
-
about: z
|
|
67
|
-
.string()
|
|
68
|
-
.max(6000, "Maximum character limit is 6000")
|
|
69
|
-
.nullable()
|
|
70
|
-
.optional()
|
|
71
|
-
.openapi({
|
|
72
|
-
example: "Apple Inc. is a multinational technology company.",
|
|
73
|
-
description: "Description about the manufacturer in the specified locale",
|
|
74
|
-
}),
|
|
75
|
-
}))
|
|
76
|
-
.min(1, "Translations are required")
|
|
77
|
-
.openapi({
|
|
78
|
-
description: "List of translations for the manufacturer",
|
|
79
|
-
}),
|
|
80
|
-
logoId: z.string().optional().openapi({
|
|
81
|
-
example: "clf9876543210abcdef",
|
|
82
|
-
description: "ID reference to the manufacturer's logo file",
|
|
83
|
-
}),
|
|
84
|
-
})
|
|
85
|
-
.superRefine(validateRequiredForDefaultLocale("about"))
|
|
86
|
-
.openapi("CreateManufacturer");
|
|
87
|
-
export const UpdateManufacturerSchema = z
|
|
88
|
-
.object({
|
|
89
|
-
name: z.string().min(1, "Name is required").optional().openapi({
|
|
90
|
-
example: "Apple Inc. Updated",
|
|
91
|
-
description: "Name of the manufacturer",
|
|
92
|
-
}),
|
|
93
|
-
logo: FileSchema.nullable().optional().openapi({
|
|
94
|
-
description: "Logo of the manufacturer",
|
|
95
|
-
}),
|
|
96
|
-
defaultLocale: z.string().min(1, "Default locale is required").openapi({
|
|
97
|
-
description: "The default locale for the manufacturer",
|
|
98
|
-
}),
|
|
99
|
-
logoId: z.string().nullable().optional().openapi({
|
|
100
|
-
example: "clf9876543210abcdef",
|
|
101
|
-
description: "ID reference to the manufacturer's logo file",
|
|
102
|
-
}),
|
|
103
|
-
translations: z
|
|
104
|
-
.array(z.object({
|
|
105
|
-
locale: z.string().min(1, "Locale is required").openapi({
|
|
106
|
-
example: "en-US",
|
|
107
|
-
description: "Locale code for the translation",
|
|
108
|
-
}),
|
|
109
|
-
about: z
|
|
110
|
-
.string()
|
|
111
|
-
.max(6000, "Maximum character limit is 6000")
|
|
112
|
-
.nullable()
|
|
113
|
-
.optional()
|
|
114
|
-
.openapi({
|
|
115
|
-
example: "Apple Inc. is a multinational technology company.",
|
|
116
|
-
description: "Description about the manufacturer in the specified locale",
|
|
117
|
-
}),
|
|
118
|
-
}))
|
|
119
|
-
.optional()
|
|
120
|
-
.openapi({
|
|
121
|
-
description: "List of translations for the manufacturer",
|
|
122
|
-
}),
|
|
123
|
-
})
|
|
124
|
-
.openapi("UpdateManufacturer");
|
|
125
|
-
//# sourceMappingURL=manufacturer.schema.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{validateRequiredForDefaultLocale as a}from"../../core/utils/zod.util";import{FileSchema as o}from"../file/file.schema";export const ManufacturerSchema=e.object({id:e.string().openapi({example:"clf9876543210abcdef",description:"ID of the manufacturer"}),name:e.string().openapi({example:"Tech Innovators Inc.",description:"Name of the manufacturer"}),logo:o.nullable().optional().openapi({description:"Logo of the manufacturer"}),createdAt:e.date(),translations:e.array(e.object({locale:e.string().min(1,"Locale is required").openapi({example:"en-US",description:"Locale code for the translation"}),about:e.string().max(6e3,"Maximum character limit is 6000").nullable().optional().openapi({example:"Tech Innovators Inc. is a technology company.",description:"Description about the manufacturer in the specified locale"})})).optional().openapi({description:"List of translations for the manufacturer"})}).openapi("Manufacturer");export const LocalizedManufacturerSchema=ManufacturerSchema.omit({translations:!0}).extend({about:e.string().nullable().optional().default("")}).openapi("LocalizedManufacturer");export const CreateManufacturerSchema=e.object({name:e.string().min(1,"Name is required").openapi({example:"Apple Inc.",description:"Name of the manufacturer"}),defaultLocale:e.string().min(1,"Default locale is required").openapi({example:"en-US",description:"The default locale for the manufacturer"}),logo:o.nullable().optional().openapi({description:"Logo of the manufacturer"}),translations:e.array(e.object({locale:e.string().min(1,"Locale is required").openapi({example:"en-US",description:"Locale code for the translation"}),about:e.string().max(6e3,"Maximum character limit is 6000").nullable().optional().openapi({example:"Apple Inc. is a multinational technology company.",description:"Description about the manufacturer in the specified locale"})})).min(1,"Translations are required").openapi({description:"List of translations for the manufacturer"}),logoId:e.string().optional().openapi({example:"clf9876543210abcdef",description:"ID reference to the manufacturer's logo file"})}).superRefine(a("about")).openapi("CreateManufacturer");export const UpdateManufacturerSchema=e.object({name:e.string().min(1,"Name is required").optional().openapi({example:"Apple Inc. Updated",description:"Name of the manufacturer"}),logo:o.nullable().optional().openapi({description:"Logo of the manufacturer"}),defaultLocale:e.string().min(1,"Default locale is required").openapi({description:"The default locale for the manufacturer"}),logoId:e.string().nullable().optional().openapi({example:"clf9876543210abcdef",description:"ID reference to the manufacturer's logo file"}),translations:e.array(e.object({locale:e.string().min(1,"Locale is required").openapi({example:"en-US",description:"Locale code for the translation"}),about:e.string().max(6e3,"Maximum character limit is 6000").nullable().optional().openapi({example:"Apple Inc. is a multinational technology company.",description:"Description about the manufacturer in the specified locale"})})).optional().openapi({description:"List of translations for the manufacturer"})}).openapi("UpdateManufacturer");
|
|
@@ -4,14 +4,7 @@ import { CreateManufacturerSchema, UpdateManufacturerSchema } from "../../schema
|
|
|
4
4
|
declare class ManufacturerService {
|
|
5
5
|
private readonly prisma;
|
|
6
6
|
constructor(prisma: PrismaClientType);
|
|
7
|
-
/**
|
|
8
|
-
* Find a manufacturer by ID and organization ID
|
|
9
|
-
* @throws HttpException with 404 status if manufacturer is not found
|
|
10
|
-
*/
|
|
11
7
|
private findManufacturer;
|
|
12
|
-
/**
|
|
13
|
-
* Create a new manufacturer
|
|
14
|
-
*/
|
|
15
8
|
createManufacturer(organizationId: string, userId: string, body: z.infer<typeof CreateManufacturerSchema>): Promise<{
|
|
16
9
|
id: string;
|
|
17
10
|
name: string;
|
|
@@ -28,9 +21,6 @@ declare class ManufacturerService {
|
|
|
28
21
|
about?: string | null | undefined;
|
|
29
22
|
}[] | undefined;
|
|
30
23
|
}>;
|
|
31
|
-
/**
|
|
32
|
-
* Get a manufacturer by ID
|
|
33
|
-
*/
|
|
34
24
|
getManufacturer(organizationId: string, id: string, query: {
|
|
35
25
|
locale?: string | null;
|
|
36
26
|
}): Promise<{
|
|
@@ -61,9 +51,6 @@ declare class ManufacturerService {
|
|
|
61
51
|
filename: string;
|
|
62
52
|
} | null | undefined;
|
|
63
53
|
}>;
|
|
64
|
-
/**
|
|
65
|
-
* Get a paginated list of manufacturers
|
|
66
|
-
*/
|
|
67
54
|
getManufacturers(organizationId: string, query: {
|
|
68
55
|
page?: number;
|
|
69
56
|
limit?: number;
|
|
@@ -119,9 +106,6 @@ declare class ManufacturerService {
|
|
|
119
106
|
} | null | undefined;
|
|
120
107
|
}[];
|
|
121
108
|
}>;
|
|
122
|
-
/**
|
|
123
|
-
* Update a manufacturer
|
|
124
|
-
*/
|
|
125
109
|
updateManufacturer(organizationId: string, id: string, userId: string, body: z.infer<typeof UpdateManufacturerSchema>): Promise<{
|
|
126
110
|
id: string;
|
|
127
111
|
name: string;
|
|
@@ -138,9 +122,6 @@ declare class ManufacturerService {
|
|
|
138
122
|
about?: string | null | undefined;
|
|
139
123
|
}[] | undefined;
|
|
140
124
|
}>;
|
|
141
|
-
/**
|
|
142
|
-
* Delete a manufacturer (soft delete)
|
|
143
|
-
*/
|
|
144
125
|
deleteManufacturer(organizationId: string, id: string, userId: string): Promise<void>;
|
|
145
126
|
}
|
|
146
127
|
export { ManufacturerService };
|
|
@@ -1,190 +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 { LocalizedManufacturerSchema, ManufacturerSchema, PaginationMetaSchema, } from "../../schemas";
|
|
6
|
-
class ManufacturerService {
|
|
7
|
-
constructor(prisma) {
|
|
8
|
-
this.prisma = prisma;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Find a manufacturer by ID and organization ID
|
|
12
|
-
* @throws HttpException with 404 status if manufacturer is not found
|
|
13
|
-
*/
|
|
14
|
-
findManufacturer(id, organizationId, options) {
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const manufacturer = yield this.prisma.manufacturer.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 (!manufacturer) {
|
|
25
|
-
throw new HttpException(404, "Manufacturer not found");
|
|
26
|
-
}
|
|
27
|
-
return manufacturer;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Create a new manufacturer
|
|
32
|
-
*/
|
|
33
|
-
createManufacturer(organizationId, userId, body) {
|
|
34
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
// Create new manufacturer
|
|
36
|
-
const manufacturer = yield this.prisma.manufacturer.create({
|
|
37
|
-
data: {
|
|
38
|
-
name: body.name,
|
|
39
|
-
organizationId,
|
|
40
|
-
createdBy: userId,
|
|
41
|
-
logoId: body.logoId,
|
|
42
|
-
translations: {
|
|
43
|
-
create: body.translations,
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
include: {
|
|
47
|
-
translations: true,
|
|
48
|
-
logo: true,
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
return ManufacturerSchema.parse(manufacturer);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Get a manufacturer by ID
|
|
56
|
-
*/
|
|
57
|
-
getManufacturer(organizationId, id, query) {
|
|
58
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
// Extract locale from query parameter
|
|
60
|
-
const { locale } = query;
|
|
61
|
-
const manufacturer = yield this.findManufacturer(id, organizationId, {
|
|
62
|
-
include: {
|
|
63
|
-
logo: true,
|
|
64
|
-
translations: locale
|
|
65
|
-
? {
|
|
66
|
-
where: { locale },
|
|
67
|
-
}
|
|
68
|
-
: true,
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
if (!locale) {
|
|
72
|
-
return ManufacturerSchema.parse(manufacturer);
|
|
73
|
-
}
|
|
74
|
-
// If locale is provided, flatten the translations data and use LocalizedManufacturerSchema
|
|
75
|
-
return LocalizedManufacturerSchema.parse(flattenTranslationData(manufacturer));
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Get a paginated list of manufacturers
|
|
80
|
-
*/
|
|
81
|
-
getManufacturers(organizationId, query) {
|
|
82
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
const { page = 1, limit = 10, search, locale } = query;
|
|
84
|
-
// Fetch manufacturers with pagination
|
|
85
|
-
const [list, meta] = yield this.prisma.manufacturer
|
|
86
|
-
.paginate({
|
|
87
|
-
orderBy: {
|
|
88
|
-
createdAt: "desc",
|
|
89
|
-
},
|
|
90
|
-
where: Object.assign({ organizationId, deletedAt: null }, (search && {
|
|
91
|
-
name: {
|
|
92
|
-
contains: search,
|
|
93
|
-
mode: "insensitive",
|
|
94
|
-
},
|
|
95
|
-
})),
|
|
96
|
-
include: {
|
|
97
|
-
logo: true,
|
|
98
|
-
translations: locale
|
|
99
|
-
? {
|
|
100
|
-
where: { locale },
|
|
101
|
-
}
|
|
102
|
-
: true,
|
|
103
|
-
},
|
|
104
|
-
})
|
|
105
|
-
.withPages({
|
|
106
|
-
page,
|
|
107
|
-
limit,
|
|
108
|
-
});
|
|
109
|
-
if (!locale) {
|
|
110
|
-
// Return standard response with ManufacturerSchema
|
|
111
|
-
return z
|
|
112
|
-
.object({
|
|
113
|
-
meta: PaginationMetaSchema,
|
|
114
|
-
list: z.array(ManufacturerSchema),
|
|
115
|
-
})
|
|
116
|
-
.parse({
|
|
117
|
-
meta,
|
|
118
|
-
list,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
// Process the list for localization
|
|
122
|
-
const localizedList = list.map((item) => flattenTranslationData(item));
|
|
123
|
-
// Return localized response with LocalizedManufacturerSchema
|
|
124
|
-
return z
|
|
125
|
-
.object({
|
|
126
|
-
meta: PaginationMetaSchema,
|
|
127
|
-
list: z.array(LocalizedManufacturerSchema),
|
|
128
|
-
})
|
|
129
|
-
.parse({
|
|
130
|
-
meta,
|
|
131
|
-
list: localizedList,
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Update a manufacturer
|
|
137
|
-
*/
|
|
138
|
-
updateManufacturer(organizationId, id, userId, body) {
|
|
139
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
-
// Fetch manufacturer by id
|
|
141
|
-
yield this.findManufacturer(id, organizationId);
|
|
142
|
-
// Update manufacturer
|
|
143
|
-
const updatedManufacturer = yield this.prisma.manufacturer.update({
|
|
144
|
-
where: {
|
|
145
|
-
id,
|
|
146
|
-
organizationId,
|
|
147
|
-
deletedAt: null,
|
|
148
|
-
},
|
|
149
|
-
data: {
|
|
150
|
-
updatedBy: userId,
|
|
151
|
-
name: body.name,
|
|
152
|
-
translations: {
|
|
153
|
-
deleteMany: {},
|
|
154
|
-
create: body.translations || [],
|
|
155
|
-
},
|
|
156
|
-
logoId: body.logoId,
|
|
157
|
-
},
|
|
158
|
-
include: {
|
|
159
|
-
logo: true,
|
|
160
|
-
translations: true,
|
|
161
|
-
},
|
|
162
|
-
});
|
|
163
|
-
return ManufacturerSchema.parse(updatedManufacturer);
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Delete a manufacturer (soft delete)
|
|
168
|
-
*/
|
|
169
|
-
deleteManufacturer(organizationId, id, userId) {
|
|
170
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
-
// Fetch manufacturer by id
|
|
172
|
-
yield this.findManufacturer(id, organizationId);
|
|
173
|
-
// Soft delete manufacturer
|
|
174
|
-
yield this.prisma.manufacturer.update({
|
|
175
|
-
where: {
|
|
176
|
-
id,
|
|
177
|
-
organizationId,
|
|
178
|
-
deletedAt: null,
|
|
179
|
-
},
|
|
180
|
-
data: {
|
|
181
|
-
deletedAt: new Date(),
|
|
182
|
-
deletedBy: userId,
|
|
183
|
-
},
|
|
184
|
-
});
|
|
185
|
-
return;
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
export { ManufacturerService };
|
|
190
|
-
//# sourceMappingURL=manufacturer.service.js.map
|
|
1
|
+
import{__awaiter as e}from"tslib";import{z as t}from"@hono/zod-openapi";import{HttpException as a}from"../../core/exceptions/http-exception";import{flattenTranslationData as r}from"../../core/utils/zod.util";import{LocalizedManufacturerSchema as i,ManufacturerSchema as n,PaginationMetaSchema as o}from"../../schemas";class d{constructor(e){this.prisma=e}findManufacturer(t,r,i){return e(this,void 0,void 0,function*(){const e=yield this.prisma.manufacturer.findUnique({where:{id:t,organizationId:r,deletedAt:null},include:null==i?void 0:i.include});if(!e)throw new a(404,"Manufacturer not found");return e})}createManufacturer(t,a,r){return e(this,void 0,void 0,function*(){const e=yield this.prisma.manufacturer.create({data:{name:r.name,organizationId:t,createdBy:a,logoId:r.logoId,translations:{create:r.translations}},include:{translations:!0,logo:!0}});return n.parse(e)})}getManufacturer(t,a,o){return e(this,void 0,void 0,function*(){const{locale:e}=o,d=yield this.findManufacturer(a,t,{include:{logo:!0,translations:!e||{where:{locale:e}}}});return e?i.parse(r(d)):n.parse(d)})}getManufacturers(a,d){return e(this,void 0,void 0,function*(){const{page:e=1,limit:s=10,search:u,locale:l}=d,[c,m]=yield this.prisma.manufacturer.paginate({orderBy:{createdAt:"desc"},where:Object.assign({organizationId:a,deletedAt:null},u&&{name:{contains:u,mode:"insensitive"}}),include:{logo:!0,translations:!l||{where:{locale:l}}}}).withPages({page:e,limit:s});if(!l)return t.object({meta:o,list:t.array(n)}).parse({meta:m,list:c});const f=c.map(e=>r(e));return t.object({meta:o,list:t.array(i)}).parse({meta:m,list:f})})}updateManufacturer(t,a,r,i){return e(this,void 0,void 0,function*(){yield this.findManufacturer(a,t);const e=yield this.prisma.manufacturer.update({where:{id:a,organizationId:t,deletedAt:null},data:{updatedBy:r,name:i.name,translations:{deleteMany:{},create:i.translations||[]},logoId:i.logoId},include:{logo:!0,translations:!0}});return n.parse(e)})}deleteManufacturer(t,a,r){return e(this,void 0,void 0,function*(){yield this.findManufacturer(a,t),yield this.prisma.manufacturer.update({where:{id:a,organizationId:t,deletedAt:null},data:{deletedAt:new Date,deletedBy:r}})})}}export{d as ManufacturerService};
|