From 84a9f7dd4f3b79a60e7e90b2e2ee811897619543 Mon Sep 17 00:00:00 2001 From: Ly Tuan Kiet Date: Tue, 3 Dec 2024 20:43:19 +0700 Subject: [PATCH] feat: enhance order description handling with lodash utility - Added lodash to the OrderSchema for improved string manipulation. - Updated the payment creation logic to use lodash for generating a cleaner description from the service name, limiting it to the first 10 words and removing diacritics. - This change enhances the readability and consistency of order descriptions in payment processing. --- src/Order/order.schema.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Order/order.schema.ts b/src/Order/order.schema.ts index 8687a7a..b7789d3 100644 --- a/src/Order/order.schema.ts +++ b/src/Order/order.schema.ts @@ -5,6 +5,7 @@ import { PrismaService } from '../Prisma/prisma.service' import { OrderStatus } from '@prisma/client' import { DateTimeUtils } from '../common/utils/datetime.utils' import { PayosService } from '../Payos/payos.service' +import _ from 'lodash' @Injectable() export class OrderSchema extends PothosSchema { constructor( @@ -200,11 +201,13 @@ export class OrderSchema extends PothosSchema { expiredAt: DateTimeUtils.now().plus({ minutes: 15 }).toJSDate(), }, }) + + const _name = _.map(_.slice(_.split(service.name, ' '), 0, 10), (word) => _.deburr(word)).join(' ') // generate payment url const paymentData = await this.payosService.createPayment({ orderCode: paymentCode, amount: service.price, - description: service.name.split(' ').slice(0, 10).join(' '), + description: _name, buyerName: ctx.http.me?.name ?? '', buyerEmail: ctx.http.me?.email ?? '', returnUrl: `${process.env.PAYOS_RETURN_URL}`.replace('', service.id),