update commission
This commit is contained in:
@@ -1,10 +1,5 @@
|
||||
import { Inject, Injectable, Logger } 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 { MinioService } from '../Minio/minio.service'
|
||||
@@ -50,6 +45,18 @@ export class ServiceSchema extends PothosSchema {
|
||||
price: t.exposeFloat('price', {
|
||||
description: 'The price of the service.',
|
||||
}),
|
||||
commission: t.exposeFloat('commission', {
|
||||
description: 'The commission of the service.',
|
||||
validate: (value) => {
|
||||
if (value === undefined) {
|
||||
return true
|
||||
}
|
||||
if (typeof value !== 'number' || value < 0 || value > 1) {
|
||||
throw new Error('Commission must be between 0 and 1, eg: 0.05 for 5%')
|
||||
}
|
||||
return true
|
||||
},
|
||||
}),
|
||||
rating: t.expose('rating', {
|
||||
type: 'Float',
|
||||
nullable: true,
|
||||
@@ -67,15 +74,8 @@ export class ServiceSchema extends PothosSchema {
|
||||
description: 'The URL of the image file for the service.',
|
||||
resolve: async (service) => {
|
||||
// get file id from imageFileUrl
|
||||
const imageFileId = service.imageFileUrl
|
||||
?.split('/')
|
||||
.pop()
|
||||
?.split('?')[0]
|
||||
return await this.minioService.updatePresignUrl(
|
||||
imageFileId ?? '',
|
||||
'files',
|
||||
service.imageFileUrl ?? undefined,
|
||||
)
|
||||
const imageFileId = service.imageFileUrl?.split('/').pop()?.split('?')[0]
|
||||
return await this.minioService.updatePresignUrl(imageFileId ?? '', 'files', service.imageFileUrl ?? undefined)
|
||||
},
|
||||
}),
|
||||
status: t.expose('status', {
|
||||
@@ -147,8 +147,7 @@ export class ServiceSchema extends PothosSchema {
|
||||
{},
|
||||
),
|
||||
services: t.prismaField({
|
||||
description:
|
||||
'Retrieve a list of services with optional filtering, ordering, and pagination.',
|
||||
description: 'Retrieve a list of services with optional filtering, ordering, and pagination.',
|
||||
type: [this.service()],
|
||||
args: this.builder.generator.findManyArgs('Service'),
|
||||
resolve: async (query, _root, args, _ctx, _info) => {
|
||||
@@ -163,8 +162,7 @@ export class ServiceSchema extends PothosSchema {
|
||||
},
|
||||
}),
|
||||
servicesByCenter: t.prismaField({
|
||||
description:
|
||||
'Retrieve a list of services with optional filtering, ordering, and pagination.',
|
||||
description: 'Retrieve a list of services with optional filtering, ordering, and pagination.',
|
||||
type: [this.service()],
|
||||
|
||||
args: this.builder.generator.findManyArgs('Service'),
|
||||
@@ -329,9 +327,7 @@ export class ServiceSchema extends PothosSchema {
|
||||
...query,
|
||||
where: { id: args.serviceId },
|
||||
data: {
|
||||
status: args.approve
|
||||
? ServiceStatus.APPROVED
|
||||
: ServiceStatus.REJECTED,
|
||||
status: args.approve ? ServiceStatus.APPROVED : ServiceStatus.REJECTED,
|
||||
adminNote: {
|
||||
create: {
|
||||
content: args.adminNote ?? '',
|
||||
@@ -362,31 +358,18 @@ export class ServiceSchema extends PothosSchema {
|
||||
where: { id: { in: mentorIds } },
|
||||
})
|
||||
Logger.log(mentorEmails, 'ServiceSchema')
|
||||
const emails = [
|
||||
centerOwner.email,
|
||||
...mentorEmails.map((mentor) => mentor.email),
|
||||
]
|
||||
const emails = [centerOwner.email, ...mentorEmails.map((mentor) => mentor.email)]
|
||||
if (args.approve) {
|
||||
await this.mailService.sendTemplateEmail(
|
||||
emails,
|
||||
'Thông báo về trạng thái dịch vụ',
|
||||
'ServiceApproved',
|
||||
{
|
||||
SERVICE_NAME: service.name,
|
||||
CENTER_NAME: center.name,
|
||||
},
|
||||
)
|
||||
await this.mailService.sendTemplateEmail(emails, 'Thông báo về trạng thái dịch vụ', 'ServiceApproved', {
|
||||
SERVICE_NAME: service.name,
|
||||
CENTER_NAME: center.name,
|
||||
})
|
||||
} else {
|
||||
await this.mailService.sendTemplateEmail(
|
||||
emails,
|
||||
'Thông báo về trạng thái dịch vụ',
|
||||
'ServiceRejected',
|
||||
{
|
||||
SERVICE_NAME: service.name,
|
||||
CENTER_NAME: center.name,
|
||||
ADMIN_NOTE: args.adminNote ?? 'Không có lý do',
|
||||
},
|
||||
)
|
||||
await this.mailService.sendTemplateEmail(emails, 'Thông báo về trạng thái dịch vụ', 'ServiceRejected', {
|
||||
SERVICE_NAME: service.name,
|
||||
CENTER_NAME: center.name,
|
||||
ADMIN_NOTE: args.adminNote ?? 'Không có lý do',
|
||||
})
|
||||
}
|
||||
return updatedService
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user