update order and fix approve center
This commit is contained in:
@@ -125,9 +125,32 @@ export class OrderSchema extends PothosSchema {
|
||||
}),
|
||||
},
|
||||
resolve: async (query, root, args, ctx, info) => {
|
||||
return await this.prisma.order.create({
|
||||
...query,
|
||||
data: args.data,
|
||||
return this.prisma.$transaction(async (prisma) => {
|
||||
const order = await prisma.order.create({
|
||||
...query,
|
||||
data: args.data,
|
||||
});
|
||||
// check if service is valid
|
||||
if (!args.data.service.connect) {
|
||||
throw new Error('Service not found');
|
||||
}
|
||||
// check if service price is free
|
||||
if (args.data.service.connect.price === 0) {
|
||||
return order;
|
||||
}
|
||||
// generate payment code by prefix 'EPESS' + 6 hex digits
|
||||
const paymentCode =
|
||||
'EPESS' + Math.random().toString(16).slice(2, 8);
|
||||
// create payment
|
||||
await prisma.payment.create({
|
||||
data: {
|
||||
orderId: order.id,
|
||||
amount: args.data.service.connect.price as number,
|
||||
paymentCode: paymentCode,
|
||||
expiredAt: new Date(Date.now() + 1000 * 60 * 60 * 24),
|
||||
},
|
||||
});
|
||||
return order;
|
||||
});
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user