@shophost/rest-api 2.0.67 → 2.0.69
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 +1 -1
- package/schema.prisma +1 -0
- package/scripts/shophost-rest-api.mjs +198 -1
- package/src/bootstrap.js +1 -1
- package/src/container.js +1 -1
- package/src/core/auth/auth.schema.js +1 -1
- package/src/core/auth/auth.util.js +1 -1
- package/src/core/auth/better-auth.lib.js +1 -1
- package/src/core/auth/generate-password-hash.util.js +1 -1
- package/src/core/auth/headers.schema.js +1 -1
- package/src/core/auth/user.schema.js +1 -1
- package/src/core/db/__generated__/client/browser.js +1 -1
- package/src/core/db/__generated__/client/client.js +1 -1
- package/src/core/db/__generated__/client/enums.js +1 -1
- package/src/core/db/__generated__/client/internal/class.js +789 -1
- package/src/core/db/__generated__/client/internal/prismaNamespace.d.ts +1 -0
- package/src/core/db/__generated__/client/internal/prismaNamespace.js +1 -1
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.d.ts +1 -0
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js +1 -1
- package/src/core/db/__generated__/client/models/OrganizationConfiguration.d.ts +41 -1
- package/src/core/db/index.js +1 -1
- package/src/core/email/components.js +1 -1
- package/src/core/exceptions/http-exception.js +1 -1
- package/src/core/hono/hono.js +1 -1
- package/src/core/lib/prisma.js +1 -1
- package/src/core/logging/pino.js +1 -1
- package/src/core/notifications/email.service.js +1 -1
- package/src/core/openapi/openapi.lib.js +1 -1
- package/src/core/utils/currency.util.js +1 -1
- package/src/core/utils/env.util.js +1 -1
- package/src/core/utils/object.util.js +1 -1
- package/src/core/utils/translations.util.js +1 -1
- package/src/core/utils/zod.util.js +1 -1
- package/src/db.js +1 -1
- package/src/features/access/access.handler.js +1 -1
- package/src/features/access/access.route.js +1 -1
- package/src/features/access/access.schema.js +1 -1
- package/src/features/access/access.service.js +1 -1
- package/src/features/analytics/analytics.handler.js +1 -1
- package/src/features/analytics/analytics.route.js +1 -1
- package/src/features/analytics/analytics.schema.js +1 -1
- package/src/features/analytics/analytics.service.js +1 -1
- package/src/features/cart/cart.handler.js +1 -1
- package/src/features/cart/cart.route.js +1 -1
- package/src/features/cart/cart.schema.js +1 -1
- package/src/features/cart/cart.service.js +1 -1
- package/src/features/cart/cart.util.js +1 -1
- package/src/features/customer/customer.handler.js +1 -1
- package/src/features/customer/customer.route.js +1 -1
- package/src/features/customer/customer.schema.js +1 -1
- package/src/features/customer/customer.service.js +1 -1
- package/src/features/file/file.handler.js +1 -1
- package/src/features/file/file.route.js +1 -1
- package/src/features/file/file.schema.js +1 -1
- package/src/features/file/file.service.js +1 -1
- package/src/features/health/health.handler.js +1 -1
- package/src/features/health/health.route.js +1 -1
- package/src/features/index.js +1 -1
- package/src/features/integration/integration-config.js +1 -1
- package/src/features/integration/integration-registry.js +1 -1
- package/src/features/integration/integration.handler.js +1 -1
- package/src/features/integration/integration.route.js +1 -1
- package/src/features/integration/integration.schema.js +1 -1
- package/src/features/integration/integration.service.js +1 -1
- package/src/features/inventory/inventory.service.js +1 -1
- package/src/features/location/location.handler.js +1 -1
- package/src/features/location/location.route.js +1 -1
- package/src/features/location/location.schema.js +1 -1
- package/src/features/location/location.service.js +1 -1
- package/src/features/manufacturer/manufacturer.handler.js +1 -1
- package/src/features/manufacturer/manufacturer.route.js +1 -1
- package/src/features/manufacturer/manufacturer.schema.js +1 -1
- package/src/features/manufacturer/manufacturer.service.js +1 -1
- package/src/features/order/emails/order-confirmation.email.js +1 -1
- package/src/features/order/emails/order-notification.email.js +1 -1
- package/src/features/order/fulfilment.schema.js +1 -1
- package/src/features/order/order-fulfillment.service.js +1 -1
- package/src/features/order/order.handler.js +1 -1
- package/src/features/order/order.route.js +1 -1
- package/src/features/order/order.schema.js +1 -1
- package/src/features/order/order.service.js +1 -1
- package/src/features/order/recipient.schema.js +1 -1
- package/src/features/organization/legal-entity.schema.js +1 -1
- package/src/features/organization/organization-configuration.schema.d.ts +2 -0
- package/src/features/organization/organization-configuration.schema.js +1 -1
- package/src/features/organization/organization.handler.js +1 -1
- package/src/features/organization/organization.route.d.ts +5 -0
- package/src/features/organization/organization.route.js +1 -1
- package/src/features/organization/organization.schema.d.ts +2 -0
- package/src/features/organization/organization.schema.js +1 -1
- package/src/features/organization/organization.service.d.ts +4 -0
- package/src/features/organization/organization.service.js +1 -1
- package/src/features/payment/payment-webhook.service.js +1 -1
- package/src/features/payment/payment.handler.js +1 -1
- package/src/features/payment/payment.route.js +1 -1
- package/src/features/payment/payment.schema.js +1 -1
- package/src/features/payment/payment.service.js +1 -1
- package/src/features/payment/stripe.service.js +1 -1
- package/src/features/product/product-modifier.schema.js +1 -1
- package/src/features/product/product.handler.js +1 -1
- package/src/features/product/product.route.js +1 -1
- package/src/features/product/product.schema.js +1 -1
- package/src/features/product/product.service.js +1 -1
- package/src/features/product-category/product-category.handler.js +1 -1
- package/src/features/product-category/product-category.route.js +1 -1
- package/src/features/product-category/product-category.schema.js +1 -1
- package/src/features/product-category/product-category.service.js +1 -1
- package/src/features/reservation/emails/reservation-cancellation.email.js +1 -1
- package/src/features/reservation/emails/reservation-confirmation.email.js +1 -1
- package/src/features/reservation/emails/reservation-email-date.d.ts +2 -0
- package/src/features/reservation/emails/reservation-email-date.js +1 -0
- package/src/features/reservation/emails/reservation-notification.email.js +1 -1
- package/src/features/reservation/emails/reservation-updated.email.js +1 -1
- package/src/features/reservation/reservation.handler.js +1 -1
- package/src/features/reservation/reservation.route.js +1 -1
- package/src/features/reservation/reservation.schema.js +1 -1
- package/src/features/reservation/reservation.service.js +1 -1
- package/src/features/shipping/shipping.handler.js +1 -1
- package/src/features/shipping/shipping.route.js +1 -1
- package/src/features/shipping/shipping.service.js +1 -1
- package/src/features/shipping-method/shipping-method.handler.js +1 -1
- package/src/features/shipping-method/shipping-method.route.js +1 -1
- package/src/features/shipping-method/shipping-method.schema.js +1 -1
- package/src/features/shipping-method/shipping-method.service.js +1 -1
- package/src/features/shipping-method/shipping-zone.schema.js +1 -1
- package/src/features/webhook/webhook.handler.js +1 -1
- package/src/features/webhook/webhook.route.js +1 -1
- package/src/index.js +1 -1
- package/src/integrations/next.js +1 -1
- package/src/schemas/address.schema.js +1 -1
- package/src/schemas/currency.schema.js +1 -1
- package/src/schemas/error.schema.js +1 -1
- package/src/schemas/index.d.ts +1 -0
- package/src/schemas/index.js +1 -1
- package/src/schemas/locales.schema.js +1 -1
- package/src/schemas/number.schema.js +1 -1
- package/src/schemas/pagination.schema.js +1 -1
- package/src/schemas/params.schema.js +1 -1
- package/src/schemas/queries.schema.js +1 -1
- package/src/schemas/time-zone.schema.d.ts +9 -0
- package/src/schemas/time-zone.schema.js +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{__awaiter as c}from"tslib";import{HttpException as s}from"../../core/exceptions/http-exception";class p{constructor(e,t,r){this.prisma=e,this.stripeService=t,this.orderFulfillmentService=r}processWebhookEvent(e,t,r,d){return c(this,void 0,void 0,function*(){if(!t)throw new s(401,"Signature is required");if(e==="stripe"){const n=yield this.stripeService.constructWebhookEvent(d,t,r);return n.type==="checkout.session.completed"?this.handleStripeCheckoutCompleted(n.data.object,d):void 0}else throw new s(400,"Payment provider not supported")})}handleStripeCheckoutCompleted(e,t){return c(this,void 0,void 0,function*(){var r,d,n,u,a;if(((r=e.metadata)===null||r===void 0?void 0:r.testIntegration)==="true")return;const i=yield this.prisma.paymentSession.findFirst({where:Object.assign({referenceId:e.id},t?{payment:{order:{organizationId:t}}}:{}),include:{payment:{include:{order:!0}}}});if(!i)throw new s(404,"Payment session not found");const o=(d=i.payment)===null||d===void 0?void 0:d.order;if(!o)throw new s(404,"Order not found");i.capturedAt&&(o.inventoryDeductedAt||o.inventoryConflictAt)||((!i.capturedAt||i.payment.status!=="succeeded")&&(yield this.prisma.paymentSession.update({where:{id:i.id},data:{capturedAt:(n=i.capturedAt)!==null&&n!==void 0?n:new Date,payment:{update:{status:"succeeded"}}}})),yield this.orderFulfillmentService.fulfillPaidOrder(o.id,(a=(u=e.metadata)===null||u===void 0?void 0:u.userId)!==null&&a!==void 0?a:o.userId))})}}export{p as PaymentWebhookService};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{__awaiter as i}from"tslib";import{createApiRouter as m}from"../../core/hono/hono";import{paymentRoute as p}from"./payment.route";export const registerPaymentHandlers=o=>{const e=m();return e.openapi(p.getAvailablePaymentMethods,t=>i(void 0,void 0,void 0,function*(){const r=t.get("auth"),a=t.req.valid("param");yield r.getCurrentUser();const n=yield o.getPaymentMethods(a.organizationId);return t.json(n,200)})),e};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{createApiRoute as a}from"../../core/hono/hono";import{ErrorSchema as e,HeaderSchema as t,OrganizationParams as o}from"../../schemas";import{PaymentMethodDetailsSchema as r}from"./payment.schema";const m=a({description:"Returns a list of available payment methods for the organization.",headers:t,method:"GET",operationId:"getAvailablePaymentMethods",path:"/:organizationId/payment/methods",pathParams:o,responses:{200:r.array(),400:e,401:e},summary:"Get Available Payment Methods",tags:["Payment"]});export const paymentRoute={getAvailablePaymentMethods:m};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{currency as n}from"../../schemas/currency.schema";export const PaymentMethodSchema=e.enum(["card","blik","cash_on_delivery","paypal"]).openapi({description:"The payment method",example:"card"}),PaymentProviderSchema=e.enum(["stripe","revolut","payu","not_applicable"]).openapi({description:"The payment method",example:"card"}),PaymentStatusSchema=e.enum(["pending","succeeded","refunded","failed","canceled"]).openapi({description:"The payment status",example:"pending"}),PaymentMethodDetailsSchema=e.object({id:e.string().min(1),provider:PaymentProviderSchema,method:PaymentMethodSchema,description:e.string().min(1)}).openapi({description:"The payment method",example:{provider:"stripe",type:"card"}}),PaymentSchema=e.object({id:e.string().cuid().min(1),method:PaymentMethodSchema,provider:PaymentProviderSchema,status:PaymentStatusSchema,shipping:e.number().min(0).default(0),subtotal:e.number().min(0),total:e.number().min(0),discount:e.preprocess(t=>t??0,e.number().min(0).default(0)),currency:n});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{__awaiter as o}from"tslib";import{HttpException as n}from"../../core/exceptions/http-exception";class d{constructor(i,t,e){this.prisma=i,this.options=t,this.stripeService=e}getPaymentMethods(i){return o(this,void 0,void 0,function*(){const t=[],e=yield this.stripeService.getPaymentMethods(i);return e.includes("card")&&t.push({id:"stripe:card",provider:"stripe",description:"Visa, Mastercard, American Express etc..",method:"card"}),e.includes("blik")&&t.push({id:"stripe:blik",provider:"stripe",description:"Popular payment method in Poland",method:"blik"}),this.options.revolut&&this.options.revolut.paymentMethods.includes("card")&&t.push({id:"revolut:card",provider:"revolut",description:"Visa, Mastercard, American Express etc..",method:"card"}),this.options.revolut&&this.options.revolut.paymentMethods.includes("blik")&&t.push({id:"revolut:blik",provider:"revolut",description:"Popular payment method in Poland",method:"blik"}),t})}handleCheckoutSessionByProvider(i,t,e,s){return o(this,void 0,void 0,function*(){if(e.payment.provider==="stripe")return this.stripeService.createCheckoutSession(i,t,e,s);throw new n(400,"Payment provider not supported")})}createCheckoutSession(i,t,e,s){return o(this,void 0,void 0,function*(){const r=yield this.handleCheckoutSessionByProvider(i,t,e,s);return yield this.prisma.paymentSession.create({data:{payment:{connect:{id:e.payment.id}},referenceId:r.id,amount:e.payment.total,currency:e.payment.currency,rawData:JSON.stringify(r)}}),{sessionId:r.id,redirectUrl:r.url}})}}export{d as PaymentService};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const _0x3cc5d1=_0x1d74,_0xd22ff5=_0x1d74;(function(_0x1e71b3,_0x18503a){const _0xc17390=_0x1d74,_0x732115=_0x1d74,_0x369692=_0x1e71b3();while(!![]){try{const _0x25f1fd=-parseInt(_0xc17390(0x1b5))/0x1*(parseInt(_0xc17390(0x1ba))/0x2)+parseInt(_0x732115(0x1ab))/0x3*(-parseInt(_0x732115(0x1f1))/0x4)+-parseInt(_0xc17390(0x200))/0x5*(parseInt(_0x732115(0x1bc))/0x6)+-parseInt(_0xc17390(0x1be))/0x7+parseInt(_0xc17390(0x1f7))/0x8*(-parseInt(_0xc17390(0x1f5))/0x9)+parseInt(_0xc17390(0x1da))/0xa*(-parseInt(_0xc17390(0x1b0))/0xb)+-parseInt(_0xc17390(0x1e7))/0xc*(-parseInt(_0x732115(0x1f4))/0xd);if(_0x25f1fd===_0x18503a)break;else _0x369692['push'](_0x369692['shift']());}catch(_0x65b7a6){_0x369692['push'](_0x369692['shift']());}}}(_0x3b64,0x413d7));import{__awaiter as _0x5556f5}from'tslib';import _0x26a8c1 from'stripe';import{HttpException as _0x380098}from'../../core/exceptions/http-exception';import{getStoredStripeConfig as _0x270561}from'../integration/integration-config';function _0x1d74(_0xbbadfc,_0x26ba4a){_0xbbadfc=_0xbbadfc-0x193;const _0x3b647e=_0x3b64();let _0x1d7449=_0x3b647e[_0xbbadfc];if(_0x1d74['MJbFqq']===undefined){var _0x3bfc8f=function(_0x2971fd){const _0x341c67='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x1afd1c='',_0x4e903b='';for(let _0x249de4=0x0,_0x3fe749,_0x34c749,_0x4182ea=0x0;_0x34c749=_0x2971fd['charAt'](_0x4182ea++);~_0x34c749&&(_0x3fe749=_0x249de4%0x4?_0x3fe749*0x40+_0x34c749:_0x34c749,_0x249de4++%0x4)?_0x1afd1c+=String['fromCharCode'](0xff&_0x3fe749>>(-0x2*_0x249de4&0x6)):0x0){_0x34c749=_0x341c67['indexOf'](_0x34c749);}for(let _0xf32bc4=0x0,_0xcfc0d5=_0x1afd1c['length'];_0xf32bc4<_0xcfc0d5;_0xf32bc4++){_0x4e903b+='%'+('00'+_0x1afd1c['charCodeAt'](_0xf32bc4)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x4e903b);};_0x1d74['vGjreH']=_0x3bfc8f,_0x1d74['dXjYTk']={},_0x1d74['MJbFqq']=!![];}const _0x90a417=_0x3b647e[0x0],_0x2e1114=_0xbbadfc+_0x90a417,_0x1ac235=_0x1d74['dXjYTk'][_0x2e1114];return!_0x1ac235?(_0x1d7449=_0x1d74['vGjreH'](_0x1d7449),_0x1d74['dXjYTk'][_0x2e1114]=_0x1d7449):_0x1d7449=_0x1ac235,_0x1d7449;}class k{constructor(_0x1f979a){const _0x2cb2bc=_0x1d74,_0x4e24e2=_0x1d74;this[_0x2cb2bc(0x211)+_0x2cb2bc(0x1b7)+_0x2cb2bc(0x216)]=_0x1f979a,this['runtimes']=new Map();}[_0x3cc5d1(0x1fa)+_0x3cc5d1(0x1dc)+_0x3cc5d1(0x1f0)](_0x344fa8){const _0x37013e=_0xd22ff5,_0x487830=_0xd22ff5;return _0x344fa8?_0x37013e(0x207)+'ntegrati'+_0x37013e(0x1ac)+_0x487830(0x19d)+_0x37013e(0x1fb)+_0x37013e(0x1bd)+_0x37013e(0x208)+'on':_0x487830(0x207)+_0x487830(0x1ce)+_0x37013e(0x1ac)+_0x487830(0x19d)+'ured';}[_0x3cc5d1(0x1d9)+_0xd22ff5(0x1a1)](_0x4e8539){const _0x406abb=_0xd22ff5,_0x1443a6={'NVAxC':function(_0x2d1baf,_0x36033){return _0x2d1baf===_0x36033;},'UHMsl':function(_0x1d61f3,_0x186cc6,_0x567713,_0x1507f9,_0x43eb28){return _0x1d61f3(_0x186cc6,_0x567713,_0x1507f9,_0x43eb28);}};return _0x1443a6[_0x406abb(0x1c9)](_0x5556f5,this,void 0x0,void 0x0,function*(){const _0x3d8fa4=_0x406abb,_0x173d38=_0x406abb;var _0x16b9af;if(!_0x4e8539)return;const _0x2e1f4b=_0x270561(this[_0x3d8fa4(0x211)+_0x173d38(0x1b7)+_0x3d8fa4(0x216)][_0x3d8fa4(0x1c1)](_0x4e8539,'stripe')),_0x112b2f=_0x2e1f4b?.[_0x173d38(0x1d8)+'y'];if(!_0x112b2f){this[_0x3d8fa4(0x1ef)][_0x3d8fa4(0x1d5)](_0x4e8539);return;}const _0x2389a4=JSON[_0x173d38(0x1aa)+'y'](_0x2e1f4b??null),_0x52e7ba=this[_0x173d38(0x1ef)][_0x3d8fa4(0x1c1)](_0x4e8539);if(_0x1443a6['NVAxC'](_0x52e7ba?.[_0x173d38(0x1bb)+'e'],_0x2389a4))return _0x52e7ba;const _0x2742fe={'webhookSecret':_0x2e1f4b?.['webhookS'+_0x3d8fa4(0x1d0)],'paymentMethods':(_0x16b9af=_0x2e1f4b?.['paymentM'+_0x3d8fa4(0x1bf)])!==null&&_0x16b9af!==void 0x0?_0x16b9af:[],'signature':_0x2389a4,'stripe':new _0x26a8c1(_0x112b2f)};return this[_0x3d8fa4(0x1ef)][_0x173d38(0x1d1)](_0x4e8539,_0x2742fe),_0x2742fe;});}[_0x3cc5d1(0x1ca)+_0xd22ff5(0x1dd)](_0x23a7c1){return _0x5556f5(this,void 0x0,void 0x0,function*(){const _0x27b99b=_0x1d74,_0x24d4c7=_0x1d74,_0x363947=yield this[_0x27b99b(0x1d9)+_0x27b99b(0x1a1)](_0x23a7c1);if(!_0x363947)throw new _0x380098(0x190,this[_0x27b99b(0x1fa)+_0x24d4c7(0x1dc)+_0x27b99b(0x1f0)](_0x23a7c1));return _0x363947;});}[_0xd22ff5(0x1b2)+'stPaymen'+_0xd22ff5(0x1f9)](_0x498ea2){const _0x7a3824=_0x3cc5d1,_0xcb888d=_0x3cc5d1,_0x5f5496={'GoCHE':_0x7a3824(0x1c8)};if(_0x498ea2[_0x7a3824(0x1e2)](_0x5f5496[_0x7a3824(0x1a9)]))return _0xcb888d(0x1c8);if(_0x498ea2[_0xcb888d(0x1e2)](_0x7a3824(0x1b3)))return _0x7a3824(0x1b3);}[_0x3cc5d1(0x218)+_0xd22ff5(0x1e4)+'lation'](_0x2aa0a1,_0x30a531,_0x10b834){const _0x4addd3=_0xd22ff5,_0x367b05=_0xd22ff5;var _0x2b54a0;const _0x851289=[...this[_0x4addd3(0x1a5)+_0x367b05(0x1de)+'es'](_0x30a531),...this[_0x367b05(0x1a5)+_0x367b05(0x1de)+'es'](_0x10b834)];for(const _0x191f2f of _0x851289){const _0x590e91=_0x2aa0a1[_0x4addd3(0x219)](_0x3d1f3f=>_0x3d1f3f[_0x4addd3(0x1f8)]===_0x191f2f);if(_0x590e91)return _0x590e91;}return(_0x2b54a0=_0x2aa0a1[_0x4addd3(0x219)](_0x3d9e4b=>_0x3d9e4b[_0x4addd3(0x1ff)][_0x367b05(0x199)]()['length']>0x0))!==null&&_0x2b54a0!==void 0x0?_0x2b54a0:_0x2aa0a1[0x0];}[_0x3cc5d1(0x1a5)+_0x3cc5d1(0x1de)+'es'](_0x1554ed){const _0x44f235=_0xd22ff5,_0x3fc7cd=_0xd22ff5,[_0xe54188]=_0x1554ed[_0x44f235(0x1ee)]('_'),_0x14dac2=[_0x1554ed];return _0xe54188&&_0xe54188!==_0x1554ed&&_0x14dac2[_0x3fc7cd(0x204)](_0xe54188),_0x14dac2;}[_0xd22ff5(0x1d6)+_0x3cc5d1(0x1f2)+'s'](_0x36c635){const _0x4e3487={'VfWBt':function(_0x6a3f4c,_0x3ff7dc){return _0x6a3f4c!==_0x3ff7dc;}};return _0x5556f5(this,void 0x0,void 0x0,function*(){const _0x53103d=_0x1d74,_0x29fa39=_0x1d74;var _0xfd7af,_0x3221d4;return _0x4e3487[_0x53103d(0x1f3)](_0x3221d4=(_0xfd7af=yield this[_0x29fa39(0x1d9)+_0x53103d(0x1a1)](_0x36c635))===null||_0xfd7af===void 0x0?void 0x0:_0xfd7af['paymentM'+_0x29fa39(0x1bf)],null)&&_0x3221d4!==void 0x0?_0x3221d4:[];});}[_0xd22ff5(0x205)+'tWebhook'+_0xd22ff5(0x1a3)](_0x89fe74,_0x1dd643,_0x1d0b5f){const _0x25d317=_0x3cc5d1,_0x53e1b4=_0x3cc5d1,_0xecc24d={'eEnzJ':'Stripe\x20w'+_0x25d317(0x1b9)+'ecret\x20is'+_0x53e1b4(0x20f)+_0x53e1b4(0x214)};return _0x5556f5(this,void 0x0,void 0x0,function*(){const _0x2bfc79=_0x25d317,_0x301195=_0x25d317,_0x2e3fed=yield this[_0x2bfc79(0x1ca)+_0x301195(0x1dd)](_0x89fe74);if(!_0x2e3fed[_0x2bfc79(0x195)+'ecret'])throw new _0x380098(0x190,_0xecc24d[_0x2bfc79(0x19b)]);return _0x2e3fed[_0x2bfc79(0x1cf)]['webhooks'][_0x2bfc79(0x205)+_0x301195(0x1cb)](_0x1d0b5f,_0x1dd643,_0x2e3fed[_0x2bfc79(0x195)+_0x301195(0x1d0)]);});}['createCh'+_0xd22ff5(0x1c6)+_0xd22ff5(0x1d4)](_0x961d31,_0x581b5e,_0x372be9,_0x470c0b){const _0x320491=_0xd22ff5,_0x42575f=_0xd22ff5,_0x387bed={'CpPQd':_0x320491(0x1c8),'RXKay':_0x320491(0x1b3)};return _0x5556f5(this,arguments,void 0x0,function*(_0x40676f,_0x3cbb95,_0x32441a,{locale:_0x118a3c,defaultLocale:_0x2bb079,successUrl:_0x4dc69a,cancelUrl:_0x45082d}){const _0x17829e=_0x42575f,_0x231d36=_0x42575f,_0x5c57b2={'XPKnf':_0x17829e(0x1eb)};var _0x362464;const _0x4fa98b=yield this[_0x17829e(0x1ca)+_0x231d36(0x1dd)](_0x40676f);if(_0x32441a[_0x231d36(0x1a2)][_0x231d36(0x1df)]!==_0x387bed['CpPQd']&&_0x32441a['payment'][_0x17829e(0x1df)]!==_0x387bed[_0x231d36(0x1e3)])throw new _0x380098(0x190,_0x231d36(0x20b)+_0x231d36(0x1d7)+_0x17829e(0x1e0)+_0x17829e(0x1c3));if(!_0x4fa98b[_0x17829e(0x217)+_0x231d36(0x1bf)][_0x17829e(0x1e2)](_0x32441a[_0x17829e(0x1a2)]['method']))throw new _0x380098(0x190,_0x231d36(0x194)+_0x17829e(0x215)+_0x231d36(0x1cd)+_0x32441a[_0x17829e(0x1a2)][_0x231d36(0x1df)]+('\x20is\x20not\x20'+_0x17829e(0x1ea)));const _0x4914c7={'payment_method_types':[_0x32441a[_0x17829e(0x1a2)][_0x231d36(0x1df)]],'customer_email':_0x3cbb95['email'],'line_items':_0x32441a[_0x231d36(0x20a)][_0x17829e(0x1e6)](({translations:_0x446ee3,unitPrice:_0x3071d6,quantity:_0x30a9eb,image:_0x5a7b92})=>{const _0x1d543b=_0x231d36,_0x354bdb=_0x231d36,_0x4136cd=this[_0x1d543b(0x218)+'temTrans'+_0x354bdb(0x19f)](_0x446ee3,_0x118a3c,_0x2bb079);return{'quantity':_0x30a9eb,'price_data':{'currency':_0x5c57b2['XPKnf'],'product_data':{'name':_0x4136cd?.[_0x1d543b(0x1ff)]||_0x354bdb(0x1c7),'description':_0x4136cd?.[_0x354bdb(0x210)]||void 0x0,'images':_0x5a7b92?.[_0x354bdb(0x1a8)]?[_0x5a7b92?.[_0x354bdb(0x1a8)]]:void 0x0},'unit_amount':_0x3071d6*0x64}};}),'shipping_options':!((_0x362464=_0x32441a[_0x17829e(0x202)+_0x17829e(0x1b4)])===null||_0x362464===void 0x0)&&_0x362464[_0x231d36(0x202)+_0x231d36(0x1c0)][0x0][_0x231d36(0x198)]?[{'shipping_rate_data':{'type':_0x17829e(0x1d3)+_0x17829e(0x1c4),'fixed_amount':{'amount':_0x32441a[_0x231d36(0x1a2)][_0x231d36(0x202)]*0x64,'currency':_0x32441a[_0x231d36(0x1fd)][_0x17829e(0x20e)+_0x231d36(0x1d2)]()},'display_name':'Delivery'+_0x17829e(0x19a)}}]:void 0x0,'mode':_0x231d36(0x1a2),'success_url':_0x4dc69a,'cancel_url':_0x45082d,'metadata':{'userId':_0x3cbb95['id'],'orderId':_0x32441a['id']}};return _0x4fa98b[_0x17829e(0x1cf)][_0x231d36(0x1a4)][_0x231d36(0x196)][_0x231d36(0x1a7)](_0x4914c7);});}[_0xd22ff5(0x1c5)+_0xd22ff5(0x203)+_0x3cc5d1(0x19e)+'n'](_0x1b0233,_0x4bef74){const _0x5f1f5d=_0xd22ff5,_0x4b8ac1=_0xd22ff5,_0x125ab8={'WmoLr':'Shophost'+_0x5f1f5d(0x1fc)+_0x5f1f5d(0x1cc)};return _0x5556f5(this,arguments,void 0x0,function*(_0x525685,{cancelUrl:_0xbcad4a,customerEmail:_0x3e9b8c,defaultCurrency:_0x1004f4,organizationName:_0x362d28,successUrl:_0x8e0849}){const _0x1d8993=_0x5f1f5d,_0x17ca12=_0x5f1f5d,_0x1960b0=yield this[_0x1d8993(0x1ca)+_0x17ca12(0x1dd)](_0x525685);if(!_0x1960b0[_0x17ca12(0x195)+_0x1d8993(0x1d0)])throw new _0x380098(0x190,_0x1d8993(0x20c)+'ebhook\x20s'+_0x1d8993(0x1a6)+_0x1d8993(0x20f)+_0x1d8993(0x214));const _0x5918ff=this[_0x17ca12(0x1b2)+_0x1d8993(0x197)+_0x17ca12(0x1f9)](_0x1960b0[_0x1d8993(0x217)+_0x17ca12(0x1bf)]);if(!_0x5918ff)throw new _0x380098(0x190,_0x1d8993(0x212)+_0x17ca12(0x1ad)+_0x17ca12(0x1e5)+_0x1d8993(0x193)+_0x17ca12(0x201)+_0x1d8993(0x1af)+_0x17ca12(0x1ec)+'.');const _0x5c6eff=_0x5918ff===_0x17ca12(0x1b3)?'pln':_0x1004f4[_0x1d8993(0x20e)+'ase']();return _0x1960b0[_0x17ca12(0x1cf)][_0x1d8993(0x1a4)][_0x1d8993(0x196)][_0x1d8993(0x1a7)]({'payment_method_types':[_0x5918ff],'customer_email':_0x3e9b8c,'line_items':[{'quantity':0x1,'price_data':{'currency':_0x5c6eff,'product_data':{'name':_0x362d28+(_0x17ca12(0x213)+_0x1d8993(0x1b1)),'description':_0x1d8993(0x1c2)+_0x17ca12(0x1db)+_0x1d8993(0x1ed)+_0x1d8993(0x20d)+_0x1d8993(0x1e9)+_0x17ca12(0x1e8)+_0x17ca12(0x209)+_0x17ca12(0x1ae)+'.'},'unit_amount':0x7cf}},{'quantity':0x1,'price_data':{'currency':_0x5c6eff,'product_data':{'name':_0x125ab8[_0x1d8993(0x1b6)],'description':_0x1d8993(0x1b8)+_0x17ca12(0x19c)+_0x1d8993(0x1a0)+_0x17ca12(0x1f6)+'or\x20Strip'+_0x17ca12(0x1e1)+_0x1d8993(0x206)+_0x1d8993(0x1fe)},'unit_amount':0x1f3}}],'mode':_0x17ca12(0x1a2),'success_url':_0x8e0849,'cancel_url':_0xbcad4a,'metadata':{'testIntegration':'true'}});});}}function _0x3b64(){const _0x796d4=['u3rYAxbLihC','CgHVC3qGDg8','Dg9mB3DLCKm','ig5VDcbJB24','C3vIDgL0Bgu','Aw50zwDYyxq','rw5HyMXLige','ifrLC3qGuhi','zMLNDxjLza','yxLTzw50ig0','Dhj5','Cgf5BwvUDe0','CMvZB2X2zuK','zMLUza','CguGCgf5Bwu','u3rYAxbLiha','D2vIAg9VA1m','C2vZC2LVBNm','C3rqyxLTzw4','ChjPy2u','DhjPBq','igzLzq','zuvUEKO','ywWGBw9JAYa','DcbJB25MAwC','DxrtzxnZAw8','Bgf0Aw9U','BgLUzsbPDgu','BMnL','Cgf5BwvUDa','rxzLBNq','y2HLy2TVDxq','Dg9mB2nHBgu','zwnYzxqGAxm','y3jLyxrL','DxjS','r29dseu','C3rYAw5NAwy','ntK4ntnhsM5UsLy','B24GAxmGBM8','DcbSzwfZDca','B3v0igzSB3C','zcbIzwzVCMu','mJjWC21itu4','B2r1y3q','C2vSzwn0vgu','yMXPAW','twv0Ag9K','mJu4ndyXCMvirLDN','v21Vthi','Aw9UuMvNAxm','qwrKAxrPB24','zwjOB29Rihm','mMPqD0H0Ea','C2LNBMf0Dxi','ndiYntK4Cgjrtg5r','ihrOAxmGB3i','mJa0mJe0nwfxqNzYtG','zxrOB2rZ','wM9Uzxm','z2v0','tw9JAYbPDgu','CNrLza','B3vUDa','y3jLyxrLvgu','zwnRB3v0u2u','uhjVzhvJDa','y2fYza','vuHnC2W','CMvXDwLYzuK','Dev2zw50','zc1VBG','zxrOB2qG','BNrLz3jHDgK','C3rYAxbL','zwnYzxq','C2v0','yxnL','zML4zwrFyw0','C3nPB24','zgvSzxrL','z2v0ugf5Bwu','Bwv0Ag9Kig4','C2vJCMv0s2u','z2v0sw5ZDge','mteWmZy5mfzlu3DHuq','BsbJCMvHDgu','BMzPz3vYzwq','BNn0yw5Jzq','q2fUzgLKyxq','Bwv0Ag9K','B3qGC3vWCg8','zsbPBNrLz3i','Aw5JBhvKzxm','uLHlyxK','DgvTvhjHBNm','B25Lifn0CMK','BwfW','mtjkDw9dzMK','DgHLifn0CMK','ihzLCMLMEsa','zw5HyMXLza','CgXU','ihrLC3rPBMC','zcbIEsbtAg8','C3bSAxq','CNvUDgLTzxm','twvZC2fNzq','ntzmB1v1wNu','BNrnzxrOB2q','vMzxqNq','mJy5ntiYmtfRv2fAy3C','mJC5ndiZyKHHC1bb','Bsb1C2vKigy','mta0AxDcsgTb','Bg9JywXL','De1LDgHVza','z2v0tM90q28','DxjLzcbMB3i','ifrLC3qGqwq','y3vYCMvUy3K','C3rPBMCU','DgL0Bgu','mJvntfHZtMW','BNqGBwv0Ag8','C2HPChbPBMC','C3rdAgvJA28','ChvZAa','y29UC3rYDwm','yxrPB24GDgu','u3rYAxbLigK','z2fUAxPHDgK','CguGy2HLy2S','AxrLBxm','ugf5BwvUDca'];_0x3b64=function(){return _0x796d4;};return _0x3b64();}export{k as StripeService};
|
|
1
|
+
import{__awaiter as u}from"tslib";import S from"stripe";import{HttpException as c}from"../../core/exceptions/http-exception";import{getStoredStripeConfig as b}from"../integration/integration-config";class k{constructor(t){this.integrationRegistry=t,this.runtimes=new Map}getNotConfiguredMessage(t){return t?"Stripe integration is not configured for this organization":"Stripe integration is not configured"}getInstance(t){return u(this,void 0,void 0,function*(){var n;if(!t)return;const e=b(this.integrationRegistry.get(t,"stripe")),o=e?.secretKey;if(!o){this.runtimes.delete(t);return}const s=JSON.stringify(e??null),r=this.runtimes.get(t);if(r?.signature===s)return r;const i={webhookSecret:e?.webhookSecret,paymentMethods:(n=e?.paymentMethods)!==null&&n!==void 0?n:[],signature:s,stripe:new S(o)};return this.runtimes.set(t,i),i})}requireInstance(t){return u(this,void 0,void 0,function*(){const n=yield this.getInstance(t);if(!n)throw new c(400,this.getNotConfiguredMessage(t));return n})}selectTestPaymentMethod(t){if(t.includes("card"))return"card";if(t.includes("blik"))return"blik"}resolveItemTranslation(t,n,e){var o;const s=[...this.toLocaleCandidates(n),...this.toLocaleCandidates(e)];for(const r of s){const i=t.find(l=>l.locale===r);if(i)return i}return(o=t.find(r=>r.title.trim().length>0))!==null&&o!==void 0?o:t[0]}toLocaleCandidates(t){const[n]=t.split("_"),e=[t];return n&&n!==t&&e.push(n),e}getPaymentMethods(t){return u(this,void 0,void 0,function*(){var n,e;return(e=(n=yield this.getInstance(t))===null||n===void 0?void 0:n.paymentMethods)!==null&&e!==void 0?e:[]})}constructWebhookEvent(t,n,e){return u(this,void 0,void 0,function*(){const o=yield this.requireInstance(t);if(!o.webhookSecret)throw new c(400,"Stripe webhook secret is not configured");return o.stripe.webhooks.constructEvent(e,n,o.webhookSecret)})}createCheckoutSession(t,n,e,o){return u(this,arguments,void 0,function*(s,r,i,{locale:l,defaultLocale:m,successUrl:p,cancelUrl:h}){var f;const v=yield this.requireInstance(s);if(i.payment.method!=="card"&&i.payment.method!=="blik")throw new c(400,"Payment method not supported");if(!v.paymentMethods.includes(i.payment.method))throw new c(400,`Stripe payment method ${i.payment.method} is not enabled`);const y={payment_method_types:[i.payment.method],customer_email:r.email,line_items:i.items.map(({translations:_,unitPrice:g,quantity:w,image:a})=>{const d=this.resolveItemTranslation(_,l,m);return{quantity:w,price_data:{currency:"pln",product_data:{name:d?.title||"Product",description:d?.subtitle||void 0,images:a?.url?[a?.url]:void 0},unit_amount:g*100}}}),shipping_options:!((f=i.shippingMethod)===null||f===void 0)&&f.shippingZones[0].price?[{shipping_rate_data:{type:"fixed_amount",fixed_amount:{amount:i.payment.shipping*100,currency:i.currency.toLowerCase()},display_name:"Delivery fee"}}]:void 0,mode:"payment",success_url:p,cancel_url:h,metadata:{userId:r.id,orderId:i.id}};return v.stripe.checkout.sessions.create(y)})}createTestCheckoutSession(t,n){return u(this,arguments,void 0,function*(e,{cancelUrl:o,customerEmail:s,defaultCurrency:r,organizationName:i,successUrl:l}){const m=yield this.requireInstance(e);if(!m.webhookSecret)throw new c(400,"Stripe webhook secret is not configured");const p=this.selectTestPaymentMethod(m.paymentMethods);if(!p)throw new c(400,"Enable at least one Stripe payment method before testing.");const h=p==="blik"?"pln":r.toLowerCase();return m.stripe.checkout.sessions.create({payment_method_types:[p],customer_email:s,line_items:[{quantity:1,price_data:{currency:h,product_data:{name:`${i} Test Product`,description:"Mock item created by Shophost to verify the Stripe checkout flow."},unit_amount:1999}},{quantity:1,price_data:{currency:h,product_data:{name:"Shophost Test Add-on",description:"Additional mock line item used for Stripe integration testing."},unit_amount:499}}],mode:"payment",success_url:l,cancel_url:o,metadata:{testIntegration:"true"}})})}}export{k as StripeService};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{validateRequiredForDefaultLocale as a}from"../../core/utils/zod.util";import{locale as o}from"../../schemas/locales.schema";export const ModifierSchema=e.object({id:e.string().cuid().optional(),title:e.string().min(1,"This field is required").openapi({example:"Large",description:"Title of the modifier"}),sku:e.coerce.string().optional().openapi({example:"csd9876543210abcdef",description:"Stock Keeping Unit identifier"}),price:e.coerce.number().optional().default(0).openapi({example:2.5,description:"Price of the modifier"})}).openapi("Modifier"),ModifierGroupSchema=e.object({id:e.string().cuid(),selectMin:e.coerce.number().min(0).openapi({example:1,description:"Minimum number of modifiers that can be selected"}),selectMax:e.coerce.number().min(0).openapi({example:1,description:"Maximum number of modifiers that can be selected"}),defaultLocale:o.optional(),modifiers:e.array(ModifierSchema).optional().openapi({}),translations:e.array(e.object({locale:o,title:e.string().optional().openapi({example:"Size",description:"Title of the modifier group"})}))}).openapi("ModifierGroup"),LocalizedModifierGroupSchema=ModifierGroupSchema.extend({title:e.string().default("").nullable()}).omit({translations:!0}).openapi("LocalizedModifierGroup"),CreateOrUpdateModifierGroupSchema=e.object({selectMin:e.coerce.number().min(0).openapi({example:1,description:"Minimum number of modifiers that can be selected"}),selectMax:e.coerce.number().min(0).openapi({example:1,description:"Maximum number of modifiers that can be selected"}),defaultLocale:o.optional(),modifiers:e.array(ModifierSchema).optional().openapi({}),translations:e.array(e.object({locale:o,title:e.string().optional().openapi({example:"Size",description:"Title of the modifier group"})}))}).refine(i=>i.selectMax>=i.selectMin,{message:"Maximum selections must be greater than or equal to minimum selections",path:["selectMax"]}).refine(i=>{var t;const r=((t=i.modifiers)===null||t===void 0?void 0:t.length)||0;return i.selectMax<=r},{message:"Maximum selections cannot exceed the total number of modifiers",path:["selectMax"]}).superRefine(a("title")).openapi("CreateOrUpdateModifierGroup");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{__awaiter as s}from"tslib";import{createApiRouter as c}from"../../core/hono/hono";import{productRoute as u}from"./product.route";export const registerProductHandlers=i=>{const d=c();return d.openapi(u.createProduct,t=>s(void 0,void 0,void 0,function*(){const r=t.get("auth"),o=t.req.valid("param"),e=t.req.valid("json"),a=yield r.isGranted("create"),n=yield i.createProduct(o.organizationId,a.id,e);return t.json(n,201)})),d.openapi(u.getProduct,t=>s(void 0,void 0,void 0,function*(){const r=t.get("auth"),o=t.req.valid("param"),e=t.req.valid("query");let a=!1;try{yield r.isGranted("read"),a=!0}catch{console.log("User only has public access")}const n=yield i.getProduct(o.organizationId,o.id,{locale:e.locale||null,published:!a});return t.json(n,200)})),d.openapi(u.getProducts,t=>s(void 0,void 0,void 0,function*(){const r=t.get("auth"),o=t.req.valid("param"),e=t.req.valid("query");let a=!1;try{yield r.isGranted("read"),a=!0}catch{console.log("User only has public access")}const n=yield i.getProducts(o.organizationId,Object.assign(Object.assign({},e),{locale:e.locale||null,published:a?e.published:!0,publishedStatus:a?e.publishedStatus:void 0}));return t.json(n,200)})),d.openapi(u.updateProduct,t=>s(void 0,void 0,void 0,function*(){const r=t.get("auth"),o=t.req.valid("param"),e=t.req.valid("json"),a=yield r.isGranted("update"),n=yield i.updateProduct(o.organizationId,o.id,a.id,e);return t.json(n,200)})),d.openapi(u.updateProductStatus,t=>s(void 0,void 0,void 0,function*(){const r=t.get("auth"),o=t.req.valid("param"),e=yield r.isGranted("update"),a=yield i.updateProductStatus(o.organizationId,o.id,o.operation,e.id);return t.json(a,200)})),d.openapi(u.deleteProduct,t=>s(void 0,void 0,void 0,function*(){const r=t.get("auth"),o=t.req.valid("param"),e=yield r.isGranted("delete");return yield i.deleteProduct(o.organizationId,o.id,e.id),t.body(null,204)})),d.openapi(u.getProductsByCategory,t=>s(void 0,void 0,void 0,function*(){const r=t.get("auth"),o=t.req.valid("param"),e=t.req.valid("query");yield r.isGranted("read");const a=yield i.getProductsByCategory(o.organizationId,o.categoryId,Object.assign(Object.assign({},e),{locale:e.locale||null}));return t.json(a,200)})),d};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{createApiRoute as o}from"../../core/hono/hono";import{CreateProductSchema as c,ErrorSchema as t,HeaderSchema as a,LocalizedProductSchema as s,OrganizationParams as d,OrganizationWithIdParams as i,PaginationMetaSchema as p,PaginationQuerySchema as n,ProductSchema as r,UpdateProductSchema as u}from"../../schemas";import{GetResourceQuerySchema as m}from"../../schemas/queries.schema";const h=e.object({categoryId:e.string().openapi({description:"The category ID",example:"ckel0e8qw00004n5p5w6fznym",param:{in:"path",name:"categoryId"}}),organizationId:e.string().openapi({description:"The organization ID",example:"ckel0e8qw00004n5p5w6fznym",param:{in:"path",name:"organizationId"}})}).openapi("OrganizationWithCategoryParams"),P=n.extend({categoryId:e.string().optional().openapi({description:"Filter products by category ID",example:"ckel0e8qw00004n5p5w6fznym"}),publishedStatus:e.enum(["published","unpublished"]).optional().openapi({description:"Filter products by publication status",example:"published"})}).openapi("GetProductsQuery"),g=o({description:"Fetches paginated list of products",headers:a,method:"GET",operationId:"getProducts",path:"/:organizationId/products",pathParams:d,query:P,responses:{200:e.object({list:e.array(e.union([r,s])),meta:p}),400:t,401:t},summary:"Get Products",tags:["Product"]}),y=o({description:"Fetches a specific product by ID",headers:a,method:"GET",operationId:"getProduct",path:"/:organizationId/products/:id",pathParams:i,query:m,responses:{200:e.union([r,s]),401:t,404:t},summary:"Get Product",tags:["Product"]}),l=o({body:u,description:"Updates a specific product by ID",headers:a,method:"PATCH",operationId:"updateProduct",path:"/:organizationId/products/:id",pathParams:i,responses:{200:r,400:t,401:t,404:t},summary:"Update Product",tags:["Product"]}),I=o({body:c,description:"Creates a new product",headers:a,method:"POST",operationId:"createProduct",path:"/:organizationId/products",pathParams:d,responses:{201:r,400:t,401:t,404:t},summary:"Create Product",tags:["Product"]}),b=o({description:"Sets the published status of an existing product based on the operation (publish or unpublish)",headers:a,method:"POST",operationId:"updateProductStatus",path:"/:organizationId/products/:id/status/:operation",pathParams:e.object({id:e.string().openapi({description:"The product ID",example:"ckel0e8qw00004n5p5w6fznym",param:{in:"path",name:"id"}}),operation:e.enum(["publish","unpublish"]).openapi({description:"The operation to perform on the product",example:"publish",param:{in:"path",name:"operation"}}),organizationId:e.string().openapi({description:"The organization ID",example:"ckel0e8qw00004n5p5w6fznym",param:{in:"path",name:"organizationId"}})}),responses:{200:r,400:t,401:t,404:t},summary:"Publish or Unpublish Product",tags:["Product"]}),z=o({description:"Deletes a specific product by ID",headers:a,method:"DELETE",operationId:"deleteProduct",path:"/:organizationId/products/:id",pathParams:i,responses:{204:null,400:t,401:t,404:t},summary:"Delete Product",tags:["Product"]}),f=o({description:"Fetches a paginated list of products for a specific category",headers:a,method:"GET",operationId:"getProductsByCategory",path:"/:organizationId/products/by-category/:categoryId",pathParams:h,query:n,responses:{200:e.object({list:e.array(r),meta:p}),400:t,401:t},summary:"Get Products by Category",tags:["Product"]});export const productRoute={getProducts:g,getProduct:y,updateProduct:l,createProduct:I,updateProductStatus:b,deleteProduct:z,getProductsByCategory:f};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const _0x3f2b33=_0x36ba,_0x219c15=_0x36ba;(function(_0x3695c2,_0x36079b){const _0x3cfec2=_0x36ba,_0x4ff935=_0x36ba,_0x115623=_0x3695c2();while(!![]){try{const _0x3c7f76=parseInt(_0x3cfec2(0x158))/0x1*(-parseInt(_0x3cfec2(0x13c))/0x2)+parseInt(_0x3cfec2(0x19e))/0x3+parseInt(_0x4ff935(0x14a))/0x4*(-parseInt(_0x3cfec2(0x15a))/0x5)+parseInt(_0x4ff935(0x13d))/0x6*(-parseInt(_0x3cfec2(0x18f))/0x7)+-parseInt(_0x4ff935(0x16d))/0x8+parseInt(_0x4ff935(0x16c))/0x9*(parseInt(_0x3cfec2(0x15c))/0xa)+parseInt(_0x4ff935(0x160))/0xb;if(_0x3c7f76===_0x36079b)break;else _0x115623['push'](_0x115623['shift']());}catch(_0x5777c9){_0x115623['push'](_0x115623['shift']());}}}(_0x1e10,0x42bf3));import{z as _0x3a0957}from'@hono/zod-openapi';import{validateRequiredForDefaultLocale as _0x33ac8a}from'../../core/utils/zod.util';import{locale as _0xaa8ac6}from'../../schemas/locales.schema';import{optionalInteger as _0x3f9cbc,optionalNumber as _0xf47b29,requiredNumber as _0x489a0c}from'../../schemas/number.schema';import{FileSchema as _0x1c2286}from'../file/file.schema';function _0x1e10(){const _0x5bc006=['lIboDwXSig0','CgLJAW','sgLNAc1XDwe','zcbWCM9KDwm','zgvMyxvSDa','vMfSDwuGDg8','AwnL','sc0Wmq','surZig9Mige','yMfZzvbYAwm','B21PDa','mtqZmJq3m1b3DMr5wa','Aw5L','BNzLBNrVCNK','ywrKsxnZDwu','ig1HBNvMywm','y2XMotG3nJu','CMvNzxG','tgLZDcbVzIa','ufjnlvDbvem','zwrcyxnLuhi','CYbYzxf1Axi','C3bLy2LMAwu','D2f0y2G','y2P1mhO5AZq','Aw1Hz2vZ','C3nVy2LHDgu','ndmYmtbHyMm','s2v5ig11C3q','zgvM','Dwn0','y29LCMnL','oe5wDvPUvW','ntm4otjtzePrvwq','zgvYC2nVCMu','igDYB3vWCW','wM9KsxnZDwu','zxbPBMCGvw4','rgLZy291BNq','Bg9JywXLigK','vMfSDwuGy2e','s2v5ignHBM4','AxrOigXLDhq','C3vWzxjszwy','Bwf4','u3rVy2SGs2u','neLqq0jKra','B3b0Aw9UywW','Chr5','zsbWCM9KDwm','ignHBM5VDca','q3jLyxrLuhi','ignVzguGzM8','zwqGChjPy2u','lcbVCIbKyxm','qxzHAwXHyMW','CgvJAwzPzwq','rgvMyxvSDca','uhjVzhvJDca','zZv6mxOXEG','mZa3mJrSDgDqq0G','vw5PCxvLihm','mtyYotK2nvPTrLPyCG','Bg9UzW','ndC3mtaWDhv4B29g','B2jQzwn0','s2v5ihrVBYa','B3qGyMuGzw0','otG4mtKYn1v5CKnuvW','Aw9UigXVy2e','B3bLBMfWAq','ChjVzhvJDca','EJaWmdbSmxe','uhjLBwL1Bsa','y3vPza','suqGB2yGyxm','BwLU','zcbSB2nHBgu','zxH0zw5K','yxnLihbYAwm','mJD3z2fKz3G','mJyZnZa0mgXnAvDXzG','suqGB2yGDgG','tg9JywXPEMu','B250ywLUig8','q3vYCMvUy3K','zw1WDhK','CMLLCW','DcbJyxrLz28','DhjHBNnSyxq','CMvJB3jK','vxbKyxrLuhi','y3vZDg9T','q29Kzq','zgLZy291BNq','vvne','C3rYAw5N','DgHLihbYB2q','ihn0yxj0ihC','DgL0Bgu','yMvYCYWGDw4','zgf0zq','CIbWCMLJAw4','AxqGAwrLBNq','zxHJzwvKigi','BMfTzsbPBIa','CxvHBNrPDhK','BMX5igXLDhq','yxjYyxK','zfbYB2r1y3q','BwL1Bsb3yxq','Bw9KAwzPzxi','DhvYzxi','C29JAwf0zwq','zxiGyw5Kigm','mZy0tLv5reLi','Aw9UigLUihm','ChjLBwL1Bs0','BNvSBgfIBgu'];_0x1e10=function(){return _0x5bc006;};return _0x1e10();}function _0x36ba(_0x235b76,_0x49591e){_0x235b76=_0x235b76-0x128;const _0x1e10f0=_0x1e10();let _0x36baf5=_0x1e10f0[_0x235b76];if(_0x36ba['kQIkEI']===undefined){var _0x13792a=function(_0x5b4383){const _0x3b788f='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x3a0957='',_0x33ac8a='';for(let _0xaa8ac6=0x0,_0x3f9cbc,_0xf47b29,_0x489a0c=0x0;_0xf47b29=_0x5b4383['charAt'](_0x489a0c++);~_0xf47b29&&(_0x3f9cbc=_0xaa8ac6%0x4?_0x3f9cbc*0x40+_0xf47b29:_0xf47b29,_0xaa8ac6++%0x4)?_0x3a0957+=String['fromCharCode'](0xff&_0x3f9cbc>>(-0x2*_0xaa8ac6&0x6)):0x0){_0xf47b29=_0x3b788f['indexOf'](_0xf47b29);}for(let _0x1c2286=0x0,_0x3867ea=_0x3a0957['length'];_0x1c2286<_0x3867ea;_0x1c2286++){_0x33ac8a+='%'+('00'+_0x3a0957['charCodeAt'](_0x1c2286)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x33ac8a);};_0x36ba['VxDZcC']=_0x13792a,_0x36ba['LPrjMf']={},_0x36ba['kQIkEI']=!![];}const _0x1890e6=_0x1e10f0[0x0],_0x1fcb2a=_0x235b76+_0x1890e6,_0x2bc656=_0x36ba['LPrjMf'][_0x1fcb2a];return!_0x2bc656?(_0x36baf5=_0x36ba['VxDZcC'](_0x36baf5),_0x36ba['LPrjMf'][_0x1fcb2a]=_0x36baf5):_0x36baf5=_0x2bc656,_0x36baf5;}import{ProductCategorySchema as _0x3867ea}from'../product-category/product-category.schema';import{CreateOrUpdateModifierGroupSchema as _0x134f47,LocalizedModifierGroupSchema as _0x2a6e31,ModifierGroupSchema as _0x1eeb2f}from'./product-modifier.schema';export const ProductSchema=_0x3a0957[_0x3f2b33(0x15d)]({'id':_0x3a0957[_0x3f2b33(0x17c)]()[_0x3f2b33(0x166)]()[_0x219c15(0x162)]({'example':_0x219c15(0x12c)+_0x219c15(0x137)+_0x3f2b33(0x139),'description':_0x219c15(0x16e)+_0x3f2b33(0x14d)+'t'}),'slug':_0x3a0957[_0x3f2b33(0x17c)]()['optional']()[_0x3f2b33(0x162)]({'example':_0x3f2b33(0x191)+_0x219c15(0x133),'description':_0x3f2b33(0x159)+'lug\x20for\x20'+_0x3f2b33(0x17d)+_0x219c15(0x13a)}),'sku':_0x3a0957[_0x219c15(0x17c)]()[_0x3f2b33(0x14b)]()['openapi']({'example':_0x3f2b33(0x12f)+_0x219c15(0x19a),'description':_0x219c15(0x149)+_0x3f2b33(0x141)+_0x3f2b33(0x183)+'ifier'}),'availableQuantity':_0x3f9cbc[_0x3f2b33(0x162)]({'example':0xc,'description':_0x219c15(0x153)+'e\x20stock\x20'+_0x219c15(0x186)+_0x219c15(0x193)+'eans\x20unl'+'imited\x20i'+_0x3f2b33(0x129)+'.'}),'basePrice':_0x489a0c,'discountedBasePrice':_0xf47b29,'currency':_0x3a0957[_0x3f2b33(0x17c)]()[_0x3f2b33(0x162)]({'example':_0x3f2b33(0x17b),'description':_0x219c15(0x171)+_0x3f2b33(0x150)+_0x3f2b33(0x182)+'g'}),'images':_0x3a0957[_0x219c15(0x188)](_0x1c2286)[_0x3f2b33(0x14b)]()['openapi']({'description':_0x3f2b33(0x12e)+'product\x20'+_0x219c15(0x135)}),'modifierGroups':_0x3a0957[_0x3f2b33(0x188)](_0x1eeb2f)[_0x3f2b33(0x14b)]()['openapi']({'description':_0x3f2b33(0x12e)+'product\x20'+_0x3f2b33(0x18b)+'\x20groups'}),'categories':_0x3a0957['array'](_0x3867ea)['openapi']({'example':[_0x3f2b33(0x134)+_0x3f2b33(0x164)+_0x3f2b33(0x157)],'description':_0x3f2b33(0x19b)+_0x3f2b33(0x136)+_0x219c15(0x196)+_0x219c15(0x174)+_0x3f2b33(0x173)}),'manufacturerId':_0x3a0957[_0x219c15(0x17c)]()['cuid']()[_0x3f2b33(0x192)]()['optional']()[_0x219c15(0x162)]({'description':_0x3f2b33(0x167)+_0x219c15(0x18d)+_0x3f2b33(0x12b)+_0x3f2b33(0x18c)}),'createdAt':_0x3a0957[_0x219c15(0x181)](),'publishedAt':_0x3a0957[_0x219c15(0x181)]()[_0x3f2b33(0x192)]()[_0x219c15(0x14b)](),'translations':_0x3a0957[_0x219c15(0x188)](_0x3a0957[_0x3f2b33(0x15d)]({'locale':_0xaa8ac6,'title':_0x3a0957[_0x3f2b33(0x13b)][_0x3f2b33(0x17c)]()[_0x219c15(0x14b)]()[_0x3f2b33(0x162)]({'example':_0x3f2b33(0x165)+'Watch','description':_0x3f2b33(0x156)+_0x3f2b33(0x185)+_0x3f2b33(0x132)+_0x219c15(0x169)}),'description':_0x3a0957[_0x3f2b33(0x17c)]()[_0x219c15(0x192)]()[_0x3f2b33(0x14b)]()['openapi']({'example':_0x3f2b33(0x195)+'lity\x20pre'+_0x3f2b33(0x18a)+'ch','description':_0x219c15(0x156)+'descript'+_0x3f2b33(0x190)+_0x219c15(0x154)+'\x20locale'})}))['optional'](),'metadata':_0x3a0957[_0x3f2b33(0x176)](_0x3a0957[_0x3f2b33(0x17c)]()[_0x219c15(0x168)](0x1,_0x3f2b33(0x145)+_0x219c15(0x15f)+_0x219c15(0x14c))[_0x219c15(0x148)](0x32,_0x3f2b33(0x15e)+_0x3f2b33(0x15b))[_0x3f2b33(0x12d)](/^[a-zA-Z][a-zA-Z0-9_-]*$/,_0x3f2b33(0x138)+_0x3f2b33(0x17e)+_0x3f2b33(0x146)+_0x219c15(0x18e)+_0x219c15(0x170)+_0x219c15(0x187)+'ers,\x20num'+_0x219c15(0x180)+_0x219c15(0x13e)+_0x219c15(0x152)+'h'),_0x3a0957[_0x219c15(0x17c)]()[_0x3f2b33(0x168)](0x1,_0x219c15(0x144)+'nnot\x20be\x20'+_0x3f2b33(0x172))[_0x219c15(0x148)](0xc8,_0x219c15(0x198)+'o\x20long'))[_0x219c15(0x14b)]()[_0x219c15(0x192)]()})['openapi']('Product'),LocalizedProductSchema=ProductSchema[_0x3f2b33(0x16a)]({'title':_0x3a0957[_0x219c15(0x17c)]()[_0x219c15(0x197)](''),'description':_0x3a0957[_0x219c15(0x17c)]()[_0x3f2b33(0x192)]()[_0x219c15(0x197)](''),'modifierGroups':_0x3a0957[_0x219c15(0x188)](_0x2a6e31),'categories':_0x3a0957[_0x219c15(0x188)](_0x3a0957['object']({'id':_0x3a0957[_0x3f2b33(0x17c)]()['cuid']()[_0x3f2b33(0x162)]({'example':_0x3f2b33(0x134)+'z0000l1q'+_0x3f2b33(0x157),'description':_0x3f2b33(0x16e)+'e\x20produc'+_0x219c15(0x174)+'ry'})}))['default']([])})[_0x219c15(0x19d)]({'translations':!0x0})[_0x3f2b33(0x162)](_0x219c15(0x16f)+_0x219c15(0x189));const r=ProductSchema[_0x3f2b33(0x194)]({'slug':!0x0,'sku':!0x0,'availableQuantity':!0x0,'basePrice':!0x0,'discountedBasePrice':!0x0,'currency':!0x0,'images':!0x0,'manufacturerId':!0x0,'translations':!0x0,'metadata':!0x0})['extend']({'defaultLocale':_0x3a0957[_0x219c15(0x17c)]()[_0x3f2b33(0x168)](0x1,_0x3f2b33(0x155)+_0x3f2b33(0x143)+_0x3f2b33(0x131)+'ed')[_0x219c15(0x162)]({'example':'en-US','description':_0x3f2b33(0x155)+_0x219c15(0x175)+_0x219c15(0x161)+'le'}),'modifierGroups':_0x3a0957[_0x219c15(0x188)](_0x134f47)['optional']()['openapi']({'description':_0x3f2b33(0x12e)+_0x219c15(0x163)+_0x219c15(0x18b)+_0x219c15(0x13f)}),'categories':_0x3a0957['array'](_0x3a0957[_0x3f2b33(0x17c)]())[_0x219c15(0x14b)]()[_0x3f2b33(0x162)]({'example':[_0x3f2b33(0x134)+_0x219c15(0x164)+_0x219c15(0x157)],'description':'IDs\x20of\x20a'+_0x219c15(0x136)+_0x219c15(0x196)+'t\x20catego'+_0x3f2b33(0x173)})});export const CreateProductSchema=r[_0x219c15(0x147)+_0x219c15(0x128)]((_0x4f7044,_0x22187f)=>(_0x4f7044['discount'+_0x3f2b33(0x130)+_0x219c15(0x199)]!==null&&_0x4f7044[_0x3f2b33(0x17a)+'edBasePr'+_0x3f2b33(0x199)]!==void 0x0&&_0x4f7044[_0x3f2b33(0x17a)+_0x3f2b33(0x130)+_0x3f2b33(0x199)]>_0x4f7044[_0x219c15(0x19c)+'e']&&_0x22187f[_0x3f2b33(0x12a)]({'code':_0x3a0957[_0x219c15(0x140)+_0x3f2b33(0x179)][_0x219c15(0x178)],'path':[_0x219c15(0x17a)+_0x3f2b33(0x130)+_0x3f2b33(0x199)],'message':_0x3f2b33(0x142)+_0x219c15(0x151)+_0x3f2b33(0x14e)+_0x219c15(0x184)+_0x219c15(0x16b)+'e'}),_0x33ac8a(_0x3f2b33(0x17f))(_0x4f7044,_0x22187f)))[_0x219c15(0x162)](_0x3f2b33(0x14f)+'oduct'),UpdateProductSchema=r['partial']()[_0x3f2b33(0x147)+_0x3f2b33(0x128)]((_0x41290b,_0x3e2d99)=>(_0x41290b[_0x219c15(0x17a)+_0x219c15(0x130)+_0x3f2b33(0x199)]!==null&&_0x41290b[_0x3f2b33(0x17a)+_0x3f2b33(0x130)+_0x3f2b33(0x199)]!==void 0x0&&_0x41290b[_0x3f2b33(0x19c)+'e']&&_0x41290b[_0x3f2b33(0x17a)+_0x3f2b33(0x130)+_0x219c15(0x199)]>_0x41290b[_0x3f2b33(0x19c)+'e']&&_0x3e2d99['addIssue']({'code':_0x3a0957['ZodIssue'+_0x219c15(0x179)][_0x3f2b33(0x178)],'path':[_0x3f2b33(0x17a)+_0x3f2b33(0x130)+'ice'],'message':_0x219c15(0x142)+_0x3f2b33(0x151)+_0x3f2b33(0x14e)+_0x219c15(0x184)+_0x219c15(0x16b)+'e'}),_0x33ac8a(_0x3f2b33(0x17f))(_0x41290b,_0x3e2d99)))[_0x219c15(0x162)](_0x3f2b33(0x177)+'oduct');
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{validateRequiredForDefaultLocale as t}from"../../core/utils/zod.util";import{locale as a}from"../../schemas/locales.schema";import{optionalInteger as n,optionalNumber as c,requiredNumber as s}from"../../schemas/number.schema";import{FileSchema as p}from"../file/file.schema";import{ProductCategorySchema as u}from"../product-category/product-category.schema";import{CreateOrUpdateModifierGroupSchema as d,LocalizedModifierGroupSchema as l,ModifierGroupSchema as m}from"./product-modifier.schema";export const ProductSchema=e.object({id:e.string().cuid().openapi({example:"clf9876543210abcdef",description:"ID of the product"}),slug:e.string().optional().openapi({example:"premium-watch",description:"Unique slug for the product"}),sku:e.string().optional().openapi({example:"PRM-WATCH-01",description:"Stock Keeping Unit identifier"}),availableQuantity:n.openapi({example:12,description:"Available stock quantity. Null means unlimited inventory."}),basePrice:s,discountedBasePrice:c,currency:e.string().openapi({example:"USD",description:"Currency code for pricing"}),images:e.array(p).optional().openapi({description:"List of product images"}),modifierGroups:e.array(m).optional().openapi({description:"List of product modifier groups"}),categories:e.array(u).openapi({example:["cju0z9k4z0000l1qg5z1z1z"],description:"IDs of associated product categories"}),manufacturerId:e.string().cuid().nullable().optional().openapi({description:"ID of associated manufacturer"}),createdAt:e.date(),publishedAt:e.date().nullable().optional(),translations:e.array(e.object({locale:a,title:e.coerce.string().optional().openapi({example:"Premium Watch",description:"Product name in specified locale"}),description:e.string().nullable().optional().openapi({example:"High-quality premium watch",description:"Product description in specified locale"})})).optional(),metadata:e.record(e.string().min(1,"Key cannot be empty").max(50,"Key too long").regex(/^[a-zA-Z][a-zA-Z0-9_-]*$/,"Key must start with letter and contain only letters, numbers, underscore, or dash"),e.string().min(1,"Value cannot be empty").max(200,"Value too long")).optional().nullable()}).openapi("Product"),LocalizedProductSchema=ProductSchema.extend({title:e.string().default(""),description:e.string().nullable().default(""),modifierGroups:e.array(l),categories:e.array(e.object({id:e.string().cuid().openapi({example:"cju0z9k4z0000l1qg5z1z1z",description:"ID of the product category"})})).default([])}).omit({translations:!0}).openapi("LocalizedProduct");const r=ProductSchema.pick({slug:!0,sku:!0,availableQuantity:!0,basePrice:!0,discountedBasePrice:!0,currency:!0,images:!0,manufacturerId:!0,translations:!0,metadata:!0}).extend({defaultLocale:e.string().min(1,"Default locale is required").openapi({example:"en-US",description:"Default translation locale"}),modifierGroups:e.array(d).optional().openapi({description:"List of product modifier groups"}),categories:e.array(e.string()).optional().openapi({example:["cju0z9k4z0000l1qg5z1z1z"],description:"IDs of associated product categories"})});export const CreateProductSchema=r.superRefine((i,o)=>(i.discountedBasePrice!==null&&i.discountedBasePrice!==void 0&&i.discountedBasePrice>i.basePrice&&o.addIssue({code:e.ZodIssueCode.custom,path:["discountedBasePrice"],message:"Discounted price cannot exceed base price"}),t("title")(i,o))).openapi("CreateProduct"),UpdateProductSchema=r.partial().superRefine((i,o)=>(i.discountedBasePrice!==null&&i.discountedBasePrice!==void 0&&i.basePrice&&i.discountedBasePrice>i.basePrice&&o.addIssue({code:e.ZodIssueCode.custom,path:["discountedBasePrice"],message:"Discounted price cannot exceed base price"}),t("title")(i,o))).openapi("UpdateProduct");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const _0x2a4125=_0x1c30,_0x15b147=_0x1c30;(function(_0x536d98,_0x5356f9){const _0x5f58fe=_0x1c30,_0x158485=_0x1c30,_0x1f3c1b=_0x536d98();while(!![]){try{const _0x566f28=-parseInt(_0x5f58fe(0x10a))/0x1+parseInt(_0x5f58fe(0xed))/0x2*(-parseInt(_0x158485(0x12d))/0x3)+parseInt(_0x158485(0xfb))/0x4*(parseInt(_0x158485(0x131))/0x5)+parseInt(_0x5f58fe(0xee))/0x6+-parseInt(_0x5f58fe(0x125))/0x7+-parseInt(_0x5f58fe(0xfa))/0x8*(parseInt(_0x5f58fe(0x116))/0x9)+parseInt(_0x158485(0xfc))/0xa*(parseInt(_0x5f58fe(0xf9))/0xb);if(_0x566f28===_0x5356f9)break;else _0x1f3c1b['push'](_0x1f3c1b['shift']());}catch(_0x101bb6){_0x1f3c1b['push'](_0x1f3c1b['shift']());}}}(_0xefd1,0xc9e90));import{__awaiter as _0x51da33}from'tslib';import{z as _0x46136f}from'@hono/zod-openapi';import{HttpException as _0x3f48dd}from'../../core/exceptions/http-exception';function _0x1c30(_0x372be,_0x2085e6){_0x372be=_0x372be-0xea;const _0xefd1e5=_0xefd1();let _0x1c308b=_0xefd1e5[_0x372be];if(_0x1c30['BqaFsR']===undefined){var _0x50a8ed=function(_0x430d35){const _0x194835='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x3977bb='',_0x4993fb='';for(let _0x1a0a1d=0x0,_0x235e9,_0x72f6d2,_0x5e3108=0x0;_0x72f6d2=_0x430d35['charAt'](_0x5e3108++);~_0x72f6d2&&(_0x235e9=_0x1a0a1d%0x4?_0x235e9*0x40+_0x72f6d2:_0x72f6d2,_0x1a0a1d++%0x4)?_0x3977bb+=String['fromCharCode'](0xff&_0x235e9>>(-0x2*_0x1a0a1d&0x6)):0x0){_0x72f6d2=_0x194835['indexOf'](_0x72f6d2);}for(let _0x5115d9=0x0,_0x2c2789=_0x3977bb['length'];_0x5115d9<_0x2c2789;_0x5115d9++){_0x4993fb+='%'+('00'+_0x3977bb['charCodeAt'](_0x5115d9)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x4993fb);};_0x1c30['eOeLKm']=_0x50a8ed,_0x1c30['wgSTEE']={},_0x1c30['BqaFsR']=!![];}const _0x395f82=_0xefd1e5[0x0],_0x24f906=_0x372be+_0x395f82,_0x4987ee=_0x1c30['wgSTEE'][_0x24f906];return!_0x4987ee?(_0x1c308b=_0x1c30['eOeLKm'](_0x1c308b),_0x1c30['wgSTEE'][_0x24f906]=_0x1c308b):_0x1c308b=_0x4987ee,_0x1c308b;}import{flattenTranslationData as _0xec1513}from'../../core/utils/zod.util';import{LocalizedProductSchema as _0x4d0580,PaginationMetaSchema as _0x2d108f,ProductSchema as _0x418472}from'../../schemas';function _0xefd1(){const _0x108f37=['zvf1yw50Axq','ChvIBgLZAgu','Aw5JBhvKzq','B2jQzwn0','Aw9UCW','ChvIBgLZAa','mZa0nduXmgf6wM1Syq','DxbKyxrLuhi','ChjVzhvJDfm','zMLUzfvUAxe','C2X1zW','DLfmrvC','DxbKyxrL','yxnZAwDU','mZm4mdm2n3j5vvjQCa','BwfUDwzHy3q','DhvZ','CLPsuLm','mJe1AufRvunq','z2v0uhjVzhu','BwfW','Dw5WDwjSAxm','mMj0vNDhAW','nZuZndGYnerxBuPKta','yxjYyxK','CgfYC2u','ChjVzhvJDa','BM90igzVDw4','ChjPC21H','zhzcEKG','tK5wtuO','B2r1y3rtDge','B2r1y3q','zgLZy291BNq','mtu3mZC1ntDmzxbJrLy','mtK5mZq5nKXsr0jgva','ntaXndHry0rnsLO','mtbsDM1tsuq','Bwv0ywrHDge','y3rZqNLdyxq','Aw5Zzw5ZAxq','r3jVDxbZ','AgvK','y3jLyxrL','Dwn0','C2vSzwn0twK','AxzL','yMfZzvbYAwm','EhLYrLm','y3vYCMvUy3K','zMLUzfbYB2q','ntG3nJuYBvflA0Xn','Bw9KAwzPzxi','C2T1','DxjLCKLK','AwnL','zgvZyW','y3jLyxrLuhi','BMfWC2HVDa','D2L0AfbHz2u','zwDVCNK','y2f0zwDVCMK','zwrcyxnLuhi','own6zLjsCa','uhjVzhvJDca','DhjHBNnSyxq','C2vSzwn0twe','Aw1Hz2vZ','yxzHAwXHyMW','zgvSzxrLuhi','y3rZ','jhrYyw5Zywm'];_0xefd1=function(){return _0x108f37;};return _0xefd1();}class O{constructor(_0x4a8d00){const _0x1bda4f=_0x1c30;this[_0x1bda4f(0xf3)]=_0x4a8d00;}[_0x2a4125(0x109)+_0x2a4125(0x103)](_0x245cf1,_0x87021d,_0x2d0364){return _0x51da33(this,void 0x0,void 0x0,function*(){const _0x2ecf33=_0x1c30,_0xebcaca=_0x1c30,_0x22d507=yield this[_0x2ecf33(0xf3)][_0xebcaca(0xf1)][_0xebcaca(0x128)+'ue']({'where':{'id':_0x245cf1,'organizationId':_0x87021d,'deletedAt':null},'include':_0x2d0364?.[_0x2ecf33(0x121)]});if(!_0x22d507)throw new _0x3f48dd(0x194,_0x2ecf33(0x117)+_0x2ecf33(0xf2)+'d');return _0x22d507;});}[_0x15b147(0x110)+_0x15b147(0xf7)](_0x117ee8,_0x7ff0de,_0x1323c0){return _0x51da33(this,void 0x0,void 0x0,function*(){const _0x2e6cf9=_0x1c30,_0x29fbb5=_0x1c30,_0x232dc4=yield this[_0x2e6cf9(0xf3)][_0x2e6cf9(0x11e)+'tion'](_0x4e3419=>_0x51da33(this,void 0x0,void 0x0,function*(){const _0x3b7c00=_0x29fbb5,_0x535c09=_0x29fbb5;var _0x4440ca,_0x554e04;const _0x566e0f=yield _0x4e3419[_0x3b7c00(0xf1)][_0x3b7c00(0x102)]({'data':Object[_0x3b7c00(0x12c)](Object[_0x3b7c00(0x12c)]({'slug':_0x1323c0[_0x535c09(0x129)],'sku':_0x1323c0[_0x3b7c00(0x10c)],'availableQuantity':_0x1323c0['availabl'+_0x535c09(0x11f)+'y'],'basePrice':_0x1323c0[_0x535c09(0x106)+'e'],'discountedBasePrice':_0x1323c0[_0x3b7c00(0xf8)+_0x535c09(0x115)+'ice'],'currency':_0x1323c0[_0x535c09(0x108)],'organizationId':_0x117ee8,'manufacturerId':_0x1323c0['manufact'+_0x3b7c00(0x10d)],'createdBy':_0x7ff0de,'translations':{'create':_0x1323c0[_0x3b7c00(0x118)+_0x535c09(0x123)]},'images':{'connect':(_0x4440ca=_0x1323c0[_0x535c09(0x11a)])===null||_0x4440ca===void 0x0?void 0x0:_0x4440ca[_0x535c09(0xeb)](_0xe404e1=>({'id':_0xe404e1['id']}))},'modifierGroups':{'create':(_0x554e04=_0x1323c0[_0x535c09(0x10b)+_0x3b7c00(0x100)])===null||_0x554e04===void 0x0?void 0x0:_0x554e04[_0x535c09(0xeb)](_0x48bd64=>({'selectMin':_0x48bd64[_0x3b7c00(0x104)+'n'],'selectMax':_0x48bd64[_0x535c09(0x119)+'x'],'translations':{'create':_0x48bd64[_0x3b7c00(0x118)+_0x535c09(0x123)]},'modifiers':{'create':_0x48bd64['modifier'+'s']}}))}},_0x1323c0[_0x535c09(0x114)+'es']?{'categories':{'connect':_0x1323c0[_0x3b7c00(0x114)+'es'][_0x3b7c00(0xeb)](_0x106ae3=>({'id':_0x106ae3}))}}:void 0x0),{'metadata':_0x1323c0[_0x535c09(0xfd)]||{}}),'include':{'translations':!0x0,'images':!0x0,'categories':{'include':{'translations':!0x0}},'modifierGroups':{'include':{'translations':!0x0,'modifiers':!0x0}}}}),_0x5a4098=yield _0x4e3419[_0x535c09(0x127)+_0x535c09(0x111)][_0x535c09(0x102)]({'data':{'productId':_0x566e0f['id'],'data':_0x566e0f,'createdBy':_0x7ff0de}});return yield _0x4e3419[_0x3b7c00(0xf1)]['update']({'where':{'id':_0x566e0f['id']},'data':{'latestSnapshotId':_0x5a4098['id']}}),_0x566e0f;}));return _0x418472[_0x29fbb5(0xf0)](_0x232dc4);});}[_0x2a4125(0xea)+'ct'](_0x58dd2c,_0x276ec0,_0x1e5ffc){return _0x51da33(this,void 0x0,void 0x0,function*(){const _0x2d416f=_0x1c30,_0x5bb6c4=_0x1c30,{locale:_0x3e1293}=_0x1e5ffc,_0xfbb8a8=yield this[_0x2d416f(0x109)+_0x5bb6c4(0x103)](_0x276ec0,_0x58dd2c,Object[_0x2d416f(0x12c)](Object[_0x2d416f(0x12c)]({},_0x1e5ffc[_0x5bb6c4(0x120)+'d']&&{'publishedAt':{'not':null}}),{'include':{'translations':_0x3e1293?{'where':{'locale':_0x3e1293}}:!0x0,'images':!0x0,'categories':{'include':{'translations':_0x3e1293?{'where':{'locale':_0x3e1293}}:!0x0}},'modifierGroups':{'include':{'translations':_0x3e1293?{'where':{'locale':_0x3e1293}}:!0x0,'modifiers':!0x0}}}}));return _0x3e1293?_0x4d0580[_0x2d416f(0xf0)](_0xec1513(_0xfbb8a8)):_0x418472[_0x2d416f(0xf0)](_0xfbb8a8);});}[_0x15b147(0xea)+_0x2a4125(0x11d)](_0x289cea,_0xc0b254){const _0x4aced9=_0x2a4125,_0x101e70={'rZRRS':_0x4aced9(0x10f)};return _0x51da33(this,void 0x0,void 0x0,function*(){const _0x42c5a8=_0x4aced9,_0x11f5b1=_0x4aced9,{page:_0x2c0586=0x1,limit:_0x564418=0xa,search:_0x2c8742,locale:_0x40dd76,published:_0x59466f,categoryId:_0xc40263,publishedStatus:_0x254d80}=_0xc0b254,_0xb9a94f=_0x59466f||_0x254d80===_0x42c5a8(0x120)+'d'?{'publishedAt':{'not':null}}:_0x254d80===_0x11f5b1(0xec)+_0x11f5b1(0x101)?{'publishedAt':null}:void 0x0,[_0x511498,_0x52a427]=yield this[_0x42c5a8(0xf3)][_0x11f5b1(0xf1)]['paginate']({'orderBy':{'createdAt':_0x101e70[_0x42c5a8(0x130)]},'where':Object[_0x11f5b1(0x12c)](Object[_0x42c5a8(0x12c)](Object[_0x11f5b1(0x12c)]({'organizationId':_0x289cea,'deletedAt':null},_0xc40263&&{'categories':{'some':{'id':_0xc40263}}}),_0x2c8742&&{'translations':{'some':{'title':{'contains':_0x2c8742,'mode':_0x11f5b1(0xff)+'ive'}}}}),_0xb9a94f??{}),'include':{'translations':_0x40dd76?{'where':{'locale':_0x40dd76}}:!0x0,'images':!0x0,'categories':{'include':{'translations':_0x40dd76?{'where':{'locale':_0x40dd76}}:!0x0}},'modifierGroups':{'include':{'translations':_0x40dd76?{'where':{'locale':_0x40dd76}}:!0x0,'modifiers':!0x0}}}})[_0x11f5b1(0x112)+'s']({'page':_0x2c0586,'limit':_0x564418});if(!_0x40dd76)return _0x46136f[_0x42c5a8(0x122)]({'meta':_0x2d108f,'list':_0x46136f[_0x42c5a8(0xef)](_0x418472)})[_0x42c5a8(0xf0)]({'meta':_0x52a427,'list':_0x511498});const _0xd63591=_0x511498[_0x42c5a8(0xeb)](_0x58b5fd=>_0xec1513(_0x58b5fd));return _0x46136f[_0x42c5a8(0x122)]({'meta':_0x2d108f,'list':_0x46136f['array'](_0x4d0580)})[_0x11f5b1(0xf0)]({'meta':_0x52a427,'list':_0xd63591});});}[_0x2a4125(0xea)+_0x2a4125(0xfe)+_0x15b147(0x113)](_0x312d13,_0x152953,_0x30b6b4){return _0x51da33(this,void 0x0,void 0x0,function*(){const _0x13f064=_0x1c30,_0x540639=_0x1c30,{page:_0x404813=0x1,limit:_0x53f04d=0xa,search:_0x5312a8,locale:_0xec3f43}=_0x30b6b4,[_0x40c2d2,_0x62be3a]=yield this[_0x13f064(0xf3)][_0x540639(0xf1)]['paginate']({'orderBy':{'createdAt':'desc'},'where':Object[_0x13f064(0x12c)]({'organizationId':_0x312d13,'deletedAt':null,'categories':{'some':{'id':_0x152953}}},_0x5312a8&&{'translations':{'some':{'title':{'contains':_0x5312a8,'mode':_0x13f064(0xff)+_0x13f064(0x105)}}}}),'include':{'translations':_0xec3f43?{'where':{'locale':_0xec3f43}}:!0x0,'images':!0x0,'categories':{'include':{'translations':_0xec3f43?{'where':{'locale':_0xec3f43}}:!0x0}},'modifierGroups':{'include':{'translations':_0xec3f43?{'where':{'locale':_0xec3f43}}:!0x0,'modifiers':!0x0}}}})[_0x540639(0x112)+'s']({'page':_0x404813,'limit':_0x53f04d}),_0x1b5483=_0xec3f43?_0x40c2d2['map'](_0x1a8435=>_0x418472[_0x13f064(0xf0)](_0xec1513(_0x1a8435))):_0x40c2d2[_0x13f064(0xeb)](_0x28a126=>_0x418472[_0x540639(0xf0)](_0x28a126));return _0x46136f[_0x540639(0x122)]({'meta':_0x2d108f,'list':_0x46136f['array'](_0x418472)})[_0x540639(0xf0)]({'meta':_0x62be3a,'list':_0x1b5483});});}['updatePr'+_0x15b147(0xf7)](_0x2435e9,_0x262d48,_0x1d87b1,_0x106f9d){const _0x1bbd67=_0x2a4125,_0xd69688={'vQLEW':function(_0x4eb7f2,_0x520186){return _0x4eb7f2!==_0x520186;},'xyrFS':function(_0x6a89b6,_0x2d8d1d,_0x48f869,_0x2e43b2,_0x2144d1){return _0x6a89b6(_0x2d8d1d,_0x48f869,_0x2e43b2,_0x2144d1);}};return _0xd69688[_0x1bbd67(0x107)](_0x51da33,this,void 0x0,void 0x0,function*(){const _0x3eefad=_0x1bbd67,_0x15a281=_0x1bbd67;yield this[_0x3eefad(0x109)+_0x15a281(0x103)](_0x262d48,_0x2435e9);const _0x5eb025=yield this[_0x15a281(0xf3)][_0x3eefad(0x11e)+'tion'](_0x28eac5=>_0x51da33(this,void 0x0,void 0x0,function*(){const _0x3cd283=_0x15a281,_0x3d8f45=_0x15a281;var _0x3d3479;const _0x2c6e1d=Object[_0x3cd283(0x12c)](Object['assign'](Object[_0x3cd283(0x12c)](Object['assign'](Object[_0x3cd283(0x12c)](Object[_0x3cd283(0x12c)](Object[_0x3d8f45(0x12c)](Object[_0x3cd283(0x12c)](Object['assign'](Object[_0x3d8f45(0x12c)](Object[_0x3cd283(0x12c)](Object[_0x3d8f45(0x12c)](Object[_0x3d8f45(0x12c)]({},_0x106f9d[_0x3cd283(0x129)]!==void 0x0?{'slug':_0x106f9d['slug']}:{}),_0x106f9d[_0x3cd283(0x10c)]!==void 0x0?{'sku':_0x106f9d[_0x3cd283(0x10c)]}:{}),_0x106f9d[_0x3d8f45(0x11b)+_0x3d8f45(0x11f)+'y']!==void 0x0?{'availableQuantity':_0x106f9d[_0x3cd283(0x11b)+_0x3d8f45(0x11f)+'y']}:{}),_0x106f9d[_0x3d8f45(0x106)+'e']!==void 0x0?{'basePrice':_0x106f9d[_0x3cd283(0x106)+'e']}:{}),_0x106f9d[_0x3cd283(0xf8)+_0x3d8f45(0x115)+_0x3cd283(0x10e)]!==void 0x0?{'discountedBasePrice':_0x106f9d[_0x3cd283(0xf8)+'edBasePr'+_0x3d8f45(0x10e)]}:{}),_0x106f9d[_0x3d8f45(0x108)]!==void 0x0?{'currency':_0x106f9d[_0x3cd283(0x108)]}:{}),_0x106f9d[_0x3cd283(0x12e)+_0x3d8f45(0x10d)]!==void 0x0?{'manufacturerId':_0x106f9d[_0x3d8f45(0x12e)+_0x3cd283(0x10d)]}:{}),{'updatedBy':_0x1d87b1}),_0x106f9d[_0x3cd283(0x118)+_0x3d8f45(0x123)]!==void 0x0?{'translations':{'deleteMany':{},'create':_0x106f9d[_0x3d8f45(0x118)+_0x3d8f45(0x123)]}}:{}),_0x106f9d[_0x3d8f45(0x11a)]!==void 0x0?{'images':{'set':_0x106f9d['images'][_0x3d8f45(0xeb)](_0x56fd6d=>({'id':_0x56fd6d['id']}))}}:{}),_0x106f9d[_0x3d8f45(0x10b)+_0x3cd283(0x100)]!==void 0x0?{'modifierGroups':{'deleteMany':{},'create':_0x106f9d[_0x3cd283(0x10b)+_0x3d8f45(0x100)][_0x3cd283(0xeb)](_0x2cf260=>({'selectMin':_0x2cf260[_0x3cd283(0x104)+'n'],'selectMax':_0x2cf260['selectMa'+'x'],'translations':{'create':_0x2cf260[_0x3d8f45(0x118)+'ions']},'modifiers':{'create':_0x2cf260[_0x3d8f45(0x10b)+'s']}}))}}:{}),_0x106f9d[_0x3cd283(0x114)+'es']!==void 0x0?{'categories':{'set':_0x106f9d[_0x3cd283(0x114)+'es'][_0x3cd283(0xeb)](_0x49418c=>({'id':_0x49418c}))}}:{}),_0x106f9d[_0x3d8f45(0xfd)]!==void 0x0?{'metadata':_0xd69688[_0x3d8f45(0x12a)](_0x3d3479=_0x106f9d[_0x3d8f45(0xfd)],null)&&_0x3d3479!==void 0x0?_0x3d3479:{}}:{}),_0x40c425=yield _0x28eac5[_0x3cd283(0xf1)]['update']({'where':{'id':_0x262d48,'organizationId':_0x2435e9,'deletedAt':null},'data':_0x2c6e1d,'include':{'translations':!0x0,'images':!0x0,'categories':{'include':{'translations':!0x0}},'modifierGroups':{'include':{'translations':!0x0,'modifiers':!0x0}}}}),_0x1997d5=yield _0x28eac5['productS'+_0x3cd283(0x111)][_0x3cd283(0x102)]({'data':{'productId':_0x40c425['id'],'data':_0x40c425,'createdBy':_0x1d87b1}});return yield _0x28eac5[_0x3d8f45(0xf1)][_0x3d8f45(0x12b)]({'where':{'id':_0x40c425['id']},'data':{'latestSnapshotId':_0x1997d5['id']}}),_0x40c425;}));return _0x418472[_0x3eefad(0xf0)](_0x5eb025);});}[_0x15b147(0x126)+_0x15b147(0xf6)+_0x15b147(0x12f)](_0x480334,_0x271764,_0x15d80f,_0x50ebea){const _0x5dfcfb=_0x2a4125,_0x3377de=_0x2a4125,_0x36ccbc={'dvBzH':_0x5dfcfb(0x124),'NNVMJ':function(_0x2f3a6e,_0x263254,_0x597f81,_0x4d9fab,_0x3327cf){return _0x2f3a6e(_0x263254,_0x597f81,_0x4d9fab,_0x3327cf);}};return _0x36ccbc[_0x5dfcfb(0xf5)](_0x51da33,this,void 0x0,void 0x0,function*(){const _0x414c00=_0x3377de,_0x12918a=_0x3377de;yield this[_0x414c00(0x109)+'uct'](_0x271764,_0x480334);const _0x2c4a28=yield this[_0x414c00(0xf3)]['product'][_0x12918a(0x12b)]({'where':{'id':_0x271764,'organizationId':_0x480334,'deletedAt':null},'data':{'publishedAt':_0x15d80f===_0x414c00(0x124)?new Date():null,'publishedBy':_0x15d80f===_0x36ccbc[_0x414c00(0xf4)]?_0x50ebea:null,'updatedBy':_0x50ebea},'include':{'translations':!0x0,'images':!0x0,'categories':{'include':{'translations':!0x0}},'modifierGroups':{'include':{'translations':!0x0,'modifiers':!0x0}}}});return _0x418472[_0x414c00(0xf0)](_0x2c4a28);});}[_0x2a4125(0x11c)+_0x2a4125(0xf7)](_0x15c769,_0x1f257d,_0xca55b4){return _0x51da33(this,void 0x0,void 0x0,function*(){const _0x1191cb=_0x1c30,_0x262130=_0x1c30;yield this['findProd'+_0x1191cb(0x103)](_0x1f257d,_0x15c769),yield this[_0x1191cb(0xf3)][_0x1191cb(0xf1)][_0x1191cb(0x12b)]({'where':{'id':_0x1f257d,'organizationId':_0x15c769,'deletedAt':null},'data':{'deletedAt':new Date(),'deletedBy':_0xca55b4}});});}}export{O as ProductService};
|
|
1
|
+
import{__awaiter as l}from"tslib";import{z as m}from"@hono/zod-openapi";import{HttpException as w}from"../../core/exceptions/http-exception";import{flattenTranslationData as f}from"../../core/utils/zod.util";import{LocalizedProductSchema as v,PaginationMetaSchema as h,ProductSchema as p}from"../../schemas";class O{constructor(i){this.prisma=i}findProduct(i,a,t){return l(this,void 0,void 0,function*(){const e=yield this.prisma.product.findUnique({where:{id:i,organizationId:a,deletedAt:null},include:t?.include});if(!e)throw new w(404,"Product not found");return e})}createProduct(i,a,t){return l(this,void 0,void 0,function*(){const e=yield this.prisma.$transaction(d=>l(this,void 0,void 0,function*(){var s,r;const c=yield d.product.create({data:Object.assign(Object.assign({slug:t.slug,sku:t.sku,availableQuantity:t.availableQuantity,basePrice:t.basePrice,discountedBasePrice:t.discountedBasePrice,currency:t.currency,organizationId:i,manufacturerId:t.manufacturerId,createdBy:a,translations:{create:t.translations},images:{connect:(s=t.images)===null||s===void 0?void 0:s.map(n=>({id:n.id}))},modifierGroups:{create:(r=t.modifierGroups)===null||r===void 0?void 0:r.map(n=>({selectMin:n.selectMin,selectMax:n.selectMax,translations:{create:n.translations},modifiers:{create:n.modifiers}}))}},t.categories?{categories:{connect:t.categories.map(n=>({id:n}))}}:void 0),{metadata:t.metadata||{}}),include:{translations:!0,images:!0,categories:{include:{translations:!0}},modifierGroups:{include:{translations:!0,modifiers:!0}}}}),o=yield d.productSnapshot.create({data:{productId:c.id,data:c,createdBy:a}});return yield d.product.update({where:{id:c.id},data:{latestSnapshotId:o.id}}),c}));return p.parse(e)})}getProduct(i,a,t){return l(this,void 0,void 0,function*(){const{locale:e}=t,d=yield this.findProduct(a,i,Object.assign(Object.assign({},t.published&&{publishedAt:{not:null}}),{include:{translations:e?{where:{locale:e}}:!0,images:!0,categories:{include:{translations:e?{where:{locale:e}}:!0}},modifierGroups:{include:{translations:e?{where:{locale:e}}:!0,modifiers:!0}}}}));return e?v.parse(f(d)):p.parse(d)})}getProducts(i,a){return l(this,void 0,void 0,function*(){const{page:t=1,limit:e=10,search:d,locale:s,published:r,categoryId:c,publishedStatus:o}=a,n=r||o==="published"?{publishedAt:{not:null}}:o==="unpublished"?{publishedAt:null}:void 0,[u,g]=yield this.prisma.product.paginate({orderBy:{createdAt:"desc"},where:Object.assign(Object.assign(Object.assign({organizationId:i,deletedAt:null},c&&{categories:{some:{id:c}}}),d&&{translations:{some:{title:{contains:d,mode:"insensitive"}}}}),n??{}),include:{translations:s?{where:{locale:s}}:!0,images:!0,categories:{include:{translations:s?{where:{locale:s}}:!0}},modifierGroups:{include:{translations:s?{where:{locale:s}}:!0,modifiers:!0}}}}).withPages({page:t,limit:e});if(!s)return m.object({meta:h,list:m.array(p)}).parse({meta:g,list:u});const P=u.map(j=>f(j));return m.object({meta:h,list:m.array(v)}).parse({meta:g,list:P})})}getProductsByCategory(i,a,t){return l(this,void 0,void 0,function*(){const{page:e=1,limit:d=10,search:s,locale:r}=t,[c,o]=yield this.prisma.product.paginate({orderBy:{createdAt:"desc"},where:Object.assign({organizationId:i,deletedAt:null,categories:{some:{id:a}}},s&&{translations:{some:{title:{contains:s,mode:"insensitive"}}}}),include:{translations:r?{where:{locale:r}}:!0,images:!0,categories:{include:{translations:r?{where:{locale:r}}:!0}},modifierGroups:{include:{translations:r?{where:{locale:r}}:!0,modifiers:!0}}}}).withPages({page:e,limit:d}),n=r?c.map(u=>p.parse(f(u))):c.map(u=>p.parse(u));return m.object({meta:h,list:m.array(p)}).parse({meta:o,list:n})})}updateProduct(i,a,t,e){return l(this,void 0,void 0,function*(){yield this.findProduct(a,i);const d=yield this.prisma.$transaction(s=>l(this,void 0,void 0,function*(){var r;const c=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},e.slug!==void 0?{slug:e.slug}:{}),e.sku!==void 0?{sku:e.sku}:{}),e.availableQuantity!==void 0?{availableQuantity:e.availableQuantity}:{}),e.basePrice!==void 0?{basePrice:e.basePrice}:{}),e.discountedBasePrice!==void 0?{discountedBasePrice:e.discountedBasePrice}:{}),e.currency!==void 0?{currency:e.currency}:{}),e.manufacturerId!==void 0?{manufacturerId:e.manufacturerId}:{}),{updatedBy:t}),e.translations!==void 0?{translations:{deleteMany:{},create:e.translations}}:{}),e.images!==void 0?{images:{set:e.images.map(u=>({id:u.id}))}}:{}),e.modifierGroups!==void 0?{modifierGroups:{deleteMany:{},create:e.modifierGroups.map(u=>({selectMin:u.selectMin,selectMax:u.selectMax,translations:{create:u.translations},modifiers:{create:u.modifiers}}))}}:{}),e.categories!==void 0?{categories:{set:e.categories.map(u=>({id:u}))}}:{}),e.metadata!==void 0?{metadata:(r=e.metadata)!==null&&r!==void 0?r:{}}:{}),o=yield s.product.update({where:{id:a,organizationId:i,deletedAt:null},data:c,include:{translations:!0,images:!0,categories:{include:{translations:!0}},modifierGroups:{include:{translations:!0,modifiers:!0}}}}),n=yield s.productSnapshot.create({data:{productId:o.id,data:o,createdBy:t}});return yield s.product.update({where:{id:o.id},data:{latestSnapshotId:n.id}}),o}));return p.parse(d)})}updateProductStatus(i,a,t,e){return l(this,void 0,void 0,function*(){yield this.findProduct(a,i);const d=yield this.prisma.product.update({where:{id:a,organizationId:i,deletedAt:null},data:{publishedAt:t==="publish"?new Date:null,publishedBy:t==="publish"?e:null,updatedBy:e},include:{translations:!0,images:!0,categories:{include:{translations:!0}},modifierGroups:{include:{translations:!0,modifiers:!0}}}});return p.parse(d)})}deleteProduct(i,a,t){return l(this,void 0,void 0,function*(){yield this.findProduct(a,i),yield this.prisma.product.update({where:{id:a,organizationId:i,deletedAt:null},data:{deletedAt:new Date,deletedBy:t}})})}}export{O as ProductService};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{__awaiter as n}from"tslib";import{createApiRouter as p}from"../../core/hono/hono";import{productCategoryRoute as u}from"./product-category.route";export const registerProductCategoryHandlers=i=>{const r=p();return r.openapi(u.createProductCategory,t=>n(void 0,void 0,void 0,function*(){const a=t.get("auth"),o=t.req.valid("param"),e=t.req.valid("json"),d=yield a.isGranted("create"),s=yield i.createProductCategory(o.organizationId,d.id,e);return t.json(s,201)})),r.openapi(u.getProductCategory,t=>n(void 0,void 0,void 0,function*(){const a=t.get("auth"),o=t.req.valid("param"),e=t.req.valid("query");yield a.isGranted("read");const d=yield i.getProductCategory(o.organizationId,o.id,{locale:e.locale||null});return t.json(d,200)})),r.openapi(u.getProductCategories,t=>n(void 0,void 0,void 0,function*(){const a=t.req.valid("param"),o=t.req.valid("query"),e=yield i.getProductCategories(a.organizationId,Object.assign(Object.assign({},o),{locale:o.locale||null,published:o.published,publishedStatus:o.publishedStatus}));return t.json(e,200)})),r.openapi(u.updateProductCategory,t=>n(void 0,void 0,void 0,function*(){const a=t.get("auth"),o=t.req.valid("param"),e=t.req.valid("json"),d=yield a.isGranted("update"),s=yield i.updateProductCategory(o.organizationId,o.id,d.id,e);return t.json(s,200)})),r.openapi(u.updateProductCategoryStatus,t=>n(void 0,void 0,void 0,function*(){const a=t.get("auth"),o=t.req.valid("param"),e=yield a.isGranted("update"),d=yield i.updateProductCategoryStatus(o.organizationId,o.id,o.operation,e.id);return t.json(d,200)})),r.openapi(u.deleteProductCategory,t=>n(void 0,void 0,void 0,function*(){const a=t.get("auth"),o=t.req.valid("param"),e=yield a.isGranted("delete");return yield i.deleteProductCategory(o.organizationId,o.id,e.id),t.body(null,204)})),r};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{createApiRoute as o}from"../../core/hono/hono";import{CreateProductCategorySchema as s,ErrorSchema as t,HeaderSchema as a,LocalizedProductCategorySchema as d,OrganizationParams as c,OrganizationWithIdParams as i,PaginationMetaSchema as p,PaginationQuerySchema as u,ProductCategorySchema as r,UpdateProductCategorySchema as n}from"../../schemas";import{GetResourceQuerySchema as g}from"../../schemas/queries.schema";const m=u.extend({publishedStatus:e.enum(["published","unpublished"]).optional().openapi({description:"Filter product categories by publication status",example:"published"})}).openapi("GetProductCategoriesQuery"),h=o({description:"Fetches a paginated list of product categories for a specific organization",headers:a,method:"GET",operationId:"getProductCategories",path:"/:organizationId/product-categories",pathParams:c,query:m,responses:{200:e.object({list:e.array(e.union([r,d])),meta:p}),400:t,401:t},summary:"Get Product Categories",tags:["ProductCategory"]}),y=o({body:s,description:"Creates a new product category for a specific organization",headers:a,method:"POST",operationId:"createProductCategory",path:"/:organizationId/product-categories",pathParams:c,responses:{201:r,400:t,401:t,404:t},summary:"Create Product Category",tags:["ProductCategory"]}),P=o({description:"Fetches a specific product category by ID",headers:a,method:"GET",operationId:"getProductCategory",path:"/:organizationId/product-categories/:id",pathParams:i,query:g,responses:{200:e.union([r,d]),401:t,404:t},summary:"Get Product Category",tags:["ProductCategory"]}),C=o({body:n,description:"Updates a specific product category by ID",headers:a,method:"PATCH",operationId:"updateProductCategory",path:"/:organizationId/product-categories/:id",pathParams:i,responses:{200:r,400:t,401:t,404:t},summary:"Update Product Category",tags:["ProductCategory"]}),l=o({description:"Sets the published status of an existing product category based on the operation (publish or unpublish)",headers:a,method:"POST",operationId:"updateProductCategoryStatus",path:"/:organizationId/product-categories/:id/status/:operation",pathParams:e.object({id:e.string().openapi({description:"The organization ID",example:"ckel0e8qw00004n5p5w6fznym",param:{in:"path",name:"id"}}),operation:e.enum(["publish","unpublish"]).openapi({description:"The operation to perform on the product category",example:"publish",param:{in:"path",name:"operation"}}),organizationId:e.string().openapi({description:"The organization ID",example:"ckel0e8qw00004n5p5w6fznym",param:{in:"path",name:"organizationId"}})}),responses:{200:r,400:t,401:t,404:t},summary:"Publish or Unpublish Product Category",tags:["ProductCategory"]}),b=o({description:"Deletes a specific product category by ID",headers:a,method:"DELETE",operationId:"deleteProductCategory",path:"/:organizationId/product-categories/:id",pathParams:i,responses:{204:null,400:t,401:t,404:t},summary:"Delete Product Category",tags:["ProductCategory"]});export const productCategoryRoute={getProductCategories:h,createProductCategory:y,getProductCategory:P,updateProductCategory:C,updateProductCategoryStatus:l,deleteProductCategory:b};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
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"),LocalizedProductCategorySchema=ProductCategorySchema.omit({translations:!0}).extend({title:e.string().default(""),description:e.string().default("")}).openapi("LocalizedProductCategory"),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"),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");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{__awaiter as o}from"tslib";import{z as u}from"@hono/zod-openapi";import{HttpException as v}from"../../core/exceptions/http-exception";import{flattenTranslationData as g}from"../../core/utils/zod.util";import{LocalizedProductCategorySchema as h,PaginationMetaSchema as y,ProductCategorySchema as d}from"../../schemas";class P{constructor(t){this.prisma=t}findProductCategory(t,i,e){return o(this,void 0,void 0,function*(){const r=yield this.prisma.productCategory.findUnique({where:{id:t,organizationId:i,deletedAt:null},include:e?.include});if(!r)throw new v(404,"Product category not found");return r})}createProductCategory(t,i,e){return o(this,void 0,void 0,function*(){const r=yield this.prisma.productCategory.create({data:{slug:e.slug,organizationId:t,createdBy:i,imageId:e.imageId,translations:{create:e.translations}},include:{translations:!0,image:!0}});return d.parse(r)})}getProductCategory(t,i,e){return o(this,void 0,void 0,function*(){const{locale:r}=e,a=yield this.findProductCategory(i,t,{include:{image:!0,translations:r?{where:{locale:r}}:!0}});return r?h.parse(g(a)):d.parse(a)})}getProductCategories(t,i){return o(this,void 0,void 0,function*(){const{page:e=1,limit:r=10,search:a,locale:n,published:m,publishedStatus:l}=i,s=m||l==="published"?{publishedAt:{not:null}}:l==="unpublished"?{publishedAt:null}:void 0,[c,p]=yield this.prisma.productCategory.paginate({orderBy:{priority:"asc"},where:Object.assign(Object.assign({organizationId:t,deletedAt:null},a&&{slug:{contains:a,mode:"insensitive"}}),s??{}),include:{image:!0,translations:n?{where:{locale:n}}:!0}}).withPages({page:e,limit:r});if(!n)return u.object({meta:y,list:u.array(d)}).parse({meta:p,list:c});const C=c.map(f=>g(f));return u.object({meta:y,list:u.array(h)}).parse({meta:p,list:C})})}updateProductCategory(t,i,e,r){return o(this,void 0,void 0,function*(){yield this.findProductCategory(i,t);const a=yield this.prisma.productCategory.update({where:{id:i,organizationId:t,deletedAt:null},data:{updatedBy:e,slug:r.slug,translations:{deleteMany:{},create:r.translations||[]},imageId:r.imageId},include:{image:!0,translations:!0}});return d.parse(a)})}updateProductCategoryStatus(t,i,e,r){return o(this,void 0,void 0,function*(){yield this.findProductCategory(i,t);const a=yield this.prisma.productCategory.update({where:{id:i,organizationId:t,deletedAt:null},data:{publishedAt:e==="publish"?new Date:null,publishedBy:e==="publish"?r:null,updatedBy:r},include:{image:!0,translations:!0}});return d.parse(a)})}deleteProductCategory(t,i,e){return o(this,void 0,void 0,function*(){yield this.findProductCategory(i,t),yield this.prisma.productCategory.update({where:{id:i,organizationId:t,deletedAt:null},data:{deletedAt:new Date,deletedBy:e}})})}}export{P as ProductCategoryService};
|