implement cron mechanic for refund strageries and make workshop reliable

This commit is contained in:
2024-11-26 17:31:40 +07:00
parent 830c9ce3f6
commit 3ac8c3fd39
3 changed files with 70 additions and 27 deletions

View File

@@ -3,6 +3,7 @@ import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-cor
import { Builder } from '../Graphql/graphql.builder'
import { PrismaService } from '../Prisma/prisma.service'
import { MinioService } from 'src/Minio/minio.service'
import { Role } from '@prisma/client'
@Injectable()
export class WorkshopSchema extends PothosSchema {
@@ -115,7 +116,7 @@ export class WorkshopSchema extends PothosSchema {
type: this.workshop(),
args: {
input: t.arg({
type: this.builder.generator.getCreateInput('Workshop'),
type: this.builder.generator.getCreateInput('Workshop', ['workshopMeetingRoom']),
required: true,
}),
},
@@ -123,11 +124,25 @@ export class WorkshopSchema extends PothosSchema {
resolve: async (query, _root, args, ctx, _info) => {
if (ctx.isSubscription) throw new Error('Workshops cannot be created in subscription context')
if (!ctx.http.me) throw new Error('User is not authenticated to create a workshop')
if (ctx.http.me.role !== Role.CENTER_OWNER) throw new Error('Only center owners can create workshops')
if (!args.input.service.connect) throw new Error('Service is required to create a workshop')
// check if service is active
const service = await this.prisma.service.findUnique({
where: { id: args.input.service.connect.id },
})
if (!service || !service.isActive) throw new Error('Service is not active')
return await this.prisma.workshop.create({
const workshop = await this.prisma.workshop.create({
...query,
data: args.input,
})
// create workshop meeting room
await this.prisma.workshopMeetingRoom.create({
data: {
workshopId: workshop.id,
},
})
return workshop
},
}),