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.
This commit is contained in:
2024-12-03 20:43:19 +07:00
parent 367fc09c6c
commit 84a9f7dd4f

View File

@@ -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('<serviceId>', service.id),