From a75e0fff3fc4e4bd300487a6b5d951ef7fe96b66 Mon Sep 17 00:00:00 2001
From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com>
Date: Fri, 24 Jan 2025 11:16:05 +0700
Subject: [PATCH] fix: template error when no items
---
src/utils/string-template.ts | 46 ++++++++++++++++++++----------------
1 file changed, 26 insertions(+), 20 deletions(-)
diff --git a/src/utils/string-template.ts b/src/utils/string-template.ts
index 21579d3e..f7350d71 100644
--- a/src/utils/string-template.ts
+++ b/src/utils/string-template.ts
@@ -44,7 +44,7 @@ const templates = {
'order-detail': {
converter: (context?: {
- items: {
+ items?: {
product: RequestWork['productService']['product'];
list: RequestWork[];
}[];
@@ -53,26 +53,32 @@ const templates = {
discount?: number;
}[];
}) => {
- return context?.items.flatMap((item) => {
- const price = formatNumberDecimal(
- item.product.serviceCharge -
- (context.itemsDiscount?.find((v) => v.productId === item.product.id)
- ?.discount || 0),
- );
-
- const list = item.list.map((v, i) => {
- const employee = v.request.employee;
- const branch = v.request.quotation.customerBranch;
- return (
- `${i + 1}. ` +
- `${employee.namePrefix}. ${employee.firstNameEN} ${employee.lastNameEN} `.toUpperCase() +
- `(${branch.customer.customerType === 'PERS' ? `นายจ้าง ${branch.namePrefix}. ${branch.firstNameEN} ${branch.lastNameEN} `.toUpperCase() : branch.registerName})`
+ return (
+ context?.items?.flatMap((item) => {
+ const price = formatNumberDecimal(
+ item.product.serviceCharge -
+ (context.itemsDiscount?.find(
+ (v) => v.productId === item.product.id,
+ )?.discount || 0),
);
- });
- return [`- ${item.product.name} ราคา ${price} บาท`, '', ...list].join(
- '
',
- );
- });
+
+ const list = item.list.map((v, i) => {
+ const employee = v.request.employee;
+ const branch = v.request.quotation.customerBranch;
+ return (
+ `${i + 1}. ` +
+ `${employee.namePrefix}. ${employee.firstNameEN} ${employee.lastNameEN} `.toUpperCase() +
+ `(${branch.customer.customerType === 'PERS' ? `นายจ้าง ${branch.namePrefix}. ${branch.firstNameEN} ${branch.lastNameEN} `.toUpperCase() : branch.registerName})`
+ );
+ });
+ return [
+ `- ${item.product.name} ราคา ${price} บาท`,
+ '',
+ ...list,
+ '',
+ ].join('
');
+ }) || []
+ ).join('
');
},
},
} as const;