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:
@@ -90,10 +90,16 @@ export class ServiceFeedbackSchema extends PothosSchema {
|
||||
},
|
||||
description: 'Create a new service feedback.',
|
||||
resolve: async (_, _root, args, ctx, _info) => {
|
||||
if (ctx.isSubscription) throw new Error('Not allowed')
|
||||
if (!ctx.http?.me) throw new Error('Unauthorized')
|
||||
if (ctx.isSubscription) {
|
||||
throw new Error('Not allowed')
|
||||
}
|
||||
if (!ctx.http?.me) {
|
||||
throw new Error('Unauthorized')
|
||||
}
|
||||
// allow only when user is CUSTOMER and order is completed
|
||||
if (ctx.http?.me?.role !== Role.CUSTOMER) throw new Error('Unauthorized')
|
||||
if (ctx.http?.me?.role !== Role.CUSTOMER) {
|
||||
throw new Error('Unauthorized')
|
||||
}
|
||||
Logger.log(`args: ${JSON.stringify(args)}`)
|
||||
const order = await this.prisma.order.findFirst({
|
||||
where: {
|
||||
@@ -109,13 +115,23 @@ export class ServiceFeedbackSchema extends PothosSchema {
|
||||
},
|
||||
},
|
||||
})
|
||||
if (!order) throw new Error('Order not found')
|
||||
if (order.userId !== ctx.http?.me?.id) throw new Error('Unauthorized')
|
||||
if (order.status !== OrderStatus.PAID) throw new Error('Order not completed')
|
||||
if (!order) {
|
||||
throw new Error('Order not found')
|
||||
}
|
||||
if (order.userId !== ctx.http?.me?.id) {
|
||||
throw new Error('Unauthorized')
|
||||
}
|
||||
if (order.status !== OrderStatus.PAID) {
|
||||
throw new Error('Order not completed')
|
||||
}
|
||||
// validate rating
|
||||
if (args.rating < 0 || args.rating > 5) throw new Error('Invalid rating')
|
||||
if (args.rating < 0 || args.rating > 5) {
|
||||
throw new Error('Invalid rating')
|
||||
}
|
||||
// validate comments
|
||||
if (args.comments && args.comments.length > 1024) throw new Error('Comments too long')
|
||||
if (args.comments && args.comments.length > 1024) {
|
||||
throw new Error('Comments too long')
|
||||
}
|
||||
return await this.prisma.serviceFeedback.create({
|
||||
data: {
|
||||
userId: ctx.http?.me?.id,
|
||||
|
||||
Reference in New Issue
Block a user