From c9435a6e0416fafc6dd4d38b0444c75d6e39c832 Mon Sep 17 00:00:00 2001 From: Ly Tuan Kiet Date: Wed, 27 Nov 2024 00:41:54 +0700 Subject: [PATCH] Enhance ServiceSchema by adding commission and descriptions for approve and adminNote arguments. Implement default commission logic when service is approved without a specified commission. --- src/Service/service.schema.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Service/service.schema.ts b/src/Service/service.schema.ts index 9c43d74..02625c9 100644 --- a/src/Service/service.schema.ts +++ b/src/Service/service.schema.ts @@ -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