update manyyyyyyyyy
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
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'
|
||||
@@ -43,6 +48,12 @@ export class OrderSchema extends PothosSchema {
|
||||
schedule: t.relation('schedule', {
|
||||
description: 'The schedule of the order.',
|
||||
}),
|
||||
chatRoomId: t.exposeID('chatRoomId', {
|
||||
description: 'The ID of the chat room.',
|
||||
}),
|
||||
chatRoom: t.relation('chatRoom', {
|
||||
description: 'The chat room of the order.',
|
||||
}),
|
||||
createdAt: t.expose('createdAt', {
|
||||
type: 'DateTime',
|
||||
description: 'The date and time the order was created.',
|
||||
@@ -79,7 +90,8 @@ 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({
|
||||
@@ -110,7 +122,18 @@ 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', 'commission']),
|
||||
type: this.builder.generator.getCreateInput('Order', [
|
||||
'id',
|
||||
'user',
|
||||
'paymentId',
|
||||
'payment',
|
||||
'refundTicket',
|
||||
'status',
|
||||
'total',
|
||||
'createdAt',
|
||||
'updatedAt',
|
||||
'commission',
|
||||
]),
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
@@ -137,7 +160,10 @@ 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')
|
||||
}
|
||||
}
|
||||
@@ -187,9 +213,17 @@ 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({
|
||||
@@ -205,15 +239,6 @@ export class OrderSchema extends PothosSchema {
|
||||
paymentCode: paymentData.paymentLinkId,
|
||||
},
|
||||
})
|
||||
|
||||
// update orderId for schedule dates
|
||||
// await this.prisma.scheduleDate.updateMany({
|
||||
// where: { scheduleId: args.data.schedule.connect?.id ?? '' },
|
||||
// data: {
|
||||
// orderId: order.id,
|
||||
// },
|
||||
// })
|
||||
|
||||
// refetch order
|
||||
return await this.prisma.order.findUnique({
|
||||
where: { id: order.id },
|
||||
@@ -244,7 +269,10 @@ 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