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:
@@ -73,14 +73,20 @@ export class CollaborationSessionSchema extends PothosSchema {
|
||||
},
|
||||
description: 'Retrieve a single collaboration session 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')
|
||||
if (ctx.isSubscription) {
|
||||
throw new Error('Not allowed')
|
||||
}
|
||||
if (!ctx.http.me) {
|
||||
throw new Error('Cannot get your info')
|
||||
}
|
||||
const scheduleDate = await this.prisma.scheduleDate.findUnique({
|
||||
where: {
|
||||
id: args.scheduleDateId,
|
||||
},
|
||||
})
|
||||
if (!scheduleDate) throw new Error('Schedule date not found')
|
||||
if (!scheduleDate) {
|
||||
throw new Error('Schedule date not found')
|
||||
}
|
||||
let collaborationSession: CollaborationSession | null = null
|
||||
collaborationSession = await this.prisma.collaborationSession.findUnique({
|
||||
where: {
|
||||
@@ -90,7 +96,9 @@ export class CollaborationSessionSchema extends PothosSchema {
|
||||
/* ---------- use case 1 : customer get collaboration session by id --------- */
|
||||
if (ctx.http.me?.role === Role.CUSTOMER && collaborationSession) {
|
||||
// check if user is participant
|
||||
if (!collaborationSession.collaboratorsIds.includes(ctx.http.me.id)) throw new Error('User not allowed')
|
||||
if (!collaborationSession.collaboratorsIds.includes(ctx.http.me.id)) {
|
||||
throw new Error('User not allowed')
|
||||
}
|
||||
// update schedule date status
|
||||
await this.prisma.scheduleDate.update({
|
||||
where: {
|
||||
@@ -104,20 +112,30 @@ export class CollaborationSessionSchema extends PothosSchema {
|
||||
}
|
||||
/* ---------- use case 2 : center mentor get collaboration session by schedule date id --------- */
|
||||
if (ctx.http.me.role !== Role.CENTER_MENTOR && ctx.http.me.role !== Role.CENTER_OWNER) {
|
||||
if (!collaborationSession) throw new Error('Mentor does not created collaboration session yet')
|
||||
if (!collaborationSession) {
|
||||
throw new Error('Mentor does not created collaboration session yet')
|
||||
}
|
||||
throw new Error('User not allowed')
|
||||
}
|
||||
// check if user is participant
|
||||
if (!scheduleDate.participantIds.includes(ctx.http.me.id)) throw new Error('User not allowed')
|
||||
if (!scheduleDate.participantIds.includes(ctx.http.me.id)) {
|
||||
throw new Error('User not allowed')
|
||||
}
|
||||
// check if order is exist in schedule date
|
||||
if (!scheduleDate.orderId) throw new Error('Order not found')
|
||||
if (!scheduleDate.orderId) {
|
||||
throw new Error('Order not found')
|
||||
}
|
||||
const order = await this.prisma.order.findUnique({
|
||||
where: {
|
||||
id: scheduleDate.orderId,
|
||||
},
|
||||
})
|
||||
if (!order) throw new Error('Order not found')
|
||||
if (!order.chatRoomId) throw new Error('Order chat room not found')
|
||||
if (!order) {
|
||||
throw new Error('Order not found')
|
||||
}
|
||||
if (!order.chatRoomId) {
|
||||
throw new Error('Order chat room not found')
|
||||
}
|
||||
// only in time before 10 minutes from start time or less and not after end time can create new collaboration session
|
||||
const now = DateTimeUtils.now()
|
||||
const startTime = DateTimeUtils.fromDate(scheduleDate.start)
|
||||
@@ -135,7 +153,9 @@ export class CollaborationSessionSchema extends PothosSchema {
|
||||
id: order.chatRoomId,
|
||||
},
|
||||
})
|
||||
if (!chatRoom) throw new Error('Chat room not found')
|
||||
if (!chatRoom) {
|
||||
throw new Error('Chat room not found')
|
||||
}
|
||||
// create new one
|
||||
Logger.log(`chatRoom: ${chatRoom.id}`)
|
||||
const newCollaborationSession = await this.prisma.collaborationSession.create({
|
||||
@@ -198,21 +218,29 @@ export class CollaborationSessionSchema extends PothosSchema {
|
||||
liveKitToken: t.field({
|
||||
type: 'String',
|
||||
resolve: async (_, _args, ctx: SchemaContext) => {
|
||||
if (ctx.isSubscription) throw new Error('Not allowed')
|
||||
if (!ctx.http?.me?.id) throw new Error('User not found')
|
||||
if (ctx.isSubscription) {
|
||||
throw new Error('Not allowed')
|
||||
}
|
||||
if (!ctx.http?.me?.id) {
|
||||
throw new Error('User not found')
|
||||
}
|
||||
// check if participantId is in meetingRoomCollaborators
|
||||
const meetingRoomCollaborator = await this.prisma.meetingRoomCollaborator.findFirst({
|
||||
where: {
|
||||
userId: ctx.http.me.id,
|
||||
},
|
||||
})
|
||||
if (!meetingRoomCollaborator) throw new Error('Meeting room collaborator not found')
|
||||
if (!meetingRoomCollaborator) {
|
||||
throw new Error('Meeting room collaborator not found')
|
||||
}
|
||||
const meetingRoom = await this.prisma.meetingRoom.findUnique({
|
||||
where: {
|
||||
id: meetingRoomCollaborator.meetingRoomId,
|
||||
},
|
||||
})
|
||||
if (!meetingRoom) throw new Error('Meeting room not found')
|
||||
if (!meetingRoom) {
|
||||
throw new Error('Meeting room not found')
|
||||
}
|
||||
const token = await this.liveKitService.createToken(ctx.http.me, meetingRoom.id)
|
||||
return token
|
||||
},
|
||||
@@ -235,8 +263,12 @@ export class CollaborationSessionSchema extends PothosSchema {
|
||||
},
|
||||
description: 'Update the active document ID for a collaboration session.',
|
||||
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')
|
||||
if (ctx.isSubscription) {
|
||||
throw new Error('Not allowed')
|
||||
}
|
||||
if (!ctx.http.me) {
|
||||
throw new Error('Cannot get your info')
|
||||
}
|
||||
// check permission
|
||||
const collaborationSession = await this.prisma.collaborationSession.findUnique({
|
||||
where: {
|
||||
@@ -246,9 +278,12 @@ export class CollaborationSessionSchema extends PothosSchema {
|
||||
scheduleDate: true,
|
||||
},
|
||||
})
|
||||
if (!collaborationSession) throw new Error('Collaboration session not found')
|
||||
if (!collaborationSession.scheduleDate.participantIds.includes(ctx.http.me.id))
|
||||
if (!collaborationSession) {
|
||||
throw new Error('Collaboration session not found')
|
||||
}
|
||||
if (!collaborationSession.scheduleDate.participantIds.includes(ctx.http.me.id)) {
|
||||
throw new Error('User not allowed')
|
||||
}
|
||||
const updatedCollaborationSession = await this.prisma.collaborationSession.update({
|
||||
where: {
|
||||
id: args.collaborationSessionId,
|
||||
@@ -275,14 +310,20 @@ export class CollaborationSessionSchema extends PothosSchema {
|
||||
}),
|
||||
},
|
||||
subscribe: async (_parent, args, ctx) => {
|
||||
if (!ctx.isSubscription) throw new Error('Not allowed')
|
||||
if (!ctx.websocket.me) throw new Error('Cannot get your info')
|
||||
if (!ctx.isSubscription) {
|
||||
throw new Error('Not allowed')
|
||||
}
|
||||
if (!ctx.websocket.me) {
|
||||
throw new Error('Cannot get your info')
|
||||
}
|
||||
const collaborationSession = await this.prisma.collaborationSession.findUnique({
|
||||
where: {
|
||||
id: args.collaborationSessionId,
|
||||
},
|
||||
})
|
||||
if (!collaborationSession) throw new Error('Collaboration session not found')
|
||||
if (!collaborationSession) {
|
||||
throw new Error('Collaboration session not found')
|
||||
}
|
||||
return ctx.websocket.pubSub.asyncIterableIterator(`collaborationSessionUpdated:${collaborationSession.id}`)
|
||||
},
|
||||
resolve: async (payload: CollaborationSession) => payload,
|
||||
|
||||
Reference in New Issue
Block a user