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.
This commit is contained in:
@@ -59,7 +59,9 @@ export class WorkshopSubscriptionSchema extends PothosSchema {
|
||||
args: this.builder.generator.findManyArgs('WorkshopSubscription'),
|
||||
description: 'Retrieve a list of workshop subscriptions with optional filtering, ordering, and pagination.',
|
||||
resolve: async (query, _root, args, ctx) => {
|
||||
if (ctx.isSubscription) throw new Error('Workshops cannot be retrieved in subscription context')
|
||||
if (ctx.isSubscription) {
|
||||
throw new Error('Workshops cannot be retrieved in subscription context')
|
||||
}
|
||||
return await this.prisma.workshopSubscription.findMany({
|
||||
...query,
|
||||
skip: args.skip ?? undefined,
|
||||
@@ -73,8 +75,12 @@ export class WorkshopSubscriptionSchema extends PothosSchema {
|
||||
type: [this.workshopSubscription()],
|
||||
description: 'Retrieve a list of workshops that the current user is subscribed to.',
|
||||
resolve: async (query, _root, _args, ctx, _info) => {
|
||||
if (ctx.isSubscription) throw new Error('Workshops cannot be retrieved in subscription context')
|
||||
if (!ctx.http.me) throw new Error('User is not authenticated')
|
||||
if (ctx.isSubscription) {
|
||||
throw new Error('Workshops cannot be retrieved in subscription context')
|
||||
}
|
||||
if (!ctx.http.me) {
|
||||
throw new Error('User is not authenticated')
|
||||
}
|
||||
return await this.prisma.workshopSubscription.findMany({
|
||||
...query,
|
||||
where: {
|
||||
@@ -94,21 +100,31 @@ export class WorkshopSubscriptionSchema extends PothosSchema {
|
||||
}),
|
||||
},
|
||||
resolve: async (_query, _root, args, ctx) => {
|
||||
if (ctx.isSubscription) throw new Error('Not allowed in subscription')
|
||||
if (ctx.isSubscription) {
|
||||
throw new Error('Not allowed in subscription')
|
||||
}
|
||||
const userId = ctx.http.me?.id
|
||||
// retrieve the workshop
|
||||
const workshop = await this.prisma.workshop.findUnique({
|
||||
where: { id: args.workshopId },
|
||||
})
|
||||
if (!workshop) throw new Error('Workshop not found')
|
||||
if (!userId) throw new Error('User not authenticated')
|
||||
if (!workshop) {
|
||||
throw new Error('Workshop not found')
|
||||
}
|
||||
if (!userId) {
|
||||
throw new Error('User not authenticated')
|
||||
}
|
||||
// check if workshop is in the future
|
||||
if (workshop.date < DateTimeUtils.now().toJSDate()) throw new Error('Workshop has already started or is over')
|
||||
if (workshop.date < DateTimeUtils.now().toJSDate()) {
|
||||
throw new Error('Workshop has already started or is over')
|
||||
}
|
||||
// check if user is already subscribed to the workshop
|
||||
const existingSubscription = await this.prisma.workshopSubscription.findFirst({
|
||||
where: { userId, workshopId: args.workshopId },
|
||||
})
|
||||
if (existingSubscription) throw new Error('User already subscribed to workshop')
|
||||
if (existingSubscription) {
|
||||
throw new Error('User already subscribed to workshop')
|
||||
}
|
||||
// create the workshop subscription
|
||||
return await this.prisma.workshopSubscription.create({
|
||||
data: {
|
||||
|
||||
Reference in New Issue
Block a user