chore: combine context

This commit is contained in:
2024-12-20 18:30:50 +07:00
parent 461f2653e3
commit 776881f961
23 changed files with 532 additions and 694 deletions

View File

@@ -65,10 +65,7 @@ export class PersonalMilestoneSchema extends PothosSchema {
args: this.builder.generator.findUniqueArgs('PersonalMilestone'),
description: 'Retrieve a single personal milestone by its unique identifier.',
resolve: async (_query, _root, args, ctx, _info) => {
if (ctx.isSubscription) {
throw new Error('Not allowed')
}
if (!ctx.http.me) {
if (!ctx.me) {
throw new Error('Cannot get your info')
}
return this.prisma.personalMilestone.findUnique({
@@ -81,10 +78,7 @@ export class PersonalMilestoneSchema extends PothosSchema {
args: this.builder.generator.findManyArgs('PersonalMilestone'),
description: 'Retrieve multiple personal milestones.',
resolve: async (_query, _root, args, ctx, _info) => {
if (ctx.isSubscription) {
throw new Error('Not allowed')
}
if (!ctx.http.me) {
if (!ctx.me) {
throw new Error('Cannot get your info')
}
return this.prisma.personalMilestone.findMany({
@@ -119,13 +113,10 @@ export class PersonalMilestoneSchema extends PothosSchema {
},
description: 'Create multiple personal milestones.',
resolve: async (_query, _root, args, ctx, _info) => {
if (ctx.isSubscription) {
throw new Error('Not allowed')
}
if (!ctx.http.me) {
if (!ctx.me) {
throw new Error('Cannot get your info')
}
const userId = ctx.http.me.id
const userId = ctx.me.id
const result = await this.prisma.personalMilestone.createManyAndReturn({
data: args.data.map((data) => ({
...data,
@@ -158,13 +149,10 @@ export class PersonalMilestoneSchema extends PothosSchema {
},
description: 'Update a personal milestone.',
resolve: async (_query, _root, args, ctx, _info) => {
if (ctx.isSubscription) {
throw new Error('Not allowed')
}
if (!ctx.http.me) {
if (!ctx.me) {
throw new Error('Cannot get your info')
}
const userId = ctx.http.me.id
const userId = ctx.me.id
return this.prisma.personalMilestone.update({
where: {
...args.where,
@@ -185,10 +173,7 @@ export class PersonalMilestoneSchema extends PothosSchema {
},
description: 'Delete a personal milestone.',
resolve: async (_query, _root, args, ctx, _info) => {
if (ctx.isSubscription) {
throw new Error('Not allowed')
}
if (!ctx.http.me) {
if (!ctx.me) {
throw new Error('Cannot get your info')
}
// check if the user is mentor of the schedule where the personal milestone belongs to
@@ -202,7 +187,7 @@ export class PersonalMilestoneSchema extends PothosSchema {
const managedService = await this.prisma.managedService.findUnique({
where: { id: schedule.managedServiceId },
})
if (managedService?.mentorId !== ctx.http.me.id) {
if (managedService?.mentorId !== ctx.me.id) {
throw new Error('Unauthorized')
}
}