feat: streamline schema definitions and enhance service logic

- Refactored package.json to consolidate Jest configuration for improved readability.
- Cleaned up launch.json by removing unnecessary whitespace for better formatting.
- Updated CronService to refine service disabling logic based on recent activity, ensuring more accurate service management.
- Enhanced MeetingRoom and WorkshopMeetingRoom schemas with consistent formatting and improved field descriptions for clarity.
- Improved error handling in MeetingRoom schema to provide clearer feedback for unauthorized access and missing resources.
- Updated pothos.generated.ts to reflect recent schema changes, ensuring type consistency across the application.

These changes enhance the overall structure and maintainability of the codebase, improving service management and user experience.
This commit is contained in:
2024-12-15 21:50:32 +07:00
parent c886d9a02f
commit 07158bef3a
7 changed files with 1417 additions and 1331 deletions

View File

@@ -1,58 +1,53 @@
import { Inject, Injectable } from "@nestjs/common";
import { ChatRoomType } from "@prisma/client";
import {
Pothos,
PothosRef,
PothosSchema,
SchemaBuilderToken,
} from "@smatch-corp/nestjs-pothos";
import { Builder } from "../Graphql/graphql.builder";
import { LiveKitService } from "../LiveKit/livekit.service";
import { PrismaService } from "../Prisma/prisma.service";
import { Inject, Injectable } from '@nestjs/common'
import { ChatRoomType } from '@prisma/client'
import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
import { Builder } from '../Graphql/graphql.builder'
import { LiveKitService } from '../LiveKit/livekit.service'
import { PrismaService } from '../Prisma/prisma.service'
@Injectable()
export class WorkshopMeetingRoomSchema extends PothosSchema {
constructor(
@Inject(SchemaBuilderToken) private readonly builder: Builder,
private readonly prisma: PrismaService,
private readonly livekitService: LiveKitService
private readonly livekitService: LiveKitService,
) {
super();
super()
}
@PothosRef()
workshopMeetingRoom() {
return this.builder.prismaObject("WorkshopMeetingRoom", {
return this.builder.prismaObject('WorkshopMeetingRoom', {
fields: (t) => ({
id: t.exposeID("id", {
description: "The ID of the workshop meeting room.",
id: t.exposeID('id', {
description: 'The ID of the workshop meeting room.',
}),
workshopId: t.exposeID("workshopId", {
description: "The ID of the workshop that the meeting room is for.",
workshopId: t.exposeID('workshopId', {
description: 'The ID of the workshop that the meeting room is for.',
}),
workshop: t.relation("workshop", {
description: "The workshop that the meeting room is for.",
workshop: t.relation('workshop', {
description: 'The workshop that the meeting room is for.',
}),
}),
});
})
}
@PothosRef()
workshopMeetingRoomJoinInfo() {
return this.builder.simpleObject("WorkshopMeetingRoomJoinInfo", {
return this.builder.simpleObject('WorkshopMeetingRoomJoinInfo', {
fields: (t) => ({
id: t.string({
description: "The ID of the workshop meeting room.",
description: 'The ID of the workshop meeting room.',
}),
token: t.string({
description: "The token to join the workshop meeting room.",
description: 'The token to join the workshop meeting room.',
}),
serverUrl: t.string({
description: "The URL of the server.",
description: 'The URL of the server.',
}),
chatRoomId: t.string({
description: "The ID of the chat room.",
description: 'The ID of the chat room.',
}),
}),
});
})
}
@Pothos()
@@ -60,59 +55,56 @@ export class WorkshopMeetingRoomSchema extends PothosSchema {
this.builder.queryFields((t) => ({
workshopMeetingRoom: t.prismaField({
type: this.workshopMeetingRoom(),
args: this.builder.generator.findUniqueArgs("WorkshopMeetingRoom"),
args: this.builder.generator.findUniqueArgs('WorkshopMeetingRoom'),
resolve: async (query, _root, args, _ctx, _info) => {
return await this.prisma.workshopMeetingRoom.findUnique({
...query,
where: args.where,
});
})
},
}),
workshopMeetingRoomJoinInfo: t.field({
type: this.workshopMeetingRoomJoinInfo(),
args: {
workshopId: t.arg({
type: "String",
type: 'String',
required: true,
}),
},
resolve: async (_, args, ctx) => {
if (ctx.isSubscription) {
throw new Error("Not allowed");
throw new Error('Not allowed')
}
if (!ctx.http?.me) {
throw new Error("Unauthorized");
throw new Error('Unauthorized')
}
const meetingRoom = await this.prisma.workshopMeetingRoom.findUnique({
where: {
workshopId: args.workshopId,
},
});
})
// query chat room
const chatRoom = await this.prisma.chatRoom.findFirst({
where: {
workshopId: args.workshopId,
type: ChatRoomType.WORKSHOP,
},
});
})
if (!meetingRoom) {
throw new Error("Meeting room not found");
throw new Error('Meeting room not found')
}
const serverUrl = this.livekitService.getServerUrl();
const serverUrl = this.livekitService.getServerUrl()
return {
id: meetingRoom.id,
token: await this.livekitService.createToken(
ctx.http?.me,
meetingRoom.id
),
token: await this.livekitService.createToken(ctx.http?.me, meetingRoom.id),
serverUrl,
chatRoomId: chatRoom?.id,
};
}
},
}),
workshopMeetingRooms: t.prismaField({
type: [this.workshopMeetingRoom()],
args: this.builder.generator.findManyArgs("WorkshopMeetingRoom"),
args: this.builder.generator.findManyArgs('WorkshopMeetingRoom'),
resolve: async (query, _root, args, _ctx, _info) => {
return await this.prisma.workshopMeetingRoom.findMany({
...query,
@@ -121,9 +113,9 @@ export class WorkshopMeetingRoomSchema extends PothosSchema {
cursor: args.cursor ?? undefined,
take: args.take ?? undefined,
skip: args.skip ?? undefined,
});
})
},
}),
}));
}))
}
}