@shophost/rest-api 2.0.67 → 2.0.68
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/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 +788 -1
- package/src/core/db/__generated__/client/internal/prismaNamespace.js +1 -1
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js +1 -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.js +1 -1
- package/src/features/organization/organization.handler.js +1 -1
- package/src/features/organization/organization.route.js +1 -1
- package/src/features/organization/organization.schema.js +1 -1
- 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-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.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
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{__awaiter as d}from"tslib";import{createApiRouter as g}from"../../core/hono/hono";import{organizationRoute as s}from"./organization.route";export const registerOrganizationHandlers=r=>{const a=g();return a.openapi(s.getOrganizations,n=>d(void 0,void 0,void 0,function*(){const t=n.get("auth"),o=n.req.valid("query"),i=yield t.getCurrentUser(),e=yield r.getOrganizations(i.id,o);return n.json(e,200)})),a.openapi(s.getOrganization,n=>d(void 0,void 0,void 0,function*(){const t=n.req.valid("param"),o=yield r.getOrganization(t.organizationId);return n.json(o,200)})),a.openapi(s.createOrganization,n=>d(void 0,void 0,void 0,function*(){const t=n.get("auth"),o=n.req.valid("json"),i=yield t.getCurrentUser(),e=yield r.createOrganization(i.id,o);return n.json(e,201)})),a.openapi(s.updateOrganization,n=>d(void 0,void 0,void 0,function*(){const t=n.get("auth"),o=n.req.valid("param"),i=n.req.valid("json"),e=yield t.isGranted("update"),u=yield r.updateOrganization(o.organizationId,e.id,i);return n.json(u,200)})),a.openapi(s.deleteOrganization,n=>d(void 0,void 0,void 0,function*(){const t=n.get("auth"),o=n.req.valid("param"),i=yield t.isGranted("delete");return yield r.deleteOrganization(o.organizationId,i.id),n.body(null,204)})),a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{z as o}from"@hono/zod-openapi";import{createApiRoute as a}from"../../core/hono/hono";import{CreateOrganizationSchema as r,ErrorSchema as i,HeaderSchema as t,OrganizationParams as e,OrganizationSchema as n,PaginationMetaSchema as s,PaginationQuerySchema as g,UpdateOrganizationSchema as z}from"../../schemas";const p=a({description:"Fetches a paginated list of organizations",headers:t,method:"GET",operationId:"getOrganizations",path:"/organizations",query:g,responses:{200:o.object({list:o.array(n),meta:s})},summary:"Get Organizations",tags:["Organization"]}),d=a({description:"Fetches a specific organization by ID",headers:t,method:"GET",operationId:"getOrganization",path:"/organizations/:organizationId",pathParams:e,responses:{200:n,404:i},summary:"Get Organization",tags:["Organization"]}),m=a({body:r,description:"Creates a new organization",headers:t,method:"POST",operationId:"createOrganization",path:"/organizations",responses:{201:n,400:i},summary:"Create Organization",tags:["Organization"]}),c=a({body:z,description:"Updates a specific organization by ID",headers:t,method:"PATCH",operationId:"updateOrganization",path:"/organizations/:organizationId",pathParams:e,responses:{200:n,404:i},summary:"Update Organization",tags:["Organization"]}),O=a({description:"Deletes a specific organization by ID",headers:t,method:"DELETE",operationId:"deleteOrganization",path:"/organizations/:organizationId",pathParams:e,responses:{204:null,404:i},summary:"Delete Organization",tags:["Organization"]});export const organizationRoute={getOrganizations:p,getOrganization:d,createOrganization:m,updateOrganization:c,deleteOrganization:O};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";import{AddressSchema as i,CreateAddressSchema as a,UpdateAddressSchema as o}from"../../schemas/address.schema";import{FileSchema as n}from"../file/file.schema";import{OrganizationConfigurationSchema as t,UpdateOrganizationConfigurationSchema as r}from"./organization-configuration.schema";export const OrganizationSchema=e.object({id:e.string().openapi({example:"clm1234567890abcdef",description:"The unique identifier of the organization"}),name:e.string().openapi({example:"Acme Store",description:"The name of the organization"}),phone:e.string().min(1,"Phone number is required").openapi({example:"+48123456890",description:"The phone number of the organization"}),email:e.string().email().optional().openapi({example:"john.doe@example.com",description:"The email address of the organization"}),createdAt:e.date().openapi({example:"2022-01-01T00:00:00.000Z",description:"The date and time the organization was created"}),legalEntityId:e.string().nullable().openapi({example:"clm1234567890abcdef",description:"The unique identifier of the legal entity associated with the organization"}),address:i,configuration:t.openapi({description:"The configuration settings for the organization"}),logo:e.string().url().optional().nullable().openapi({example:"https://example.com/logo.jpg",description:"The logo of the organization"}),logoFile:n.optional().nullable().openapi({description:"The logo of the organization"})}).openapi("Organization"),CreateOrganizationSchema=OrganizationSchema.pick({name:!0,phone:!0,email:!0,logoFile:!0}).extend({logoId:e.string().optional().nullable().openapi({example:"clm1234567890abcdef",description:"The unique identifier of the thumbnail image associated with the organization"}),address:a}).openapi("CreateOrganization"),UpdateOrganizationSchema=CreateOrganizationSchema.extend({address:o,configuration:r}).partial().openapi("UpdateOrganization");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const _0x431135=_0x4dd9,_0x356f33=_0x4dd9;function _0x4621(){const _0x120268=['y29UzMLNDxi','BwfW','Aw5Nt3jKzxi','B1rPBwvtDhi','C1nOAxbWAw4','mJyZnKn2v3zLEq','zw5HyMXLsg8','B3bLBMLUz1q','Dgvty2HLzhu','z2v0ugXHy2u','DgH1CNnKyxK','D2L0AfbHz2u','Bgf0Axr1zgu','C3ruCMfJA2K','BgvuB1rPBwu','DhvLC2rHEq','yxrPB24','zgvZyW','ntqWode1EhPgAufK','ve1Lq1i','BgXPC2vJB24','Aw5N','r29Vz2XLie0','mteYnJy0v3bTDxHm','DgLVBG','DxbKyxrLt3i','Aw1LCW','CMvKDwnL','yxjYyxK','zw1HAwW','ywrKCMvZCW','mI1KAwDPDa','rxvYB3bLl1C','otm0mJa5zKrqwfbn','y3jLyxrLt3i','zNjPzgf5','rgv0ywLSCW','Dg9mB2nHBgu','CgfNAw5HDgu','C2f0DxjKyxK','A2v5igLZihi','CgXHy2vjza','yxnZAwDU','y2XVC2LUz1q','u3rYAw5N','rgf0zvn0CMK','DxbKyxrL','mtj5EfL5yNm','zxf1AxjLza','nZGZCwnSqNPJ','Axnby2nLChq','C3vUzgf5','zMLUzfvUAxe','BMfTzq','mtuXmtC0ogntAuDLra','zgvMyxvSDem','CMvXDwLYzuW','C2v0vvrdsg8','DMf0Aw9UCW','B2nHDgLVBLm','vgLTzvn0CMK','DgLVBIbUB3q','Bg9Uz2L0Dwq','z2fUAxPHDgK','mtbPvgH0twS','yunJAva','ALngyLi','AxPHDgLVBG','C3rdAgvJA28','zM9YBwf0rge','y29UDMvYDfq','Dg9mB3DLCKm','z2v0t3jNyw4','B3DUzxi','CgHVBMu','BNv0zxm','y291BNrYAwu','Bg9JyxrPB24','DxjYzw5JEq','vvrd','t3jNyw5PEMe','B3jNyw5PEMe','zgvSzxrLt3i','Bg9NB0LK','Aw5NuMvZzxi','u2vYDMLJzq','y29Uzhm','igzVDw5K','mJeXodiWmfLHyKTjtW','yxnL','zw4Tvvm','y3jLyxrL','zxj2AwnL','ChjPC21H','C3bSAxq','CgfYC2u','yxjZyxC','zgvMyxvSDeW','mJi5odi0qMPKsKDu','Bw9Uzgf5','D2vKBMvZzge'];_0x4621=function(){return _0x120268;};return _0x4621();}(function(_0x14828a,_0x5ceb57){const _0x550e38=_0x4dd9,_0x23c3ef=_0x4dd9,_0x2ba2cf=_0x14828a();while(!![]){try{const _0x489b4d=parseInt(_0x550e38(0x1c5))/0x1+parseInt(_0x23c3ef(0x1b3))/0x2*(parseInt(_0x550e38(0x1df))/0x3)+-parseInt(_0x550e38(0x1dd))/0x4*(parseInt(_0x23c3ef(0x1c0))/0x5)+parseInt(_0x23c3ef(0x1e4))/0x6+-parseInt(_0x550e38(0x1ab))/0x7+-parseInt(_0x23c3ef(0x1a1))/0x8+parseInt(_0x23c3ef(0x1cf))/0x9*(parseInt(_0x23c3ef(0x1ee))/0xa);if(_0x489b4d===_0x5ceb57)break;else _0x2ba2cf['push'](_0x2ba2cf['shift']());}catch(_0x5b3d5c){_0x2ba2cf['push'](_0x2ba2cf['shift']());}}}(_0x4621,0x2e775));import{__awaiter as _0x3bb9cc}from'tslib';import{z as _0x29a6a}from'@hono/zod-openapi';function _0x4dd9(_0x36dd76,_0x33a131){_0x36dd76=_0x36dd76-0x19e;const _0x46214b=_0x4621();let _0x4dd92f=_0x46214b[_0x36dd76];if(_0x4dd9['XfCCsR']===undefined){var _0x6fc762=function(_0x5d1cc4){const _0x367dcb='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0xa10245='',_0x434f64='';for(let _0x181479=0x0,_0x5d009a,_0x150b86,_0x42999f=0x0;_0x150b86=_0x5d1cc4['charAt'](_0x42999f++);~_0x150b86&&(_0x5d009a=_0x181479%0x4?_0x5d009a*0x40+_0x150b86:_0x150b86,_0x181479++%0x4)?_0xa10245+=String['fromCharCode'](0xff&_0x5d009a>>(-0x2*_0x181479&0x6)):0x0){_0x150b86=_0x367dcb['indexOf'](_0x150b86);}for(let _0x149387=0x0,_0x48c049=_0xa10245['length'];_0x149387<_0x48c049;_0x149387++){_0x434f64+='%'+('00'+_0xa10245['charCodeAt'](_0x149387)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x434f64);};_0x4dd9['toOSkF']=_0x6fc762,_0x4dd9['uOQwDt']={},_0x4dd9['XfCCsR']=!![];}const _0x1314aa=_0x46214b[0x0],_0x21cadf=_0x36dd76+_0x1314aa,_0x2fbeae=_0x4dd9['uOQwDt'][_0x21cadf];return!_0x2fbeae?(_0x4dd92f=_0x4dd9['toOSkF'](_0x4dd92f),_0x4dd9['uOQwDt'][_0x21cadf]=_0x4dd92f):_0x4dd92f=_0x2fbeae,_0x4dd92f;}import{HttpException as _0x4bb76c}from'../../core/exceptions/http-exception';import{OrganizationSchema as _0x2bb98c,PaginationMetaSchema as _0xc7c631}from'../../schemas';class S{constructor(_0x451f4f,_0x1f6b90){const _0x5b4b1f=_0x4dd9,_0x5f3756=_0x4dd9;this[_0x5b4b1f(0x1a6)]=_0x451f4f,this[_0x5f3756(0x1fb)+_0x5b4b1f(0x19e)]=_0x1f6b90,this['convertT'+_0x5f3756(0x1b1)+_0x5f3756(0x1c3)]=_0x325dde=>_0x325dde?_0x325dde[_0x5f3756(0x1d3)+'TimeStri'+'ng']('en-US',{'hour':_0x5b4b1f(0x1cd),'minute':_0x5b4b1f(0x1cd),'hour12':!0x1,'timeZone':_0x5f3756(0x1fd)}):'';}['requireL'+_0x431135(0x1e9)+_0x431135(0x1a5)](){const _0x5e31a2=_0x431135,_0x2a610a=_0x431135;if(!this[_0x5e31a2(0x1fb)+_0x5e31a2(0x19e)])throw new Error(_0x5e31a2(0x1c4)+'aps\x20API\x20'+_0x2a610a(0x1d6)+_0x5e31a2(0x1de));return this[_0x2a610a(0x1fb)+_0x2a610a(0x19e)];}[_0x356f33(0x1f6)+'izations'](_0x3376d0,_0x2c5df7){return _0x3bb9cc(this,void 0x0,void 0x0,function*(){const _0x5adf0b=_0x4dd9,_0x186afd=_0x4dd9,{page:_0x4479f9,limit:_0x493737}=_0x2c5df7,[_0x34bf1f,_0x5b3237]=yield this[_0x5adf0b(0x1a6)][_0x186afd(0x1ff)+_0x5adf0b(0x1c6)][_0x5adf0b(0x1d4)]({'orderBy':{'createdAt':_0x5adf0b(0x1bf)},'where':{'members':{'some':{'userId':_0x3376d0}}},'include':{'address':!0x0,'configuration':!0x0,'logoFile':!0x0}})[_0x186afd(0x1b9)+'s']({'page':_0x4479f9,'limit':_0x493737});return{'meta':_0xc7c631[_0x186afd(0x1a8)](_0x5b3237),'list':_0x29a6a[_0x186afd(0x1ca)](_0x2bb98c)[_0x186afd(0x1a8)](_0x34bf1f)};});}[_0x431135(0x1f3)+'teSchedu'+_0x356f33(0x1bc)+_0x431135(0x1da)](_0x1403ac){const _0x1a21d1=_0x431135,_0x7c4aaf=_0x431135,_0x4348c8={'aCciP':'wednesda'+'y','TMeCR':_0x1a21d1(0x1b8)};return _0x1403ac?[_0x1a21d1(0x1ac),_0x7c4aaf(0x1bd),_0x4348c8[_0x7c4aaf(0x1ef)],_0x4348c8[_0x1a21d1(0x1c1)],_0x7c4aaf(0x1d1),_0x7c4aaf(0x1d5),_0x1a21d1(0x1e1)][_0x7c4aaf(0x1c9)]((_0x54f669,_0x404185)=>(_0x54f669[_0x404185]=this[_0x7c4aaf(0x1f4)+_0x1a21d1(0x1b1)+_0x7c4aaf(0x1c3)](_0x1403ac[_0x404185]),_0x54f669),{}):null;}[_0x356f33(0x1f6)+_0x356f33(0x1f1)](_0x900c96){return _0x3bb9cc(this,void 0x0,void 0x0,function*(){const _0x37fba1=_0x4dd9,_0xe3b7ed=_0x4dd9;var _0xfa7ea,_0x3105f4;const _0x229296=yield this['prisma'][_0x37fba1(0x1ff)+_0x37fba1(0x1c6)][_0x37fba1(0x1e2)+'ue']({'where':{'id':_0x900c96,'deletedAt':null},'include':{'address':!0x0,'configuration':{'include':{'openingTimes':!0x0,'closingTimes':!0x0}},'logoFile':!0x0}});if(!_0x229296)throw new _0x4bb76c(0x194,'Organiza'+_0x37fba1(0x1eb)+'\x20found');const _0x1c4c8d=((()=>{const _0x1f0cda=_0x37fba1,_0x3053d5=_0x37fba1;if(!_0x229296[_0x1f0cda(0x1ae)+_0x1f0cda(0x1be)][_0x1f0cda(0x1e0)+_0x3053d5(0x1b0)+'s']||!_0x229296[_0x3053d5(0x1ae)+_0x1f0cda(0x1be)]['openingT'+_0x1f0cda(0x1c8)]||!_0x229296[_0x3053d5(0x1ae)+_0x3053d5(0x1be)][_0x1f0cda(0x1d9)+_0x1f0cda(0x1c8)])return!0x1;const _0x1f5ebb=new Date(new Date()['toLocale'+'String'](_0x1f0cda(0x1a3),{'timeZone':'Europe/W'+'arsaw'})),_0x12900c=_0x1f5ebb[_0x1f0cda(0x1d3)+_0x3053d5(0x1db)+'ng'](_0x1f0cda(0x1a3),{'weekday':'long'})[_0x1f0cda(0x1f5)+_0x1f0cda(0x1a2)](),_0x218058=_0x1f5ebb[_0x3053d5(0x1d3)+_0x3053d5(0x1ea)+'ng'](_0x1f0cda(0x1a3),{'hour':_0x1f0cda(0x1cd),'minute':_0x1f0cda(0x1cd),'hour12':!0x1,'timeZone':_0x1f0cda(0x1ce)+_0x1f0cda(0x1a9)}),_0x5b5624=_0x229296[_0x3053d5(0x1ae)+_0x3053d5(0x1be)][_0x3053d5(0x1b5)+_0x3053d5(0x1c8)][_0x12900c],_0x34dede=_0x229296[_0x1f0cda(0x1ae)+_0x3053d5(0x1be)][_0x1f0cda(0x1d9)+_0x3053d5(0x1c8)][_0x12900c];if(!_0x5b5624||!_0x34dede)return!0x1;const _0x3db2cc=this[_0x3053d5(0x1f4)+_0x1f0cda(0x1b1)+_0x3053d5(0x1c3)](_0x5b5624),_0x21abea=this[_0x1f0cda(0x1f4)+_0x1f0cda(0x1b1)+'ing'](_0x34dede);return _0x218058>=_0x3db2cc&&_0x218058<=_0x21abea;})());return _0x2bb98c[_0xe3b7ed(0x1a8)](Object[_0x37fba1(0x1d8)](Object[_0x37fba1(0x1d8)]({},_0x229296),{'configuration':Object[_0xe3b7ed(0x1d8)](Object[_0x37fba1(0x1d8)]({},_0x229296['configur'+_0xe3b7ed(0x1be)]),{'isOpen':_0x1c4c8d,'openingTimes':(_0xfa7ea=this[_0x37fba1(0x1f3)+_0xe3b7ed(0x1b6)+_0xe3b7ed(0x1bc)+_0x37fba1(0x1da)](_0x229296['configur'+_0xe3b7ed(0x1be)][_0x37fba1(0x1b5)+'imes']))!==null&&_0xfa7ea!==void 0x0?_0xfa7ea:void 0x0,'closingTimes':(_0x3105f4=this[_0xe3b7ed(0x1f3)+'teSchedu'+_0xe3b7ed(0x1bc)+'String'](_0x229296['configur'+'ation'][_0x37fba1(0x1d9)+_0xe3b7ed(0x1c8)]))!==null&&_0x3105f4!==void 0x0?_0x3105f4:void 0x0})}));});}[_0x431135(0x1d0)+_0x431135(0x1ed)+'on'](_0x1aae94,_0xabd98a){const _0x3c4023=_0x356f33,_0x3f318f={'VhVXj':_0x3c4023(0x1f7)};return _0x3bb9cc(this,void 0x0,void 0x0,function*(){const _0x4b5b99=_0x3c4023,_0x4b5674=_0x3c4023;var _0x52a7cb,_0xb86f60;const _0x41ffbb=yield this[_0x4b5b99(0x1e6)+_0x4b5b99(0x1e9)+_0x4b5674(0x1a5)]()['getPlace'+_0x4b5674(0x1d2)](_0xabd98a[_0x4b5674(0x1cc)][_0x4b5674(0x1d7)]),_0x5b52b1=yield this[_0x4b5674(0x1a6)][_0x4b5674(0x1ff)+_0x4b5b99(0x1c6)][_0x4b5b99(0x1a4)]({'data':Object[_0x4b5674(0x1d8)]({'name':_0xabd98a[_0x4b5674(0x1e3)],'phone':_0xabd98a[_0x4b5b99(0x1f8)],'email':_0xabd98a[_0x4b5b99(0x1cb)],'address':{'create':Object[_0x4b5674(0x1d8)](Object[_0x4b5b99(0x1d8)]({},_0xabd98a[_0x4b5b99(0x1cc)]),{'latitude':_0x41ffbb['latitude'],'longitude':_0x41ffbb[_0x4b5b99(0x1ec)+'e'],'createdBy':_0x1aae94})},'configuration':{'create':{'countriesShipping':['us'],'createdBy':_0x1aae94,'enableHostCheckout':!0x1,'enableHostTracking':!0x1,'isAcceptingReservations':!0x1,'openingTimes':{'create':{'monday':null,'tuesday':null,'wednesday':null,'thursday':null,'friday':null,'saturday':null,'sunday':null}},'closingTimes':{'create':{'monday':null,'tuesday':null,'wednesday':null,'thursday':null,'friday':null,'saturday':null}}}},'members':{'create':{'user':{'connect':{'id':_0x1aae94}},'role':_0x3f318f['VhVXj']}},'createdBy':_0x1aae94},_0xabd98a[_0x4b5b99(0x201)]?{'logoFile':{'connect':{'id':_0xabd98a[_0x4b5674(0x201)]}}}:{}),'include':{'address':!0x0,'configuration':{'include':{'openingTimes':!0x0,'closingTimes':!0x0}},'logoFile':!0x0}});return _0x2bb98c[_0x4b5b99(0x1a8)](Object[_0x4b5674(0x1d8)](Object[_0x4b5b99(0x1d8)]({},_0x5b52b1),{'configuration':Object[_0x4b5674(0x1d8)](Object[_0x4b5b99(0x1d8)]({},_0x5b52b1[_0x4b5b99(0x1ae)+_0x4b5674(0x1be)]),{'openingTimes':(_0x52a7cb=this[_0x4b5674(0x1f3)+'teSchedu'+'leToTime'+_0x4b5674(0x1da)](_0x5b52b1[_0x4b5674(0x1ae)+_0x4b5674(0x1be)][_0x4b5b99(0x1b5)+_0x4b5b99(0x1c8)]))!==null&&_0x52a7cb!==void 0x0?_0x52a7cb:void 0x0,'closingTimes':(_0xb86f60=this['formatDa'+_0x4b5674(0x1b6)+_0x4b5b99(0x1bc)+_0x4b5674(0x1da)](_0x5b52b1[_0x4b5674(0x1ae)+_0x4b5674(0x1be)][_0x4b5b99(0x1d9)+'imes']))!==null&&_0xb86f60!==void 0x0?_0xb86f60:void 0x0})}));});}[_0x356f33(0x1c7)+_0x431135(0x1ed)+'on'](_0x2a13c6,_0x2ee401,_0x596e22){const _0x5d19c8={'lSirA':function(_0x360941,_0x15aedd){return _0x360941(_0x15aedd);},'jSFbR':function(_0x23b93d,_0x105d89){return _0x23b93d!==_0x105d89;}};return _0x3bb9cc(this,void 0x0,void 0x0,function*(){const _0x5a1723=_0x4dd9,_0x20f6c6=_0x4dd9;var _0x1d8dd6,_0x37ec30;if(!(yield this[_0x5a1723(0x1a6)][_0x5a1723(0x1ff)+_0x20f6c6(0x1c6)][_0x20f6c6(0x1e2)+'ue']({'where':{'id':_0x2a13c6,'deletedAt':null}})))throw new _0x4bb76c(0x194,_0x5a1723(0x1fe)+'tion\x20not'+_0x20f6c6(0x1a0));const _0x350a10=_0x596e22[_0x20f6c6(0x1cc)]?yield this[_0x5a1723(0x1e6)+'ocationS'+_0x5a1723(0x1a5)]()[_0x5a1723(0x1b7)+_0x20f6c6(0x1d2)](_0x596e22[_0x5a1723(0x1cc)][_0x5a1723(0x1d7)]):void 0x0,_0x58ce53=_0x53cc9f=>{const _0x41eb72=_0x5a1723,_0x37d5eb=_0x5a1723;if(!_0x53cc9f)return null;const [_0x49a83e,_0x91f8b7]=_0x53cc9f[_0x41eb72(0x1a7)](':')[_0x41eb72(0x1af)](Number),_0x49c379=new Date();return _0x49c379[_0x37d5eb(0x1e7)+'urs'](_0x49a83e),_0x49c379['setUTCMi'+_0x37d5eb(0x1f9)](_0x91f8b7),_0x49c379['setUTCSe'+_0x41eb72(0x19f)](0x0),_0x49c379['setUTCMi'+_0x41eb72(0x1c2)+'ds'](0x0),_0x49c379;},_0x172aa2=yield this[_0x5a1723(0x1a6)][_0x5a1723(0x1ff)+_0x5a1723(0x1c6)][_0x20f6c6(0x1dc)]({'where':{'id':_0x2a13c6},'data':Object[_0x5a1723(0x1d8)](Object[_0x20f6c6(0x1d8)](Object[_0x5a1723(0x1d8)](Object[_0x5a1723(0x1d8)]({'name':_0x596e22[_0x20f6c6(0x1e3)],'phone':_0x596e22[_0x5a1723(0x1f8)],'email':_0x596e22[_0x20f6c6(0x1cb)]},_0x596e22[_0x20f6c6(0x201)]?{'logoFile':{'connect':{'id':_0x596e22[_0x5a1723(0x201)]}}}:{}),{'address':_0x596e22[_0x20f6c6(0x1cc)]?{'update':Object[_0x20f6c6(0x1d8)](Object[_0x5a1723(0x1d8)]({},_0x596e22[_0x5a1723(0x1cc)]),{'latitude':_0x350a10[_0x5a1723(0x1ba)],'longitude':_0x350a10['longitud'+'e'],'updatedBy':_0x2ee401})}:void 0x0}),_0x596e22[_0x5a1723(0x1ae)+_0x20f6c6(0x1be)]?{'configuration':{'update':{'countriesShipping':_0x596e22[_0x5a1723(0x1ae)+'ation'][_0x5a1723(0x1fa)+_0x5a1723(0x1b2)+'g'],'enableHostCheckout':_0x596e22[_0x5a1723(0x1ae)+_0x5a1723(0x1be)][_0x20f6c6(0x1b4)+_0x5a1723(0x1f2)+'ut'],'enableHostTracking':_0x596e22[_0x20f6c6(0x1ae)+_0x5a1723(0x1be)]['enableHo'+_0x5a1723(0x1bb)+'ng'],'defaultLocale':_0x596e22[_0x5a1723(0x1ae)+_0x5a1723(0x1be)][_0x5a1723(0x1aa)+'ocale'],'supportedLocales':_0x596e22[_0x5a1723(0x1ae)+_0x20f6c6(0x1be)]['supporte'+'dLocales'],'defaultCurrency':_0x596e22[_0x5a1723(0x1ae)+_0x20f6c6(0x1be)][_0x20f6c6(0x1e5)+_0x20f6c6(0x1fc)],'updatedBy':_0x2ee401,'isAcceptingOrders':_0x596e22[_0x20f6c6(0x1ae)+_0x20f6c6(0x1be)][_0x5a1723(0x1e0)+'ingOrder'+'s'],'isAcceptingReservations':_0x596e22[_0x20f6c6(0x1ae)+_0x20f6c6(0x1be)][_0x5a1723(0x1e0)+_0x20f6c6(0x202)+_0x5a1723(0x1e8)],'openingTimes':_0x596e22[_0x5a1723(0x1ae)+_0x20f6c6(0x1be)][_0x20f6c6(0x1b5)+_0x20f6c6(0x1c8)]?{'update':{'data':{'monday':_0x596e22[_0x20f6c6(0x1ae)+_0x5a1723(0x1be)][_0x20f6c6(0x1b5)+_0x5a1723(0x1c8)][_0x20f6c6(0x1ac)]?_0x58ce53(_0x596e22['configur'+_0x5a1723(0x1be)][_0x20f6c6(0x1b5)+_0x20f6c6(0x1c8)][_0x20f6c6(0x1ac)]):null,'tuesday':_0x596e22['configur'+_0x20f6c6(0x1be)]['openingT'+_0x5a1723(0x1c8)][_0x5a1723(0x1bd)]?_0x58ce53(_0x596e22[_0x5a1723(0x1ae)+_0x20f6c6(0x1be)][_0x20f6c6(0x1b5)+'imes']['tuesday']):null,'wednesday':_0x596e22['configur'+_0x20f6c6(0x1be)][_0x5a1723(0x1b5)+_0x20f6c6(0x1c8)][_0x5a1723(0x1ad)+'y']?_0x5d19c8['lSirA'](_0x58ce53,_0x596e22[_0x5a1723(0x1ae)+_0x20f6c6(0x1be)][_0x5a1723(0x1b5)+_0x5a1723(0x1c8)][_0x20f6c6(0x1ad)+'y']):null,'thursday':_0x596e22[_0x5a1723(0x1ae)+_0x20f6c6(0x1be)][_0x20f6c6(0x1b5)+_0x5a1723(0x1c8)][_0x20f6c6(0x1b8)]?_0x58ce53(_0x596e22[_0x5a1723(0x1ae)+_0x5a1723(0x1be)][_0x5a1723(0x1b5)+_0x20f6c6(0x1c8)][_0x5a1723(0x1b8)]):null,'friday':_0x596e22[_0x5a1723(0x1ae)+_0x5a1723(0x1be)][_0x20f6c6(0x1b5)+_0x5a1723(0x1c8)][_0x5a1723(0x1d1)]?_0x58ce53(_0x596e22[_0x20f6c6(0x1ae)+_0x5a1723(0x1be)]['openingT'+_0x20f6c6(0x1c8)][_0x5a1723(0x1d1)]):null,'saturday':_0x596e22[_0x5a1723(0x1ae)+'ation'][_0x20f6c6(0x1b5)+'imes'][_0x20f6c6(0x1d5)]?_0x58ce53(_0x596e22[_0x5a1723(0x1ae)+_0x5a1723(0x1be)][_0x5a1723(0x1b5)+_0x5a1723(0x1c8)]['saturday']):null,'sunday':_0x596e22[_0x20f6c6(0x1ae)+_0x20f6c6(0x1be)][_0x5a1723(0x1b5)+_0x5a1723(0x1c8)][_0x5a1723(0x1e1)]?_0x58ce53(_0x596e22['configur'+'ation'][_0x20f6c6(0x1b5)+_0x5a1723(0x1c8)][_0x20f6c6(0x1e1)]):null}}}:void 0x0,'closingTimes':_0x596e22[_0x5a1723(0x1ae)+_0x5a1723(0x1be)][_0x5a1723(0x1d9)+_0x5a1723(0x1c8)]?{'update':{'data':{'monday':_0x596e22[_0x5a1723(0x1ae)+'ation'][_0x5a1723(0x1d9)+_0x20f6c6(0x1c8)][_0x20f6c6(0x1ac)]?_0x58ce53(_0x596e22[_0x20f6c6(0x1ae)+_0x20f6c6(0x1be)][_0x5a1723(0x1d9)+_0x20f6c6(0x1c8)][_0x5a1723(0x1ac)]):null,'tuesday':_0x596e22['configur'+'ation'][_0x20f6c6(0x1d9)+_0x5a1723(0x1c8)][_0x20f6c6(0x1bd)]?_0x58ce53(_0x596e22[_0x20f6c6(0x1ae)+_0x20f6c6(0x1be)][_0x5a1723(0x1d9)+_0x20f6c6(0x1c8)][_0x20f6c6(0x1bd)]):null,'wednesday':_0x596e22[_0x5a1723(0x1ae)+_0x5a1723(0x1be)][_0x5a1723(0x1d9)+_0x5a1723(0x1c8)][_0x5a1723(0x1ad)+'y']?_0x58ce53(_0x596e22[_0x5a1723(0x1ae)+_0x20f6c6(0x1be)][_0x5a1723(0x1d9)+'imes'][_0x20f6c6(0x1ad)+'y']):null,'thursday':_0x596e22[_0x20f6c6(0x1ae)+_0x5a1723(0x1be)]['closingT'+_0x5a1723(0x1c8)][_0x20f6c6(0x1b8)]?_0x58ce53(_0x596e22[_0x5a1723(0x1ae)+_0x20f6c6(0x1be)]['closingT'+_0x5a1723(0x1c8)][_0x20f6c6(0x1b8)]):null,'friday':_0x596e22[_0x20f6c6(0x1ae)+_0x20f6c6(0x1be)][_0x20f6c6(0x1d9)+_0x20f6c6(0x1c8)][_0x20f6c6(0x1d1)]?_0x58ce53(_0x596e22[_0x5a1723(0x1ae)+_0x5a1723(0x1be)][_0x5a1723(0x1d9)+_0x5a1723(0x1c8)][_0x5a1723(0x1d1)]):null,'saturday':_0x596e22[_0x5a1723(0x1ae)+_0x5a1723(0x1be)][_0x20f6c6(0x1d9)+_0x5a1723(0x1c8)][_0x5a1723(0x1d5)]?_0x58ce53(_0x596e22[_0x5a1723(0x1ae)+_0x5a1723(0x1be)][_0x5a1723(0x1d9)+_0x5a1723(0x1c8)][_0x20f6c6(0x1d5)]):null,'sunday':_0x596e22[_0x20f6c6(0x1ae)+_0x5a1723(0x1be)][_0x5a1723(0x1d9)+_0x20f6c6(0x1c8)]['sunday']?_0x58ce53(_0x596e22['configur'+_0x20f6c6(0x1be)][_0x5a1723(0x1d9)+'imes']['sunday']):null}}}:void 0x0}}}:void 0x0),{'updatedBy':_0x2ee401}),'include':{'address':!0x0,'logoFile':!0x0,'configuration':{'include':{'openingTimes':!0x0,'closingTimes':!0x0}}}});return _0x2bb98c[_0x20f6c6(0x1a8)](Object[_0x20f6c6(0x1d8)](Object['assign']({},_0x172aa2),{'configuration':Object[_0x20f6c6(0x1d8)](Object[_0x5a1723(0x1d8)]({},_0x172aa2[_0x20f6c6(0x1ae)+_0x5a1723(0x1be)]),{'openingTimes':(_0x1d8dd6=this[_0x20f6c6(0x1f3)+_0x5a1723(0x1b6)+_0x5a1723(0x1bc)+_0x5a1723(0x1da)](_0x172aa2['configur'+'ation']['openingT'+'imes']))!==null&&_0x1d8dd6!==void 0x0?_0x1d8dd6:void 0x0,'closingTimes':(_0x37ec30=this[_0x5a1723(0x1f3)+'teSchedu'+_0x20f6c6(0x1bc)+_0x20f6c6(0x1da)](_0x172aa2[_0x5a1723(0x1ae)+_0x5a1723(0x1be)][_0x20f6c6(0x1d9)+_0x5a1723(0x1c8)]))!==null&&_0x5d19c8[_0x20f6c6(0x1f0)](_0x37ec30,void 0x0)?_0x37ec30:void 0x0})}));});}[_0x431135(0x200)+'ganizati'+'on'](_0xbfe5b5,_0x2757ef){return _0x3bb9cc(this,void 0x0,void 0x0,function*(){const _0x68b8b3=_0x4dd9,_0x5a5fb4=_0x4dd9;if(!(yield this[_0x68b8b3(0x1a6)][_0x5a5fb4(0x1ff)+_0x5a5fb4(0x1c6)][_0x68b8b3(0x1e2)+'ue']({'where':{'id':_0xbfe5b5}})))throw new _0x4bb76c(0x194,_0x5a5fb4(0x1fe)+_0x68b8b3(0x1eb)+'\x20found');yield this[_0x5a5fb4(0x1a6)][_0x68b8b3(0x1ff)+_0x68b8b3(0x1c6)]['update']({'where':{'id':_0xbfe5b5},'data':{'deletedAt':new Date(),'deletedBy':_0x2757ef}});});}}export{S as OrganizationService};
|
|
1
|
+
import{__awaiter as l}from"tslib";import{z as p}from"@hono/zod-openapi";import{HttpException as T}from"../../core/exceptions/http-exception";import{OrganizationSchema as d,PaginationMetaSchema as h}from"../../schemas";class S{constructor(t,e){this.prisma=t,this.locationService=e,this.convertToTimeString=i=>i?i.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:!1,timeZone:"UTC"}):""}requireLocationService(){if(!this.locationService)throw new Error("Google Maps API key is required");return this.locationService}getOrganizations(t,e){return l(this,void 0,void 0,function*(){const{page:i,limit:n}=e,[o,s]=yield this.prisma.organization.paginate({orderBy:{createdAt:"desc"},where:{members:{some:{userId:t}}},include:{address:!0,configuration:!0,logoFile:!0}}).withPages({page:i,limit:n});return{meta:h.parse(s),list:p.array(d).parse(o)}})}formatDateScheduleToTimeString(t){return t?["monday","tuesday","wednesday","thursday","friday","saturday","sunday"].reduce((i,n)=>(i[n]=this.convertToTimeString(t[n]),i),{}):null}getOrganization(t){return l(this,void 0,void 0,function*(){var e,i;const n=yield this.prisma.organization.findUnique({where:{id:t,deletedAt:null},include:{address:!0,configuration:{include:{openingTimes:!0,closingTimes:!0}},logoFile:!0}});if(!n)throw new T(404,"Organization not found");const o=(()=>{if(!n.configuration.isAcceptingOrders||!n.configuration.openingTimes||!n.configuration.closingTimes)return!1;const s=new Date(new Date().toLocaleString("en-US",{timeZone:"Europe/Warsaw"})),u=s.toLocaleDateString("en-US",{weekday:"long"}).toLowerCase(),a=s.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:!1,timeZone:"Europe/Warsaw"}),r=n.configuration.openingTimes[u],c=n.configuration.closingTimes[u];if(!r||!c)return!1;const m=this.convertToTimeString(r),f=this.convertToTimeString(c);return a>=m&&a<=f})();return d.parse(Object.assign(Object.assign({},n),{configuration:Object.assign(Object.assign({},n.configuration),{isOpen:o,openingTimes:(e=this.formatDateScheduleToTimeString(n.configuration.openingTimes))!==null&&e!==void 0?e:void 0,closingTimes:(i=this.formatDateScheduleToTimeString(n.configuration.closingTimes))!==null&&i!==void 0?i:void 0})}))})}createOrganization(t,e){return l(this,void 0,void 0,function*(){var i,n;const o=yield this.requireLocationService().getPlaceDetails(e.address.placeId),s=yield this.prisma.organization.create({data:Object.assign({name:e.name,phone:e.phone,email:e.email,address:{create:Object.assign(Object.assign({},e.address),{latitude:o.latitude,longitude:o.longitude,createdBy:t})},configuration:{create:{countriesShipping:["us"],createdBy:t,enableHostCheckout:!1,enableHostTracking:!1,isAcceptingReservations:!1,openingTimes:{create:{monday:null,tuesday:null,wednesday:null,thursday:null,friday:null,saturday:null,sunday:null}},closingTimes:{create:{monday:null,tuesday:null,wednesday:null,thursday:null,friday:null,saturday:null}}}},members:{create:{user:{connect:{id:t}},role:"owner"}},createdBy:t},e.logoId?{logoFile:{connect:{id:e.logoId}}}:{}),include:{address:!0,configuration:{include:{openingTimes:!0,closingTimes:!0}},logoFile:!0}});return d.parse(Object.assign(Object.assign({},s),{configuration:Object.assign(Object.assign({},s.configuration),{openingTimes:(i=this.formatDateScheduleToTimeString(s.configuration.openingTimes))!==null&&i!==void 0?i:void 0,closingTimes:(n=this.formatDateScheduleToTimeString(s.configuration.closingTimes))!==null&&n!==void 0?n:void 0})}))})}updateOrganization(t,e,i){return l(this,void 0,void 0,function*(){var n,o;if(!(yield this.prisma.organization.findUnique({where:{id:t,deletedAt:null}})))throw new T(404,"Organization not found");const u=i.address?yield this.requireLocationService().getPlaceDetails(i.address.placeId):void 0,a=c=>{if(!c)return null;const[m,f]=c.split(":").map(Number),g=new Date;return g.setUTCHours(m),g.setUTCMinutes(f),g.setUTCSeconds(0),g.setUTCMilliseconds(0),g},r=yield this.prisma.organization.update({where:{id:t},data:Object.assign(Object.assign(Object.assign(Object.assign({name:i.name,phone:i.phone,email:i.email},i.logoId?{logoFile:{connect:{id:i.logoId}}}:{}),{address:i.address?{update:Object.assign(Object.assign({},i.address),{latitude:u.latitude,longitude:u.longitude,updatedBy:e})}:void 0}),i.configuration?{configuration:{update:{countriesShipping:i.configuration.countriesShipping,enableHostCheckout:i.configuration.enableHostCheckout,enableHostTracking:i.configuration.enableHostTracking,defaultLocale:i.configuration.defaultLocale,supportedLocales:i.configuration.supportedLocales,defaultCurrency:i.configuration.defaultCurrency,updatedBy:e,isAcceptingOrders:i.configuration.isAcceptingOrders,isAcceptingReservations:i.configuration.isAcceptingReservations,openingTimes:i.configuration.openingTimes?{update:{data:{monday:i.configuration.openingTimes.monday?a(i.configuration.openingTimes.monday):null,tuesday:i.configuration.openingTimes.tuesday?a(i.configuration.openingTimes.tuesday):null,wednesday:i.configuration.openingTimes.wednesday?a(i.configuration.openingTimes.wednesday):null,thursday:i.configuration.openingTimes.thursday?a(i.configuration.openingTimes.thursday):null,friday:i.configuration.openingTimes.friday?a(i.configuration.openingTimes.friday):null,saturday:i.configuration.openingTimes.saturday?a(i.configuration.openingTimes.saturday):null,sunday:i.configuration.openingTimes.sunday?a(i.configuration.openingTimes.sunday):null}}}:void 0,closingTimes:i.configuration.closingTimes?{update:{data:{monday:i.configuration.closingTimes.monday?a(i.configuration.closingTimes.monday):null,tuesday:i.configuration.closingTimes.tuesday?a(i.configuration.closingTimes.tuesday):null,wednesday:i.configuration.closingTimes.wednesday?a(i.configuration.closingTimes.wednesday):null,thursday:i.configuration.closingTimes.thursday?a(i.configuration.closingTimes.thursday):null,friday:i.configuration.closingTimes.friday?a(i.configuration.closingTimes.friday):null,saturday:i.configuration.closingTimes.saturday?a(i.configuration.closingTimes.saturday):null,sunday:i.configuration.closingTimes.sunday?a(i.configuration.closingTimes.sunday):null}}}:void 0}}}:void 0),{updatedBy:e}),include:{address:!0,logoFile:!0,configuration:{include:{openingTimes:!0,closingTimes:!0}}}});return d.parse(Object.assign(Object.assign({},r),{configuration:Object.assign(Object.assign({},r.configuration),{openingTimes:(n=this.formatDateScheduleToTimeString(r.configuration.openingTimes))!==null&&n!==void 0?n:void 0,closingTimes:(o=this.formatDateScheduleToTimeString(r.configuration.closingTimes))!==null&&o!==void 0?o:void 0})}))})}deleteOrganization(t,e){return l(this,void 0,void 0,function*(){if(!(yield this.prisma.organization.findUnique({where:{id:t}})))throw new T(404,"Organization not found");yield this.prisma.organization.update({where:{id:t},data:{deletedAt:new Date,deletedBy:e}})})}}export{S as OrganizationService};
|
|
@@ -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};
|