update subscribe to workshop

This commit is contained in:
2024-11-25 22:52:53 +07:00
parent 26dd46c7a0
commit 547947eeb8
3 changed files with 27 additions and 2 deletions

View File

@@ -38,6 +38,9 @@ export class WorkshopSubscriptionSchema extends PothosSchema {
description:
'The date and time the workshop subscription was created.',
}),
notified: t.exposeBoolean('notified', {
description: 'Whether the user has been notified about the workshop.',
}),
}),
})
}
@@ -73,5 +76,27 @@ export class WorkshopSubscriptionSchema extends PothosSchema {
},
}),
}))
this.builder.mutationFields((t) => ({
subscribeToWorkshop: t.prismaField({
type: this.workshopSubscription(),
args: {
workshopId: t.arg.string({
description: 'The ID of the workshop to subscribe to.',
required: true,
}),
},
resolve: async (_query, _root, args, ctx) => {
if (ctx.isSubscription) throw new Error('Not allowed in subscription')
const userId = ctx.http.me?.id
if (!userId) throw new Error('User not authenticated')
return await this.prisma.workshopSubscription.create({
data: {
userId,
workshopId: args.workshopId,
},
})
},
}),
}))
}
}