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:
2024-12-08 21:01:26 +07:00
parent 10e20092ab
commit 45dca51990
17 changed files with 430 additions and 159 deletions

View File

@@ -135,8 +135,12 @@ export class QuizSchema extends PothosSchema {
type: this.quiz(),
args: this.builder.generator.findUniqueArgs('Quiz'),
resolve: async (query, _root, args, ctx, _info) => {
if (ctx.isSubscription) throw new Error('Subscription is not allowed')
if (!ctx.http.me) throw new Error('User is not authenticated')
if (ctx.isSubscription) {
throw new Error('Subscription is not allowed')
}
if (!ctx.http.me) {
throw new Error('User is not authenticated')
}
return await this.prisma.quiz.findUnique({ ...query, where: { id: args.where.id } })
},
}),
@@ -144,8 +148,12 @@ export class QuizSchema extends PothosSchema {
type: [this.quiz()],
args: this.builder.generator.findManyArgs('Quiz'),
resolve: async (query, _root, args, ctx, _info) => {
if (ctx.isSubscription) throw new Error('Subscription is not allowed')
if (!ctx.http.me) throw new Error('User is not authenticated')
if (ctx.isSubscription) {
throw new Error('Subscription is not allowed')
}
if (!ctx.http.me) {
throw new Error('User is not authenticated')
}
return await this.prisma.quiz.findMany({
...query,
where: args.filter ?? undefined,
@@ -167,9 +175,15 @@ export class QuizSchema extends PothosSchema {
}),
},
resolve: async (query, _root, args, ctx, _info) => {
if (ctx.isSubscription) throw new Error('Subscription is not allowed')
if (!ctx.http.me) throw new Error('User is not authenticated')
if (!args.data) throw new Error('Data is required')
if (ctx.isSubscription) {
throw new Error('Subscription is not allowed')
}
if (!ctx.http.me) {
throw new Error('User is not authenticated')
}
if (!args.data) {
throw new Error('Data is required')
}
return await this.prisma.quiz.create({
...query,
@@ -193,8 +207,12 @@ export class QuizSchema extends PothosSchema {
}),
},
resolve: async (query, _root, args, ctx, _info) => {
if (ctx.isSubscription) throw new Error('Subscription is not allowed')
if (!ctx.http.me) throw new Error('User is not authenticated')
if (ctx.isSubscription) {
throw new Error('Subscription is not allowed')
}
if (!ctx.http.me) {
throw new Error('User is not authenticated')
}
return await this.prisma.quiz.update({
...query,
where: args.where,
@@ -218,15 +236,25 @@ export class QuizSchema extends PothosSchema {
}),
},
resolve: async (query, _root, args, ctx, _info) => {
if (ctx.isSubscription) throw new Error('Subscription is not allowed')
if (!ctx.http.me) throw new Error('User is not authenticated')
if (!args.data) throw new Error('Data is required')
if (!args.data.quiz?.connect?.id) throw new Error('Quiz ID is required')
if (ctx.isSubscription) {
throw new Error('Subscription is not allowed')
}
if (!ctx.http.me) {
throw new Error('User is not authenticated')
}
if (!args.data) {
throw new Error('Data is required')
}
if (!args.data.quiz?.connect?.id) {
throw new Error('Quiz ID is required')
}
// query the quiz to get the questions
const quiz = await this.prisma.quiz.findUnique({
where: { id: args.data.quiz.connect.id },
})
if (!quiz) throw new Error('Quiz not found')
if (!quiz) {
throw new Error('Quiz not found')
}
return await this.prisma.quizAttempt.create({
...query,
data: {