@shophost/rest-api 2.0.51 → 2.0.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/schema.prisma +4 -0
- package/src/bootstrap.js +1 -1
- package/src/bootstrap.js.map +1 -1
- package/src/{app-services.d.ts → container.d.ts} +7 -5
- package/src/container.js +1 -0
- package/src/container.js.map +1 -0
- package/src/core/db/__generated__/client/internal/class.js +33 -29
- package/src/core/db/__generated__/client/internal/class.js.map +1 -1
- package/src/core/db/__generated__/client/internal/prismaNamespace.d.ts +4 -0
- package/src/core/db/__generated__/client/internal/prismaNamespace.js +1 -1
- package/src/core/db/__generated__/client/internal/prismaNamespace.js.map +1 -1
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.d.ts +4 -0
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js +1 -1
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js.map +1 -1
- package/src/core/db/__generated__/client/models/Order.d.ts +178 -1
- package/src/core/db/__generated__/client/models/Product.d.ts +75 -1
- package/src/core/utils/zod.util.js +1 -1
- package/src/core/utils/zod.util.js.map +1 -1
- package/src/features/cart/cart.route.d.ts +29 -0
- package/src/features/cart/cart.route.js +1 -1
- package/src/features/cart/cart.route.js.map +1 -1
- package/src/features/cart/cart.schema.d.ts +399 -0
- package/src/features/cart/cart.schema.js +1 -1
- package/src/features/cart/cart.schema.js.map +1 -1
- package/src/features/cart/cart.service.d.ts +30 -3
- package/src/features/cart/cart.service.js +1 -1
- package/src/features/cart/cart.service.js.map +1 -1
- package/src/features/inventory/inventory.service.d.ts +24 -0
- package/src/features/inventory/inventory.service.js +1 -0
- package/src/features/inventory/inventory.service.js.map +1 -0
- package/src/features/order/order.handler.js +1 -1
- package/src/features/order/order.handler.js.map +1 -1
- package/src/features/order/order.route.d.ts +314 -0
- package/src/features/order/order.route.js +1 -1
- package/src/features/order/order.route.js.map +1 -1
- package/src/features/order/order.schema.d.ts +33 -0
- package/src/features/order/order.schema.js +1 -1
- package/src/features/order/order.schema.js.map +1 -1
- package/src/features/order/order.service.d.ts +55 -1
- package/src/features/order/order.service.js +1 -1
- package/src/features/order/order.service.js.map +1 -1
- package/src/features/payment/payment.service.d.ts +4 -1
- package/src/features/payment/payment.service.js +1 -1
- package/src/features/payment/payment.service.js.map +1 -1
- package/src/features/payment/stripe.service.d.ts +2 -2
- package/src/features/payment/stripe.service.js +1 -1
- package/src/features/payment/stripe.service.js.map +1 -1
- package/src/features/product/product.route.d.ts +10 -0
- package/src/features/product/product.schema.d.ts +4 -0
- package/src/features/product/product.schema.js +1 -1
- package/src/features/product/product.schema.js.map +1 -1
- package/src/features/product/product.service.d.ts +8 -0
- package/src/features/product/product.service.js +1 -1
- package/src/features/product/product.service.js.map +1 -1
- package/src/schemas/number.schema.d.ts +1 -0
- package/src/schemas/number.schema.js +1 -1
- package/src/schemas/number.schema.js.map +1 -1
- package/src/app-services.js +0 -1
- package/src/app-services.js.map +0 -1
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { z } from "@hono/zod-openapi";
|
|
2
|
+
import { HttpException } from "../../core/exceptions/http-exception";
|
|
2
3
|
import { PrismaClientType } from "../../core/lib/prisma";
|
|
3
4
|
import { CreateOrderSchema, OrderStatus, User } from "../../schemas";
|
|
5
|
+
import { CartData } from "../cart/cart.schema";
|
|
6
|
+
import { CartService } from "../cart/cart.service";
|
|
4
7
|
import { PaymentService } from "../payment/payment.service";
|
|
8
|
+
declare class OrderInventoryConflictError extends HttpException {
|
|
9
|
+
readonly payload: CartData & {
|
|
10
|
+
message: string;
|
|
11
|
+
};
|
|
12
|
+
constructor(payload: CartData & {
|
|
13
|
+
message: string;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
5
16
|
declare class OrderService {
|
|
6
17
|
private readonly prisma;
|
|
7
18
|
private readonly paymentService;
|
|
8
|
-
|
|
19
|
+
private readonly cartService;
|
|
20
|
+
constructor(prisma: PrismaClientType, paymentService: PaymentService, cartService: CartService);
|
|
9
21
|
/**
|
|
10
22
|
* Create a draft order
|
|
11
23
|
*/
|
|
@@ -96,6 +108,14 @@ declare class OrderService {
|
|
|
96
108
|
readyForDispatchAt?: Date | null | undefined;
|
|
97
109
|
completedAt?: Date | null | undefined;
|
|
98
110
|
cancelledAt?: Date | null | undefined;
|
|
111
|
+
inventoryDeductedAt?: Date | null | undefined;
|
|
112
|
+
inventoryConflictAt?: Date | null | undefined;
|
|
113
|
+
inventoryConflictItems?: {
|
|
114
|
+
productId: string;
|
|
115
|
+
title: string;
|
|
116
|
+
requestedQuantity: number;
|
|
117
|
+
availableQuantity: number;
|
|
118
|
+
}[] | null | undefined;
|
|
99
119
|
shippingAddress?: {
|
|
100
120
|
id: string;
|
|
101
121
|
addressLineOne: string;
|
|
@@ -112,6 +132,7 @@ declare class OrderService {
|
|
|
112
132
|
} | null | undefined;
|
|
113
133
|
};
|
|
114
134
|
}>;
|
|
135
|
+
private hasCartConflict;
|
|
115
136
|
/**
|
|
116
137
|
* Get a specific order by ID
|
|
117
138
|
*/
|
|
@@ -200,6 +221,14 @@ declare class OrderService {
|
|
|
200
221
|
readyForDispatchAt?: Date | null | undefined;
|
|
201
222
|
completedAt?: Date | null | undefined;
|
|
202
223
|
cancelledAt?: Date | null | undefined;
|
|
224
|
+
inventoryDeductedAt?: Date | null | undefined;
|
|
225
|
+
inventoryConflictAt?: Date | null | undefined;
|
|
226
|
+
inventoryConflictItems?: {
|
|
227
|
+
productId: string;
|
|
228
|
+
title: string;
|
|
229
|
+
requestedQuantity: number;
|
|
230
|
+
availableQuantity: number;
|
|
231
|
+
}[] | null | undefined;
|
|
203
232
|
shippingAddress?: {
|
|
204
233
|
id: string;
|
|
205
234
|
addressLineOne: string;
|
|
@@ -314,6 +343,14 @@ declare class OrderService {
|
|
|
314
343
|
readyForDispatchAt?: Date | null | undefined;
|
|
315
344
|
completedAt?: Date | null | undefined;
|
|
316
345
|
cancelledAt?: Date | null | undefined;
|
|
346
|
+
inventoryDeductedAt?: Date | null | undefined;
|
|
347
|
+
inventoryConflictAt?: Date | null | undefined;
|
|
348
|
+
inventoryConflictItems?: {
|
|
349
|
+
productId: string;
|
|
350
|
+
title: string;
|
|
351
|
+
requestedQuantity: number;
|
|
352
|
+
availableQuantity: number;
|
|
353
|
+
}[] | null | undefined;
|
|
317
354
|
shippingAddress?: {
|
|
318
355
|
id: string;
|
|
319
356
|
addressLineOne: string;
|
|
@@ -431,6 +468,14 @@ declare class OrderService {
|
|
|
431
468
|
readyForDispatchAt?: Date | null | undefined;
|
|
432
469
|
completedAt?: Date | null | undefined;
|
|
433
470
|
cancelledAt?: Date | null | undefined;
|
|
471
|
+
inventoryDeductedAt?: Date | null | undefined;
|
|
472
|
+
inventoryConflictAt?: Date | null | undefined;
|
|
473
|
+
inventoryConflictItems?: {
|
|
474
|
+
productId: string;
|
|
475
|
+
title: string;
|
|
476
|
+
requestedQuantity: number;
|
|
477
|
+
availableQuantity: number;
|
|
478
|
+
}[] | null | undefined;
|
|
434
479
|
shippingAddress?: {
|
|
435
480
|
id: string;
|
|
436
481
|
addressLineOne: string;
|
|
@@ -539,6 +584,14 @@ declare class OrderService {
|
|
|
539
584
|
readyForDispatchAt?: Date | null | undefined;
|
|
540
585
|
completedAt?: Date | null | undefined;
|
|
541
586
|
cancelledAt?: Date | null | undefined;
|
|
587
|
+
inventoryDeductedAt?: Date | null | undefined;
|
|
588
|
+
inventoryConflictAt?: Date | null | undefined;
|
|
589
|
+
inventoryConflictItems?: {
|
|
590
|
+
productId: string;
|
|
591
|
+
title: string;
|
|
592
|
+
requestedQuantity: number;
|
|
593
|
+
availableQuantity: number;
|
|
594
|
+
}[] | null | undefined;
|
|
542
595
|
shippingAddress?: {
|
|
543
596
|
id: string;
|
|
544
597
|
addressLineOne: string;
|
|
@@ -556,3 +609,4 @@ declare class OrderService {
|
|
|
556
609
|
}>;
|
|
557
610
|
}
|
|
558
611
|
export { OrderService };
|
|
612
|
+
export { OrderInventoryConflictError };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as a}from"tslib";import{z as
|
|
1
|
+
import{__awaiter as a}from"tslib";import{z as y}from"@hono/zod-openapi";import{customAlphabet as U}from"nanoid";import{HttpException as o}from"../../core/exceptions/http-exception";import{OrderSchema as c,PaginationMetaSchema as w}from"../../schemas";import{transformCartItemToOrderItem as Z}from"../cart/cart.util";const O=U("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ",6);class A extends o{constructor(t){super(409,t.message),this.payload=t}}class z{constructor(t,i,e){this.prisma=t,this.paymentService=i,this.cartService=e}createOrder(t,i,e){return a(this,void 0,void 0,function*(){var n,r,s,u,l;const p=yield this.prisma.organization.findFirst({where:{id:t},include:{configuration:!0}});if(!p)throw new o(404,"Organization not found");const h=yield this.cartService.getCartData(t,e,{locale:p.configuration.defaultLocale});if(h.invalidProductIds.length>0||this.hasCartConflict(e.items,h.normalizedItems))throw new A(Object.assign(Object.assign({},h),{message:"Some items in your cart are no longer available in the requested quantity."}));const m=yield this.prisma.address.findFirst({where:{users:{some:{id:i.id}},isDefault:!0}});if(e.fulfilmentMethod==="delivery"&&!m)throw new o(400,"This user does not have a default shipping address");const f=yield Promise.all(h.normalizedItems.map(Z(this.prisma))),d=yield this.prisma.shippingMethod.findFirst({where:{id:e.shippingMethodId},include:{shippingZones:!0}}),S=(r=(n=d?.shippingZones[0])===null||n===void 0?void 0:n.price)!==null&&r!==void 0?r:0,v=f.reduce((I,k)=>I+k.totalPrice,0),C=v+S,g=yield this.prisma.order.create({data:Object.assign(Object.assign({token:O(),referenceId:O(),organization:{connect:{id:t}},fulfilmentMethod:e.fulfilmentMethod,shippingMethod:e.shippingMethodId?{connect:{id:e.shippingMethodId}}:void 0,currency:p.configuration.defaultCurrency,sourceIp:"127.0.0.1",items:{create:f}},m?{shippingAddress:{create:Object.assign(Object.assign({},m),{id:void 0})}}:{}),{user:{connect:{id:i.id}},payment:{create:{method:e.payment.method,provider:e.payment.provider,shipping:(u=(s=d?.shippingZones[0])===null||s===void 0?void 0:s.price)!==null&&u!==void 0?u:0,subtotal:v,total:C,discount:0,currency:p.configuration.defaultCurrency}}}),include:{items:{include:{translations:!0,image:!0}},payment:!0,shippingMethod:{include:{shippingZones:!0}}}}),D=c.parse(g);return{redirectUrl:(l=(yield this.paymentService.createCheckoutSession(t,i,D,{locale:"en",successUrl:`${e.checkoutBaseUrl}/account/orders/${g.id}?clearCart=true`,cancelUrl:`${e.checkoutBaseUrl}/checkout/shipping-and-payment`})).redirectUrl)!==null&&l!==void 0?l:void 0,order:c.parse(g)}})}hasCartConflict(t,i){return JSON.stringify(t)!==JSON.stringify(i)}getOrder(t,i,e){return a(this,void 0,void 0,function*(){const n=yield this.prisma.order.findUnique({where:{id:e,organizationId:i,deletedAt:null,user:{id:t.id}},include:{items:{include:{translations:!0,image:!0}},shippingAddress:!0,shippingMethod:{include:{shippingZones:!0}},payment:!0}});if(!n)throw new o(404,"Order not found");return c.parse(n)})}getMyOrders(t,i,e){return a(this,void 0,void 0,function*(){const{page:n=1,limit:r=10,search:s}=e,[u,l]=yield this.prisma.order.paginate({where:Object.assign({organizationId:i,userId:t,deletedAt:null},s?{referenceId:{contains:s,mode:"insensitive"}}:{}),include:{items:{include:{translations:!0,image:!0}},shippingAddress:!0,shippingMethod:{include:{shippingZones:!0}},payment:!0},orderBy:{createdAt:"desc"}}).withPages({page:n,limit:r});return{meta:w.parse(l),list:y.array(c).parse(u)}})}getOrders(t,i){return a(this,void 0,void 0,function*(){const{page:e=1,limit:n=10}=i,[r,s]=yield this.prisma.order.paginate({where:{organizationId:t,deletedAt:null},include:{items:{include:{translations:!0,image:!0}},shippingAddress:!0,shippingMethod:{include:{shippingZones:!0}},payment:!0},orderBy:{createdAt:"desc"}}).withPages({page:e,limit:n});return{meta:w.parse(s),list:y.array(c).parse(r)}})}deleteOrder(t,i,e){return a(this,void 0,void 0,function*(){if(!(yield this.prisma.order.findUnique({where:{id:i,organizationId:t,deletedAt:null}})))throw new o(404,"Order not found");yield this.prisma.order.update({where:{id:i,organizationId:t,deletedAt:null},data:{deletedAt:new Date,deletedBy:e}})})}updateStatus(t,i,e){return a(this,void 0,void 0,function*(){if(!(yield this.prisma.order.findUnique({where:{id:i,organizationId:t,deletedAt:null},include:{items:!0,shippingMethod:{include:{shippingZones:!0}}}})))throw new o(404,"Order not found");let r={};switch(e){case"accepted":r={acceptedAt:new Date};break;case"ready-for-dispatch":r={readyForDispatchAt:new Date};break;case"dispatched":r={dispatchedAt:new Date};break;case"completed":r={completedAt:new Date};break;case"cancelled":r={cancelledAt:new Date};break}const s=yield this.prisma.order.update({where:{id:i},data:r,include:{items:{include:{translations:!0,image:!0}},shippingAddress:!0,shippingMethod:{include:{shippingZones:!0}},payment:!0}});return c.parse(s)})}}export{z as OrderService};export{A as OrderInventoryConflictError};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.service.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/order/order.service.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAErE,OAAO,EAEL,WAAW,EAEX,oBAAoB,GAErB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"order.service.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/order/order.service.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAErE,OAAO,EAEL,WAAW,EAEX,oBAAoB,GAErB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,4BA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oBACd,UAAU,GAAG;wBACX,WAAW,EAAE,IAAI,IAAI,EAAE;qBACxB,CAAC;oBACF,MAAM;YACV,CAAC;YAED,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;gBAClD,KAAK,EAAE;oBACL,EAAE,EAAE,OAAO;iBACZ;gBACD,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE;oBACP,KAAK,EAAE;wBACL,OAAO,EAAE;4BACP,YAAY,EAAE,IAAI;4BAClB,KAAK,EAAE,IAAI;yBACZ;qBACF;oBACD,eAAe,EAAE,IAAI;oBACrB,cAAc,EAAE;wBACd,OAAO,EAAE;4BACP,aAAa,EAAE,IAAI;yBACpB;qBACF;oBACD,OAAO,EAAE,IAAI;iBACd;aACF,CAAC,CAAC;YAEH,OAAO,WAAW,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACzC,CAAC;KAAA;CACF;AAED,OAAO,EAAE,YAAY,EAAE,CAAC;AACxB,OAAO,EAAE,2BAA2B,EAAE,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PrismaClientType } from "../../core/lib/prisma";
|
|
2
2
|
import { Locale, User } from "../../schemas";
|
|
3
3
|
import { IntegrationRegistry } from "../integration/integration-registry";
|
|
4
|
+
import { InventoryService } from "../inventory/inventory.service";
|
|
4
5
|
import { Order } from "../order/order.schema";
|
|
5
6
|
export interface PaymentServiceOptions {
|
|
6
7
|
revolut?: {
|
|
@@ -17,8 +18,9 @@ declare class PaymentService {
|
|
|
17
18
|
private readonly prisma;
|
|
18
19
|
readonly options: PaymentServiceOptions;
|
|
19
20
|
private readonly integrationRegistry;
|
|
21
|
+
private readonly inventoryService;
|
|
20
22
|
private readonly stripeRuntimes;
|
|
21
|
-
constructor(prisma: PrismaClientType, options: PaymentServiceOptions, integrationRegistry: IntegrationRegistry);
|
|
23
|
+
constructor(prisma: PrismaClientType, options: PaymentServiceOptions, integrationRegistry: IntegrationRegistry, inventoryService: InventoryService);
|
|
22
24
|
private getStripeNotConfiguredMessage;
|
|
23
25
|
private resolveStripeRuntime;
|
|
24
26
|
private requireStripeRuntime;
|
|
@@ -34,5 +36,6 @@ declare class PaymentService {
|
|
|
34
36
|
redirectUrl: string | null;
|
|
35
37
|
}>;
|
|
36
38
|
processWebhookEvent(provider: "stripe" | "revolut", signature: string | null, body: string, organizationId?: string): Promise<void>;
|
|
39
|
+
private handleStripeCheckoutCompleted;
|
|
37
40
|
}
|
|
38
41
|
export { PaymentService };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as
|
|
1
|
+
import{__awaiter as u}from"tslib";import{HttpException as p}from"../../core/exceptions/http-exception";import{getStoredResendConfig as a,getStoredStripeConfig as l}from"../integration/integration-config";import{StripeService as v}from"./stripe.service";class h{constructor(t,r,e,i){this.prisma=t,this.options=r,this.integrationRegistry=e,this.inventoryService=i,this.stripeRuntimes=new Map}getStripeNotConfiguredMessage(t){return t?"Stripe integration is not configured for this organization":"Stripe integration is not configured"}resolveStripeRuntime(t){return u(this,void 0,void 0,function*(){var r;if(!t)return;const e=l(yield this.integrationRegistry.get(t,"stripe")),i=e?.secretKey;if(!i){this.stripeRuntimes.delete(t);return}const n=a(yield this.integrationRegistry.get(t,"resend")),s={secretKey:i,paymentMethods:(r=e?.paymentMethods)!==null&&r!==void 0?r:[],resendApiKey:n?.apiKey,resendFromEmail:n?.fromEmail,webhookSecret:e?.webhookSecret},c=JSON.stringify({resend:n??null,stripe:e??null}),o=this.stripeRuntimes.get(t);if(o?.signature===c)return o;const d={options:s,service:new v(this.prisma,s),signature:c};return this.stripeRuntimes.set(t,d),d})}requireStripeRuntime(t){return u(this,void 0,void 0,function*(){const r=yield this.resolveStripeRuntime(t);if(!r)throw new p(400,this.getStripeNotConfiguredMessage(t));return r})}getPaymentMethods(t){return u(this,void 0,void 0,function*(){var r;const e=[],i=(r=yield this.resolveStripeRuntime(t))===null||r===void 0?void 0:r.options;return i?.paymentMethods.includes("card")&&e.push({id:"stripe:card",provider:"stripe",description:"Visa, Mastercard, American Express etc..",method:"card"}),i?.paymentMethods.includes("blik")&&e.push({id:"stripe:blik",provider:"stripe",description:"Popular payment method in Poland",method:"blik"}),this.options.revolut&&this.options.revolut.paymentMethods.includes("card")&&e.push({id:"revolut:card",provider:"revolut",description:"Visa, Mastercard, American Express etc..",method:"card"}),this.options.revolut&&this.options.revolut.paymentMethods.includes("blik")&&e.push({id:"revolut:blik",provider:"revolut",description:"Popular payment method in Poland",method:"blik"}),e})}handleCheckoutSessionByProvider(t,r,e,i){return u(this,void 0,void 0,function*(){if(e.payment.provider==="stripe")return(yield this.requireStripeRuntime(t)).service.createCheckoutSession(r,e,i);throw new p(400,"Payment provider not supported")})}createCheckoutSession(t,r,e,i){return u(this,void 0,void 0,function*(){const n=yield this.handleCheckoutSessionByProvider(t,r,e,i);return yield this.prisma.paymentSession.create({data:{payment:{connect:{id:e.payment.id}},referenceId:n.id,amount:e.payment.total,currency:e.payment.currency,rawData:JSON.stringify(n)}}),{sessionId:n.id,redirectUrl:n.url}})}processWebhookEvent(t,r,e,i){return u(this,void 0,void 0,function*(){if(!r)throw new p(401,"Signature is required");if(t==="stripe"){const n=yield this.requireStripeRuntime(i),s=n.service.constructWebhookEvent(r,e);return s.type==="checkout.session.completed"?this.handleStripeCheckoutCompleted(s.data.object,n.service,i):void 0}else throw new p(400,"Payment provider not supported")})}handleStripeCheckoutCompleted(t,r,e){return u(this,void 0,void 0,function*(){var i,n,s,c;const o=yield this.prisma.paymentSession.findFirst({where:Object.assign({referenceId:t.id},e?{payment:{order:{organizationId:e}}}:{}),include:{payment:{include:{order:!0}}}});if(!o)throw new p(404,"Payment session not found");const d=(i=o.payment)===null||i===void 0?void 0:i.order;if(!d)throw new p(404,"Order not found");o.capturedAt&&(d.inventoryDeductedAt||d.inventoryConflictAt)||((!o.capturedAt||o.payment.status!=="succeeded")&&(yield this.prisma.paymentSession.update({where:{id:o.id},data:{capturedAt:(n=o.capturedAt)!==null&&n!==void 0?n:new Date,payment:{update:{status:"succeeded"}}}})),(yield this.inventoryService.processPaidOrderInventory(d.id)).status!=="deducted")||(yield r.sendOrderNotifications(d.id,(c=(s=t.metadata)===null||s===void 0?void 0:s.userId)!==null&&c!==void 0?c:d.userId))})}}export{h as PaymentService};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payment.service.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/payment/payment.service.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAGrE,OAAO,EACL,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"payment.service.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/payment/payment.service.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAGrE,OAAO,EACL,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,mCAAmC,CAAC;AAK3C,OAAO,EAAE,aAAa,EAAwB,MAAM,kBAAkB,CAAC;AAqBvE,MAAM,cAAc;IAGlB,YACmB,MAAwB,EACzB,OAA8B,EAC7B,mBAAwC,EACxC,gBAAkC;QAHlC,WAAM,GAAN,MAAM,CAAkB;QACzB,YAAO,GAAP,OAAO,CAAuB;QAC7B,wBAAmB,GAAnB,mBAAmB,CAAqB;QACxC,qBAAgB,GAAhB,gBAAgB,CAAkB;QANpC,mBAAc,GAAG,IAAI,GAAG,EAAyB,CAAC;IAOhE,CAAC;IAEI,6BAA6B,CAAC,cAAuB;QAC3D,OAAO,cAAc;YACnB,CAAC,CAAC,4DAA4D;YAC9D,CAAC,CAAC,sCAAsC,CAAC;IAC7C,CAAC;IAEa,oBAAoB,CAChC,cAAuB;;;YAEvB,IAAI,CAAC,cAAc,EAAE,CAAC;gBACpB,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,MAAM,YAAY,GAAG,qB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,yBAAyB,CAC3E,KAAK,CAAC,EAAE,CACT,CAAC;YAEF,IAAI,eAAe,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;gBAC1C,OAAO;YACT,CAAC;YAED,MAAM,aAAa,CAAC,sBAAsB,CACxC,KAAK,CAAC,EAAE,EACR,MAAA,MAAA,OAAO,CAAC,QAAQ,0CAAE,MAAM,mCAAI,KAAK,CAAC,MAAM,CACzC,CAAC;QACJ,CAAC;KAAA;CACF;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -20,8 +20,8 @@ declare class StripeService {
|
|
|
20
20
|
private readonly stripe?;
|
|
21
21
|
private emailService?;
|
|
22
22
|
constructor(prisma: PrismaClientType, options?: StripeServiceOptions | undefined);
|
|
23
|
-
|
|
23
|
+
sendOrderNotifications(orderId: string, userId?: string | null): Promise<void>;
|
|
24
|
+
constructWebhookEvent(signature: string, body: string): Stripe.Event;
|
|
24
25
|
createCheckoutSession(user: User, order: Order, { locale, successUrl, cancelUrl }: CreateCheckoutSessionOptions): Promise<Stripe.Response<Stripe.Checkout.Session>>;
|
|
25
|
-
handleWebhookEvent(signature: string, body: string): Promise<void>;
|
|
26
26
|
}
|
|
27
27
|
export { StripeService };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as
|
|
1
|
+
import{__awaiter as c}from"tslib";import k from"stripe";import{HttpException as a}from"../../core/exceptions/http-exception";import{EmailService as E}from"../../core/notifications/email.service";import{OrderSchema as h,OrganizationSchema as v,UserSchema as p}from"../../schemas";class z{constructor(r,e){this.prisma=r,this.options=e,e?.secretKey&&(this.stripe=new k(e.secretKey)),e?.resendApiKey&&(this.emailService=new E({apiKey:e.resendApiKey,fromEmail:e.resendFromEmail}))}sendOrderNotifications(r,e){return c(this,void 0,void 0,function*(){if(!this.emailService)return;const i=yield this.prisma.order.findFirst({where:{id:r},include:{items:{include:{translations:!0,image:!0}},payment:!0,organization:{include:{address:!0,configuration:!0,logoFile:!0,members:{include:{user:!0}}}},shippingAddress:!0,shippingMethod:{include:{shippingZones:!0}}}}),s=e??i?.userId,t=s?yield this.prisma.user.findFirst({where:{id:s}}):null;if(!(!i||!t)){yield this.emailService.sendOrderConfirmationEmail(p.parse(t),v.parse(i.organization),h.parse(i));for(const d of i.organization.members)yield this.emailService.sendOrderNotificationEmail(p.parse(t),p.parse(d.user),v.parse(i.organization),h.parse(i))}})}constructWebhookEvent(r,e){var i;if(!this.stripe)throw new a(400,"Stripe is not configured");if(!(!((i=this.options)===null||i===void 0)&&i.webhookSecret))throw new a(400,"Stripe webhook secret is not configured");return this.stripe.webhooks.constructEvent(e,r,this.options.webhookSecret)}createCheckoutSession(r,e,i){return c(this,arguments,void 0,function*(s,t,{locale:d,successUrl:f,cancelUrl:y}){var u,l;if(!this.stripe)throw new a(400,"Stripe is not configured");if(t.payment.method!=="card"&&t.payment.method!=="blik")throw new a(400,"Payment method not supported");if(!(!((u=this.options)===null||u===void 0)&&u.paymentMethods.includes(t.payment.method)))throw new a(400,`Stripe payment method ${t.payment.method} is not enabled`);const _={payment_method_types:[t.payment.method],customer_email:s.email,line_items:t.items.map(({translations:w,unitPrice:S,quantity:g,image:n})=>{var m;const o=w.find(b=>b.locale===d);return{quantity:g,price_data:{currency:"pln",product_data:{name:(m=o?.title)!==null&&m!==void 0?m:"N/A",description:o?.subtitle||void 0,images:n?.url?[n?.url]:void 0},unit_amount:S*100}}}),shipping_options:!((l=t.shippingMethod)===null||l===void 0)&&l.shippingZones[0].price?[{shipping_rate_data:{type:"fixed_amount",fixed_amount:{amount:t.payment.shipping*100,currency:t.currency.toLowerCase()},display_name:"Delivery fee"}}]:void 0,mode:"payment",success_url:f,cancel_url:y,metadata:{userId:s.id,orderId:t.id}};return this.stripe.checkout.sessions.create(_)})}}export{z as StripeService};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripe.service.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/payment/stripe.service.ts"],"names":[],"mappings":";AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAErE,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAEL,WAAW,EACX,kBAAkB,EAElB,UAAU,GACX,MAAM,eAAe,CAAC;AAiBvB,MAAM,aAAa;IAIjB,YACmB,MAAwB,EACzB,OAA8B;QAD7B,WAAM,GAAN,MAAM,CAAkB;QACzB,YAAO,GAAP,OAAO,CAAuB;QAE9C,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,EAAE,CAAC;YACvB,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC9C,CAAC;QAED,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,EAAE,CAAC;YAC1B,IAAI,CAAC,YAAY,GAAG,IAAI,YAAY,CAAC;gBACnC,MAAM,EAAE,OAAO,CAAC,YAAY;gBAC5B,SAAS,EAAE,OAAO,CAAC,eAAe;aACnC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;
|
|
1
|
+
{"version":3,"file":"stripe.service.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/payment/stripe.service.ts"],"names":[],"mappings":";AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAErE,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAEL,WAAW,EACX,kBAAkB,EAElB,UAAU,GACX,MAAM,eAAe,CAAC;AAiBvB,MAAM,aAAa;IAIjB,YACmB,MAAwB,EACzB,OAA8B;QAD7B,WAAM,GAAN,MAAM,CAAkB;QACzB,YAAO,GAAP,OAAO,CAAuB;QAE9C,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,EAAE,CAAC;YACvB,IAAI,CAAC,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MAAM,EAAE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,GAAG,EAAC,CAAC,CAAC,CAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS;6BAC9C;4BACD,WAAW,EAAE,SAAS,GAAG,GAAG;yBAC7B;qBACF,CAAC;gBACJ,CAAC,CACF;gBACD,gBAAgB,EAAE,CAAA,MAAA,KAAK,CAAC,cAAc,0CAAE,aAAa,CAAC,CAAC,EAAE,KAAK;oBAC5D,CAAC,CAAC;wBACE;4BACE,kBAAkB,EAAE;gCAClB,IAAI,EAAE,cAAc;gCACpB,YAAY,EAAE;oCACZ,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ,GAAG,GAAG;oCACpC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE;iCACvC;gCACD,YAAY,EAAE,cAAc;6BAC7B;yBACF;qBACF;oBACH,CAAC,CAAC,SAAS;gBACb,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE,UAAU;gBACvB,UAAU,EAAE,SAAS;gBACrB,QAAQ,EAAE;oBACR,MAAM,EAAE,IAAI,CAAC,EAAE;oBACf,OAAO,EAAE,KAAK,CAAC,EAAE;iBAClB;aACF,CAAC;YAEF,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACtD,CAAC;KAAA;CAEF;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -151,6 +151,7 @@ export declare const productRoute: {
|
|
|
151
151
|
id: z.ZodString;
|
|
152
152
|
slug: z.ZodOptional<z.ZodString>;
|
|
153
153
|
sku: z.ZodOptional<z.ZodString>;
|
|
154
|
+
availableQuantity: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
154
155
|
basePrice: z.ZodCoercedNumber<unknown>;
|
|
155
156
|
discountedBasePrice: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
156
157
|
currency: z.ZodString;
|
|
@@ -557,6 +558,7 @@ export declare const productRoute: {
|
|
|
557
558
|
sku: z.ZodOptional<z.ZodString>;
|
|
558
559
|
basePrice: z.ZodCoercedNumber<unknown>;
|
|
559
560
|
discountedBasePrice: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
561
|
+
availableQuantity: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
560
562
|
images: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
561
563
|
id: z.ZodString;
|
|
562
564
|
url: z.ZodString;
|
|
@@ -881,6 +883,7 @@ export declare const productRoute: {
|
|
|
881
883
|
id: z.ZodString;
|
|
882
884
|
slug: z.ZodOptional<z.ZodString>;
|
|
883
885
|
sku: z.ZodOptional<z.ZodString>;
|
|
886
|
+
availableQuantity: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
884
887
|
basePrice: z.ZodCoercedNumber<unknown>;
|
|
885
888
|
discountedBasePrice: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
886
889
|
currency: z.ZodString;
|
|
@@ -1287,6 +1290,7 @@ export declare const productRoute: {
|
|
|
1287
1290
|
sku: z.ZodOptional<z.ZodString>;
|
|
1288
1291
|
basePrice: z.ZodCoercedNumber<unknown>;
|
|
1289
1292
|
discountedBasePrice: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
1293
|
+
availableQuantity: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
1290
1294
|
images: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1291
1295
|
id: z.ZodString;
|
|
1292
1296
|
url: z.ZodString;
|
|
@@ -1593,6 +1597,7 @@ export declare const productRoute: {
|
|
|
1593
1597
|
sku: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
1594
1598
|
basePrice: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
1595
1599
|
discountedBasePrice: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>>;
|
|
1600
|
+
availableQuantity: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>>;
|
|
1596
1601
|
images: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1597
1602
|
id: z.ZodString;
|
|
1598
1603
|
url: z.ZodString;
|
|
@@ -1871,6 +1876,7 @@ export declare const productRoute: {
|
|
|
1871
1876
|
id: z.ZodString;
|
|
1872
1877
|
slug: z.ZodOptional<z.ZodString>;
|
|
1873
1878
|
sku: z.ZodOptional<z.ZodString>;
|
|
1879
|
+
availableQuantity: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
1874
1880
|
basePrice: z.ZodCoercedNumber<unknown>;
|
|
1875
1881
|
discountedBasePrice: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
1876
1882
|
currency: z.ZodString;
|
|
@@ -2444,6 +2450,7 @@ export declare const productRoute: {
|
|
|
2444
2450
|
sku: z.ZodOptional<z.ZodString>;
|
|
2445
2451
|
basePrice: z.ZodCoercedNumber<unknown>;
|
|
2446
2452
|
discountedBasePrice: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
2453
|
+
availableQuantity: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
2447
2454
|
images: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
2448
2455
|
id: z.ZodString;
|
|
2449
2456
|
url: z.ZodString;
|
|
@@ -2721,6 +2728,7 @@ export declare const productRoute: {
|
|
|
2721
2728
|
id: z.ZodString;
|
|
2722
2729
|
slug: z.ZodOptional<z.ZodString>;
|
|
2723
2730
|
sku: z.ZodOptional<z.ZodString>;
|
|
2731
|
+
availableQuantity: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
2724
2732
|
basePrice: z.ZodCoercedNumber<unknown>;
|
|
2725
2733
|
discountedBasePrice: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
2726
2734
|
currency: z.ZodString;
|
|
@@ -3188,6 +3196,7 @@ export declare const productRoute: {
|
|
|
3188
3196
|
id: z.ZodString;
|
|
3189
3197
|
slug: z.ZodOptional<z.ZodString>;
|
|
3190
3198
|
sku: z.ZodOptional<z.ZodString>;
|
|
3199
|
+
availableQuantity: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
3191
3200
|
basePrice: z.ZodCoercedNumber<unknown>;
|
|
3192
3201
|
discountedBasePrice: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
3193
3202
|
currency: z.ZodString;
|
|
@@ -3833,6 +3842,7 @@ export declare const productRoute: {
|
|
|
3833
3842
|
id: z.ZodString;
|
|
3834
3843
|
slug: z.ZodOptional<z.ZodString>;
|
|
3835
3844
|
sku: z.ZodOptional<z.ZodString>;
|
|
3845
|
+
availableQuantity: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
3836
3846
|
basePrice: z.ZodCoercedNumber<unknown>;
|
|
3837
3847
|
discountedBasePrice: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
3838
3848
|
currency: z.ZodString;
|
|
@@ -3,6 +3,7 @@ export declare const ProductSchema: z.ZodObject<{
|
|
|
3
3
|
id: z.ZodString;
|
|
4
4
|
slug: z.ZodOptional<z.ZodString>;
|
|
5
5
|
sku: z.ZodOptional<z.ZodString>;
|
|
6
|
+
availableQuantity: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
6
7
|
basePrice: z.ZodCoercedNumber<unknown>;
|
|
7
8
|
discountedBasePrice: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
8
9
|
currency: z.ZodString;
|
|
@@ -410,6 +411,7 @@ export declare const LocalizedProductSchema: z.ZodObject<{
|
|
|
410
411
|
sku: z.ZodOptional<z.ZodString>;
|
|
411
412
|
basePrice: z.ZodCoercedNumber<unknown>;
|
|
412
413
|
discountedBasePrice: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
414
|
+
availableQuantity: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
413
415
|
images: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
414
416
|
id: z.ZodString;
|
|
415
417
|
url: z.ZodString;
|
|
@@ -675,6 +677,7 @@ export declare const CreateProductSchema: z.ZodObject<{
|
|
|
675
677
|
sku: z.ZodOptional<z.ZodString>;
|
|
676
678
|
basePrice: z.ZodCoercedNumber<unknown>;
|
|
677
679
|
discountedBasePrice: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
680
|
+
availableQuantity: z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>;
|
|
678
681
|
images: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
679
682
|
id: z.ZodString;
|
|
680
683
|
url: z.ZodString;
|
|
@@ -1055,6 +1058,7 @@ export declare const UpdateProductSchema: z.ZodObject<{
|
|
|
1055
1058
|
sku: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
1056
1059
|
basePrice: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
1057
1060
|
discountedBasePrice: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>>;
|
|
1061
|
+
availableQuantity: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodNull]>>, z.ZodTransform<string | number | null, string | number | null | undefined>>, z.ZodNullable<z.ZodNumber>>>;
|
|
1058
1062
|
images: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1059
1063
|
id: z.ZodString;
|
|
1060
1064
|
url: z.ZodString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{z as e}from"@hono/zod-openapi";import{validateRequiredForDefaultLocale as
|
|
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
|
-
{"version":3,"file":"product.schema.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/product/product.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAEtC,OAAO,EAAE,gCAAgC,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,
|
|
1
|
+
{"version":3,"file":"product.schema.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/product/product.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM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,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,SAAS,EACzC,CAAC;QACD,GAAG,CAAC,QAAQ,CAAC;YACX,IAAI,EAAE,CAAC,CAAC,YAAY,CAAC,MAAM;YAC3B,IAAI,EAAE,CAAC,qBAAqB,CAAC;YAC7B,OAAO,EAAE,2CAA2C;SACrD,CAAC,CAAC;IACL,CAAC;IACD,yCAAyC;IACzC,OAAO,gCAAgC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAC9D,CAAC,CAAC;KACD,OAAO,CAAC,eAAe,CAAC,CAAC"}
|
|
@@ -14,6 +14,7 @@ declare class ProductService {
|
|
|
14
14
|
*/
|
|
15
15
|
createProduct(organizationId: string, userId: string, body: z.infer<typeof CreateProductSchema>): Promise<{
|
|
16
16
|
id: string;
|
|
17
|
+
availableQuantity: number | null;
|
|
17
18
|
basePrice: number;
|
|
18
19
|
discountedBasePrice: number | null;
|
|
19
20
|
currency: string;
|
|
@@ -84,6 +85,7 @@ declare class ProductService {
|
|
|
84
85
|
createdAt: Date;
|
|
85
86
|
basePrice: number;
|
|
86
87
|
discountedBasePrice: number | null;
|
|
88
|
+
availableQuantity: number | null;
|
|
87
89
|
modifierGroups: {
|
|
88
90
|
title: string | null;
|
|
89
91
|
id: string;
|
|
@@ -114,6 +116,7 @@ declare class ProductService {
|
|
|
114
116
|
metadata?: Record<string, string> | null | undefined;
|
|
115
117
|
} | {
|
|
116
118
|
id: string;
|
|
119
|
+
availableQuantity: number | null;
|
|
117
120
|
basePrice: number;
|
|
118
121
|
discountedBasePrice: number | null;
|
|
119
122
|
currency: string;
|
|
@@ -193,6 +196,7 @@ declare class ProductService {
|
|
|
193
196
|
};
|
|
194
197
|
list: {
|
|
195
198
|
id: string;
|
|
199
|
+
availableQuantity: number | null;
|
|
196
200
|
basePrice: number;
|
|
197
201
|
discountedBasePrice: number | null;
|
|
198
202
|
currency: string;
|
|
@@ -267,6 +271,7 @@ declare class ProductService {
|
|
|
267
271
|
createdAt: Date;
|
|
268
272
|
basePrice: number;
|
|
269
273
|
discountedBasePrice: number | null;
|
|
274
|
+
availableQuantity: number | null;
|
|
270
275
|
modifierGroups: {
|
|
271
276
|
title: string | null;
|
|
272
277
|
id: string;
|
|
@@ -317,6 +322,7 @@ declare class ProductService {
|
|
|
317
322
|
};
|
|
318
323
|
list: {
|
|
319
324
|
id: string;
|
|
325
|
+
availableQuantity: number | null;
|
|
320
326
|
basePrice: number;
|
|
321
327
|
discountedBasePrice: number | null;
|
|
322
328
|
currency: string;
|
|
@@ -379,6 +385,7 @@ declare class ProductService {
|
|
|
379
385
|
*/
|
|
380
386
|
updateProduct(organizationId: string, id: string, userId: string, body: z.infer<typeof UpdateProductSchema>): Promise<{
|
|
381
387
|
id: string;
|
|
388
|
+
availableQuantity: number | null;
|
|
382
389
|
basePrice: number;
|
|
383
390
|
discountedBasePrice: number | null;
|
|
384
391
|
currency: string;
|
|
@@ -440,6 +447,7 @@ declare class ProductService {
|
|
|
440
447
|
*/
|
|
441
448
|
updateProductStatus(organizationId: string, id: string, operation: "publish" | "unpublish", userId: string): Promise<{
|
|
442
449
|
id: string;
|
|
450
|
+
availableQuantity: number | null;
|
|
443
451
|
basePrice: number;
|
|
444
452
|
discountedBasePrice: number | null;
|
|
445
453
|
currency: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as l}from"tslib";import{z as
|
|
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};
|