update transaction
This commit is contained in:
@@ -1,10 +1,5 @@
|
||||
import { Inject, Injectable } from '@nestjs/common'
|
||||
import {
|
||||
Pothos,
|
||||
PothosRef,
|
||||
PothosSchema,
|
||||
SchemaBuilderToken,
|
||||
} from '@smatch-corp/nestjs-pothos'
|
||||
import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
|
||||
import { Builder } from '../Graphql/graphql.builder'
|
||||
import { PrismaService } from '../Prisma/prisma.service'
|
||||
import { OrderStatus } from '@prisma/client'
|
||||
@@ -81,8 +76,7 @@ export class OrderSchema extends PothosSchema {
|
||||
this.builder.queryFields((t) => ({
|
||||
orders: t.prismaField({
|
||||
type: [this.order()],
|
||||
description:
|
||||
'Retrieve a list of orders with optional filtering, ordering, and pagination.',
|
||||
description: 'Retrieve a list of orders with optional filtering, ordering, and pagination.',
|
||||
args: this.builder.generator.findManyArgs('Order'),
|
||||
resolve: async (query, _root, args, _ctx, _info) => {
|
||||
return await this.prisma.order.findMany({
|
||||
@@ -113,17 +107,7 @@ export class OrderSchema extends PothosSchema {
|
||||
description: 'Create a new order.',
|
||||
args: {
|
||||
data: t.arg({
|
||||
type: this.builder.generator.getCreateInput('Order', [
|
||||
'id',
|
||||
'user',
|
||||
'paymentId',
|
||||
'payment',
|
||||
'refundTicket',
|
||||
'status',
|
||||
'total',
|
||||
'createdAt',
|
||||
'updatedAt',
|
||||
]),
|
||||
type: this.builder.generator.getCreateInput('Order', ['id', 'user', 'paymentId', 'payment', 'refundTicket', 'status', 'total', 'createdAt', 'updatedAt']),
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
@@ -150,10 +134,7 @@ export class OrderSchema extends PothosSchema {
|
||||
const order = await this.prisma.order.findUnique({
|
||||
where: { id: schedule.orderId },
|
||||
})
|
||||
if (
|
||||
order?.status === OrderStatus.PAID ||
|
||||
order?.status === OrderStatus.PENDING
|
||||
) {
|
||||
if (order?.status === OrderStatus.PAID || order?.status === OrderStatus.PENDING) {
|
||||
throw new Error('Schedule already has an order')
|
||||
}
|
||||
}
|
||||
@@ -202,17 +183,9 @@ export class OrderSchema extends PothosSchema {
|
||||
description: service.name,
|
||||
buyerName: ctx.http.me?.name ?? '',
|
||||
buyerEmail: ctx.http.me?.email ?? '',
|
||||
returnUrl: `${process.env.PAYOS_RETURN_URL}`.replace(
|
||||
'<serviceId>',
|
||||
service.id,
|
||||
),
|
||||
cancelUrl: `${process.env.PAYOS_RETURN_URL}`.replace(
|
||||
'<serviceId>',
|
||||
service.id,
|
||||
),
|
||||
expiredAt: DateTimeUtils.now()
|
||||
.plus({ minutes: 15 })
|
||||
.toUnixInteger(),
|
||||
returnUrl: `${process.env.PAYOS_RETURN_URL}`.replace('<serviceId>', service.id),
|
||||
cancelUrl: `${process.env.PAYOS_RETURN_URL}`.replace('<serviceId>', service.id),
|
||||
expiredAt: DateTimeUtils.now().plus({ minutes: 15 }).toUnixInteger(),
|
||||
})
|
||||
// update order payment id
|
||||
await this.prisma.order.update({
|
||||
@@ -230,12 +203,12 @@ export class OrderSchema extends PothosSchema {
|
||||
})
|
||||
|
||||
// update orderId for schedule dates
|
||||
await this.prisma.scheduleDate.updateMany({
|
||||
where: { scheduleId: args.data.schedule.connect?.id ?? '' },
|
||||
data: {
|
||||
orderId: order.id,
|
||||
},
|
||||
})
|
||||
// await this.prisma.scheduleDate.updateMany({
|
||||
// where: { scheduleId: args.data.schedule.connect?.id ?? '' },
|
||||
// data: {
|
||||
// orderId: order.id,
|
||||
// },
|
||||
// })
|
||||
|
||||
// refetch order
|
||||
return await this.prisma.order.findUnique({
|
||||
@@ -267,10 +240,7 @@ export class OrderSchema extends PothosSchema {
|
||||
description: 'Update an existing order.',
|
||||
args: {
|
||||
data: t.arg({
|
||||
type: this.builder.generator.getUpdateInput('Order', [
|
||||
'status',
|
||||
'total',
|
||||
]),
|
||||
type: this.builder.generator.getUpdateInput('Order', ['status', 'total']),
|
||||
required: true,
|
||||
}),
|
||||
where: t.arg({
|
||||
|
||||
Reference in New Issue
Block a user