day len server theo loi Khoi noi, toi xin tuyen bo mien tru trach nhiem

This commit is contained in:
2024-11-05 15:02:53 +07:00
parent 0f68b51d75
commit 56ba2808c8
22 changed files with 482 additions and 63 deletions

View File

@@ -8,8 +8,8 @@ import {
import { Builder } from '../Graphql/graphql.builder'
import { PrismaService } from '../Prisma/prisma.service'
import { OrderStatus } from '@prisma/client'
import { DateTimeUtils } from 'src/common/utils/datetime.utils'
import { PayosService } from 'src/Payos/payos.service'
import { DateTimeUtils } from '../common/utils/datetime.utils'
import { PayosService } from '../Payos/payos.service'
@Injectable()
export class OrderSchema extends PothosSchema {
constructor(
@@ -45,6 +45,9 @@ export class OrderSchema extends PothosSchema {
scheduleId: t.exposeID('scheduleId', {
description: 'The ID of the schedule.',
}),
schedule: t.relation('schedule', {
description: 'The schedule of the order.',
}),
createdAt: t.expose('createdAt', {
type: 'DateTime',
description: 'The date and time the order was created.',
@@ -140,7 +143,7 @@ export class OrderSchema extends PothosSchema {
}
// check if input schedule has order id then throw error
const schedule = await this.prisma.schedule.findUnique({
where: { id: args.data.scheduleId },
where: { id: args.data.schedule.connect?.id ?? '' },
})
if (schedule?.orderId) {
// check if order status is PAID OR PENDING
@@ -159,9 +162,9 @@ export class OrderSchema extends PothosSchema {
data: {
status: OrderStatus.PENDING,
total: service.price,
userId: ctx.http.me.id,
userId: ctx.http.me?.id ?? '',
serviceId: service.id,
scheduleId: args.data.scheduleId,
scheduleId: args.data.schedule.connect?.id ?? '',
},
})
// check if service is valid
@@ -173,7 +176,7 @@ export class OrderSchema extends PothosSchema {
if (order.total === 0) {
// assign schedule
await this.prisma.schedule.update({
where: { id: args.data.scheduleId },
where: { id: args.data.schedule.connect?.id ?? '' },
data: {
orderId: order.id,
},
@@ -197,8 +200,8 @@ export class OrderSchema extends PothosSchema {
orderCode: paymentCode,
amount: service.price,
description: service.name,
buyerName: ctx.http.me.name,
buyerEmail: ctx.http.me.email,
buyerName: ctx.http.me?.name ?? '',
buyerEmail: ctx.http.me?.email ?? '',
returnUrl: `${process.env.PAYOS_RETURN_URL}`.replace(
'<serviceId>',
service.id,