Files
epess-web-backend/src/PersonalMilestone/personalmilestone.schema.ts
Ly Tuan Kiet 45dca51990 chore: update biome configuration and enhance error handling in schema files
- Enabled useIgnoreFile in biome.json for better file management.
- Updated various correctness and style rules in biome.json to enforce stricter coding standards.
- Added new biome lint command in package.json for improved code quality checks.
- Refactored error handling in multiple schema files to use consistent error throwing patterns, enhancing readability and maintainability.
- Improved user authentication checks across various schemas to ensure proper access control.
2024-12-08 21:01:26 +07:00

102 lines
3.6 KiB
TypeScript

import { Inject, Injectable, Logger } from '@nestjs/common'
import { PersonalMilestoneStatus } from '@prisma/client'
import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
import { Builder } from '../Graphql/graphql.builder'
import { PrismaService } from '../Prisma/prisma.service'
@Injectable()
export class PersonalMilestoneSchema extends PothosSchema {
constructor(
@Inject(SchemaBuilderToken) private readonly builder: Builder,
private readonly prisma: PrismaService,
) {
super()
}
@PothosRef()
personalMilestone() {
return this.builder.prismaObject('PersonalMilestone', {
fields: (t) => ({
id: t.exposeID('id', {
description: 'The ID of the personal milestone.',
}),
milestoneOrder: t.exposeInt('milestoneOrder', {
description: 'The order of the personal milestone.',
}),
scheduleId: t.exposeString('scheduleId', {
description: 'The ID of the schedule the personal milestone belongs to.',
}),
schedule: t.relation('schedule', {
description: 'The schedule the personal milestone belongs to.',
}),
userId: t.exposeString('userId', {
description: 'The ID of the user the personal milestone belongs to.',
}),
user: t.relation('user', {
description: 'The user the personal milestone belongs to.',
}),
title: t.exposeString('title', {
description: 'The title of the personal milestone.',
}),
description: t.exposeString('description', {
description: 'The description of the personal milestone.',
}),
status: t.expose('status', {
type: PersonalMilestoneStatus,
description: 'The status of the personal milestone.',
}),
createdAt: t.expose('createdAt', {
type: 'DateTime',
description: 'The date the personal milestone was created.',
}),
updatedAt: t.expose('updatedAt', {
type: 'DateTime',
description: 'The date the personal milestone was last updated.',
}),
}),
})
}
@Pothos()
init(): void {
this.builder.queryFields((t) => ({
personalMilestone: t.prismaField({
type: this.personalMilestone(),
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) {
throw new Error('Cannot get your info')
}
return this.prisma.personalMilestone.findUnique({
where: args.where,
})
},
}),
personalMilestones: t.prismaField({
type: [this.personalMilestone()],
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) {
throw new Error('Cannot get your info')
}
return this.prisma.personalMilestone.findMany({
where: args.filter ?? undefined,
orderBy: args.orderBy ?? undefined,
skip: args.skip ?? undefined,
take: args.take ?? undefined,
cursor: args.cursor ?? undefined,
})
},
}),
}))
}
}