update commission
This commit is contained in:
Submodule epess-database updated: 31999e9454...43ddf9328e
@@ -43,4 +43,10 @@ export const ConfigConstants: Record<
|
||||
value: '22:00:00',
|
||||
visible: true,
|
||||
},
|
||||
DEFAULT_COMMISSION: {
|
||||
name: 'Default Commission',
|
||||
key: 'DEFAULT_COMMISSION',
|
||||
value: '0.05',
|
||||
visible: true,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -50,8 +50,8 @@ export class ChatroomSchema extends PothosSchema {
|
||||
mentor: t.relation('mentor', {
|
||||
description: 'The mentor.',
|
||||
}),
|
||||
meetingRoom: t.relation('meetingRoom', {
|
||||
description: 'The meeting room.',
|
||||
collaborationSession: t.relation('CollaborationSession', {
|
||||
description: 'The collaboration session.',
|
||||
}),
|
||||
lastActivity: t.expose('lastActivity', {
|
||||
type: 'DateTime',
|
||||
|
||||
@@ -5,4 +5,5 @@ export enum DocumentEvent {
|
||||
SAVED = 'document_saved',
|
||||
PAGE_CREATED = 'document_page_created',
|
||||
PAGE_DELETED = 'document_page_deleted',
|
||||
DOCUMENT_CREATED = 'document_created',
|
||||
}
|
||||
|
||||
@@ -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, SchemaContext } from '../Graphql/graphql.builder'
|
||||
import { PrismaService } from '../Prisma/prisma.service'
|
||||
import { DocumentEvent } from './document.event'
|
||||
@@ -33,22 +28,44 @@ export class DocumentSchema extends PothosSchema {
|
||||
updatedAt: t.expose('updatedAt', { type: 'DateTime' }),
|
||||
owner: t.relation('owner'),
|
||||
ownerId: t.exposeID('ownerId'),
|
||||
collaborators: t.exposeStringList('collaborators'),
|
||||
collaborators: t.relation('collaborators'),
|
||||
isPublic: t.exposeBoolean('isPublic'),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
@PothosRef()
|
||||
documentCollaborator() {
|
||||
return this.builder.prismaObject('DocumentCollaborator', {
|
||||
fields: (t) => ({
|
||||
documentId: t.exposeID('documentId', { nullable: false }),
|
||||
userId: t.exposeID('userId', { nullable: false }),
|
||||
document: t.relation('document', { nullable: false }),
|
||||
user: t.relation('user', { nullable: false }),
|
||||
readable: t.exposeBoolean('readable', { nullable: false }),
|
||||
writable: t.exposeBoolean('writable', { nullable: false }),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
@PothosRef()
|
||||
documentDelta() {
|
||||
return this.builder.simpleObject('DocumentDelta', {
|
||||
fields: (t) => ({
|
||||
documentId: t.string(),
|
||||
pageIndex: t.int(),
|
||||
eventType: t.string(),
|
||||
documentId: t.string({
|
||||
nullable: true,
|
||||
}),
|
||||
pageIndex: t.int({
|
||||
nullable: true,
|
||||
}),
|
||||
delta: t.field({
|
||||
type: 'Delta',
|
||||
nullable: true,
|
||||
}),
|
||||
senderId: t.string({
|
||||
nullable: true,
|
||||
}),
|
||||
senderId: t.string(),
|
||||
}),
|
||||
})
|
||||
}
|
||||
@@ -98,11 +115,7 @@ export class DocumentSchema extends PothosSchema {
|
||||
if (ctx.isSubscription) throw new Error('Not allowed')
|
||||
const userId = ctx.http?.me?.id
|
||||
if (!userId) throw new Error('User not found')
|
||||
const fileUrl = await this.minio.getFileUrl(
|
||||
'document',
|
||||
'document',
|
||||
'document',
|
||||
)
|
||||
const fileUrl = await this.minio.getFileUrl('document', 'document', 'document')
|
||||
if (!fileUrl) throw new Error('File not found')
|
||||
const document = await this.prisma.document.create({
|
||||
...query,
|
||||
@@ -155,10 +168,7 @@ export class DocumentSchema extends PothosSchema {
|
||||
delta,
|
||||
senderId: ctx.http?.me?.id,
|
||||
}
|
||||
ctx.http.pubSub.publish(
|
||||
`${DocumentEvent.CHANGED}.${args.documentId}`,
|
||||
documentDelta,
|
||||
)
|
||||
ctx.http.pubSub.publish(`${DocumentEvent.CHANGED}.${args.documentId}`, documentDelta)
|
||||
return documentDelta
|
||||
},
|
||||
}),
|
||||
@@ -185,6 +195,32 @@ export class DocumentSchema extends PothosSchema {
|
||||
return args.data
|
||||
},
|
||||
}),
|
||||
addCollaborator: t.prismaField({
|
||||
type: this.documentCollaborator(),
|
||||
args: {
|
||||
documentId: t.arg({ type: 'String', required: true }),
|
||||
userId: t.arg({ type: 'String', required: true }),
|
||||
readable: t.arg({ type: 'Boolean', required: true }),
|
||||
writable: t.arg({ type: 'Boolean', required: true }),
|
||||
},
|
||||
resolve: async (_, __, args, ctx: SchemaContext) => {
|
||||
if (ctx.isSubscription) throw new Error('Not allowed')
|
||||
// check if ctx user is owner of document
|
||||
const document = await this.prisma.document.findUnique({
|
||||
where: { id: args.documentId },
|
||||
})
|
||||
if (!document) throw new Error('Document not found')
|
||||
if (document.ownerId !== ctx.http?.me?.id) throw new Error('User is not owner of document')
|
||||
return await this.prisma.documentCollaborator.create({
|
||||
data: {
|
||||
documentId: args.documentId,
|
||||
userId: args.userId,
|
||||
readable: args.readable,
|
||||
writable: args.writable,
|
||||
},
|
||||
})
|
||||
},
|
||||
}),
|
||||
}))
|
||||
|
||||
this.builder.subscriptionFields((t) => ({
|
||||
|
||||
@@ -1,5 +1,45 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { Pothos, PothosRef } from '@smatch-corp/nestjs-pothos'
|
||||
import { Inject, Injectable } from '@nestjs/common'
|
||||
import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
|
||||
import { Builder } from 'src/Graphql/graphql.builder'
|
||||
import { PrismaService } from 'src/Prisma/prisma.service'
|
||||
|
||||
@Injectable()
|
||||
export class FinanceSchema {}
|
||||
export class FinanceSchema extends PothosSchema {
|
||||
constructor(
|
||||
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||
private readonly prisma: PrismaService,
|
||||
) {
|
||||
super()
|
||||
}
|
||||
|
||||
@PothosRef()
|
||||
finance() {
|
||||
return this.builder.simpleObject('Finance', {
|
||||
description: 'A finance in the system.',
|
||||
fields: (t) => ({
|
||||
id: t.string({
|
||||
description: 'The ID of the finance.',
|
||||
}),
|
||||
amount: t.string({
|
||||
description: 'The amount of the finance.',
|
||||
}),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
@PothosRef()
|
||||
init(): void {
|
||||
this.builder.queryFields((t) => ({
|
||||
finance: t.field({
|
||||
type: this.finance(),
|
||||
description: 'Retrieve a single finance by its unique identifier.',
|
||||
resolve: async () => {
|
||||
return {
|
||||
id: '1',
|
||||
amount: '100',
|
||||
}
|
||||
},
|
||||
}),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import { initContextCache } from '@pothos/core'
|
||||
import { PubSub } from 'graphql-subscriptions'
|
||||
import { DocumentModule } from 'src/Document/document.module'
|
||||
import { Context } from 'graphql-ws'
|
||||
import { FinanceModule } from 'src/Finance/finance.module'
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
@@ -77,6 +78,7 @@ import { Context } from 'graphql-ws'
|
||||
WorkshopMeetingRoomModule,
|
||||
AdminNoteModule,
|
||||
DocumentModule,
|
||||
FinanceModule,
|
||||
PothosModule.forRoot({
|
||||
builder: {
|
||||
inject: [PrismaService],
|
||||
|
||||
@@ -51,6 +51,9 @@ export class OrderSchema extends PothosSchema {
|
||||
type: 'DateTime',
|
||||
description: 'The date and time the order was updated.',
|
||||
}),
|
||||
commission: t.exposeFloat('commission', {
|
||||
description: 'The commission of the order.',
|
||||
}),
|
||||
user: t.relation('user', {
|
||||
description: 'The user who made the order.',
|
||||
}),
|
||||
@@ -107,7 +110,7 @@ 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']),
|
||||
type: this.builder.generator.getCreateInput('Order', ['id', 'user', 'paymentId', 'payment', 'refundTicket', 'status', 'total', 'createdAt', 'updatedAt', 'commission']),
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
@@ -146,6 +149,7 @@ export class OrderSchema extends PothosSchema {
|
||||
userId: ctx.http.me?.id ?? '',
|
||||
serviceId: service.id,
|
||||
scheduleId: args.data.schedule.connect?.id ?? '',
|
||||
commission: service.commission ?? 0.0,
|
||||
},
|
||||
})
|
||||
// check if service is valid
|
||||
|
||||
@@ -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
|
||||
})
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
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 { LiveKitRoomService } from 'src/LiveKit/livekit.room.service'
|
||||
@@ -22,17 +17,17 @@ export class ServiceMeetingRoomSchema extends PothosSchema {
|
||||
|
||||
@PothosRef()
|
||||
serviceMeetingRoom() {
|
||||
return this.builder.prismaObject('ServiceMeetingRoom', {
|
||||
return this.builder.prismaObject('CollaborationSession', {
|
||||
description: 'A service meeting room in the system.',
|
||||
fields: (t) => ({
|
||||
id: t.exposeID('id', {
|
||||
description: 'The ID of the service meeting room.',
|
||||
description: 'The ID of the collaboration session.',
|
||||
}),
|
||||
chattingRoomId: t.exposeString('chattingRoomId', {
|
||||
description: 'The ID of the chatting room.',
|
||||
chatRoomId: t.exposeString('chatRoomId', {
|
||||
description: 'The ID of the chat room.',
|
||||
}),
|
||||
chattingRoom: t.relation('chattingRoom', {
|
||||
description: 'The chatting room.',
|
||||
chatRoom: t.relation('chatRoom', {
|
||||
description: 'The chat room.',
|
||||
}),
|
||||
}),
|
||||
})
|
||||
@@ -43,11 +38,10 @@ export class ServiceMeetingRoomSchema extends PothosSchema {
|
||||
this.builder.queryFields((t) => ({
|
||||
serviceMeetingRoom: t.prismaField({
|
||||
type: this.serviceMeetingRoom(),
|
||||
args: this.builder.generator.findUniqueArgs('ServiceMeetingRoom'),
|
||||
description:
|
||||
'Retrieve a single service meeting room by its unique identifier.',
|
||||
args: this.builder.generator.findUniqueArgs('CollaborationSession'),
|
||||
description: 'Retrieve a single collaboration session by its unique identifier.',
|
||||
resolve: async (query, _root, args, _ctx, _info) => {
|
||||
return await this.prisma.serviceMeetingRoom.findUnique({
|
||||
return await this.prisma.collaborationSession.findUnique({
|
||||
...query,
|
||||
where: args.where,
|
||||
})
|
||||
@@ -55,11 +49,10 @@ export class ServiceMeetingRoomSchema extends PothosSchema {
|
||||
}),
|
||||
serviceMeetingRooms: t.prismaField({
|
||||
type: [this.serviceMeetingRoom()],
|
||||
args: this.builder.generator.findManyArgs('ServiceMeetingRoom'),
|
||||
description:
|
||||
'Retrieve a list of service meeting rooms with optional filtering, ordering, and pagination.',
|
||||
args: this.builder.generator.findManyArgs('CollaborationSession'),
|
||||
description: 'Retrieve a list of collaboration sessions with optional filtering, ordering, and pagination.',
|
||||
resolve: async (query, _root, args, _ctx, _info) => {
|
||||
return await this.prisma.serviceMeetingRoom.findMany({
|
||||
return await this.prisma.collaborationSession.findMany({
|
||||
...query,
|
||||
skip: args.skip ?? undefined,
|
||||
take: args.take ?? undefined,
|
||||
@@ -75,22 +68,22 @@ export class ServiceMeetingRoomSchema extends PothosSchema {
|
||||
type: this.serviceMeetingRoom(),
|
||||
args: {
|
||||
input: t.arg({
|
||||
type: this.builder.generator.getCreateInput('ServiceMeetingRoom'),
|
||||
type: this.builder.generator.getCreateInput('CollaborationSession'),
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
description: 'Create a new service meeting room.',
|
||||
resolve: async (query, _root, args, _ctx, _info) => {
|
||||
// for test only !!!
|
||||
if (args.input.chattingRoom.create) {
|
||||
args.input.chattingRoom.create.id = uuidv4()
|
||||
if (args.input.chatRoom.create) {
|
||||
args.input.chatRoom.create.id = uuidv4()
|
||||
}
|
||||
|
||||
// call livekit room service to create room
|
||||
// this.liveKitRoomService.createServiceMeetingRoom(
|
||||
// args.input.chattingRoom.create?.id ?? '',
|
||||
// args.input.chatRoom.create?.id ?? '',
|
||||
// )
|
||||
return await this.prisma.serviceMeetingRoom.create({
|
||||
return await this.prisma.collaborationSession.create({
|
||||
...query,
|
||||
data: args.input,
|
||||
})
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user