Enhance ServiceSchema by adding commission and descriptions for approve and adminNote arguments. Implement default commission logic when service is approved without a specified commission.

This commit is contained in:
2024-11-27 00:41:54 +07:00
parent 01aede0b09
commit c9435a6e04

View File

@@ -296,10 +296,17 @@ export class ServiceSchema extends PothosSchema {
approve: t.arg({
type: 'Boolean',
required: true,
description: 'The approve status of the service.',
}),
adminNote: t.arg({
type: 'String',
required: false,
description: 'The admin note of the service.',
}),
commission: t.arg({
type: 'Float',
required: false,
description: 'The commission of the service. present as float 0 to 1 and required if approve is true',
}),
},
resolve: async (query, _root, args, ctx, _info) => {
@@ -317,6 +324,10 @@ export class ServiceSchema extends PothosSchema {
if (service.status !== ServiceStatus.PENDING) {
throw new Error('Service is already approved or rejected')
}
let commission = args.commission
if (args.approve && !commission) {
commission = 0.05
}
// update service status
const updatedService = await prisma.service.update({
...query,
@@ -329,6 +340,7 @@ export class ServiceSchema extends PothosSchema {
notedByUserId: ctx.http.me?.id ?? '',
},
},
commission: commission ?? 0,
},
})
// mail to all mentor or center owner for the center