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:
@@ -5,6 +5,7 @@ import { PrismaService } from '../Prisma/prisma.service'
|
|||||||
import { OrderStatus } from '@prisma/client'
|
import { OrderStatus } from '@prisma/client'
|
||||||
import { DateTimeUtils } from '../common/utils/datetime.utils'
|
import { DateTimeUtils } from '../common/utils/datetime.utils'
|
||||||
import { PayosService } from '../Payos/payos.service'
|
import { PayosService } from '../Payos/payos.service'
|
||||||
|
import _ from 'lodash'
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class OrderSchema extends PothosSchema {
|
export class OrderSchema extends PothosSchema {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -200,11 +201,13 @@ export class OrderSchema extends PothosSchema {
|
|||||||
expiredAt: DateTimeUtils.now().plus({ minutes: 15 }).toJSDate(),
|
expiredAt: DateTimeUtils.now().plus({ minutes: 15 }).toJSDate(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const _name = _.map(_.slice(_.split(service.name, ' '), 0, 10), (word) => _.deburr(word)).join(' ')
|
||||||
// generate payment url
|
// generate payment url
|
||||||
const paymentData = await this.payosService.createPayment({
|
const paymentData = await this.payosService.createPayment({
|
||||||
orderCode: paymentCode,
|
orderCode: paymentCode,
|
||||||
amount: service.price,
|
amount: service.price,
|
||||||
description: service.name.split(' ').slice(0, 10).join(' '),
|
description: _name,
|
||||||
buyerName: ctx.http.me?.name ?? '',
|
buyerName: ctx.http.me?.name ?? '',
|
||||||
buyerEmail: ctx.http.me?.email ?? '',
|
buyerEmail: ctx.http.me?.email ?? '',
|
||||||
returnUrl: `${process.env.PAYOS_RETURN_URL}`.replace('<serviceId>', service.id),
|
returnUrl: `${process.env.PAYOS_RETURN_URL}`.replace('<serviceId>', service.id),
|
||||||
|
|||||||
Reference in New Issue
Block a user