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:
1
.vscode/launch.json
vendored
1
.vscode/launch.json
vendored
@@ -4,7 +4,6 @@
|
|||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "Attach by Process ID",
|
"name": "Attach by Process ID",
|
||||||
"processId": "${command:PickProcess}",
|
"processId": "${command:PickProcess}",
|
||||||
|
|||||||
10
package.json
10
package.json
@@ -140,19 +140,13 @@
|
|||||||
"@css-inline/css-inline-linux-x64-musl": "^0.14.3"
|
"@css-inline/css-inline-linux-x64-musl": "^0.14.3"
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
"moduleFileExtensions": [
|
"moduleFileExtensions": ["js", "json", "ts"],
|
||||||
"js",
|
|
||||||
"json",
|
|
||||||
"ts"
|
|
||||||
],
|
|
||||||
"rootDir": "src",
|
"rootDir": "src",
|
||||||
"testRegex": ".*\\.spec\\.ts$",
|
"testRegex": ".*\\.spec\\.ts$",
|
||||||
"transform": {
|
"transform": {
|
||||||
"^.+\\.(t|j)s$": "ts-jest"
|
"^.+\\.(t|j)s$": "ts-jest"
|
||||||
},
|
},
|
||||||
"collectCoverageFrom": [
|
"collectCoverageFrom": ["**/*.(t|j)s"],
|
||||||
"**/*.(t|j)s"
|
|
||||||
],
|
|
||||||
"coverageDirectory": "../coverage",
|
"coverageDirectory": "../coverage",
|
||||||
"testEnvironment": "node"
|
"testEnvironment": "node"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -161,22 +161,30 @@ export class CronService {
|
|||||||
async taskDisableServiceWithoutSchedule() {
|
async taskDisableServiceWithoutSchedule() {
|
||||||
const services = await this.prisma.service.findMany({
|
const services = await this.prisma.service.findMany({
|
||||||
where: {
|
where: {
|
||||||
NOT: {
|
status: ServiceStatus.APPROVED,
|
||||||
// check if service has any schedule in the past 30 days
|
AND: [
|
||||||
managedService: {
|
{
|
||||||
some: {
|
managedService: {
|
||||||
schedule: {
|
none: {
|
||||||
some: {
|
schedule: {
|
||||||
scheduleStart: { gte: DateTimeUtils.now().minus({ days: 30 }).toJSDate() },
|
some: {
|
||||||
|
scheduleStart: {
|
||||||
|
gte: DateTimeUtils.now().minus({ minutes: 10 }).toJSDate(),
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// and createdAt is more than 3 days ago
|
{
|
||||||
createdAt: {
|
createdAt: {
|
||||||
lt: DateTimeUtils.now().minus({ days: 3 }).toJSDate(),
|
lt: DateTimeUtils.now().minus({ days: 3 }).toJSDate(),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
],
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
managedService: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -187,7 +195,10 @@ export class CronService {
|
|||||||
status: ServiceStatus.INACTIVE,
|
status: ServiceStatus.INACTIVE,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
Logger.log(`Service ${service.id} has been disabled`, 'CronService')
|
Logger.log(
|
||||||
|
`Service ${service.id} has been disabled due to inactivity. Managed Services: ${service.managedService.length}`,
|
||||||
|
'CronService',
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,72 +1,67 @@
|
|||||||
import { Inject, Injectable, Logger } from "@nestjs/common";
|
import { Inject, Injectable, Logger } from '@nestjs/common'
|
||||||
import {
|
import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
|
||||||
Pothos,
|
import { Builder, SchemaContext } from 'src/Graphql/graphql.builder'
|
||||||
PothosRef,
|
import { LiveKitService } from 'src/LiveKit/livekit.service'
|
||||||
PothosSchema,
|
import { MinioService } from 'src/Minio/minio.service'
|
||||||
SchemaBuilderToken,
|
import { PrismaService } from 'src/Prisma/prisma.service'
|
||||||
} from "@smatch-corp/nestjs-pothos";
|
|
||||||
import { Builder, SchemaContext } from "src/Graphql/graphql.builder";
|
|
||||||
import { LiveKitService } from "src/LiveKit/livekit.service";
|
|
||||||
import { MinioService } from "src/Minio/minio.service";
|
|
||||||
import { PrismaService } from "src/Prisma/prisma.service";
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MeetingRoomSchema extends PothosSchema {
|
export class MeetingRoomSchema extends PothosSchema {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||||
private readonly prisma: PrismaService,
|
private readonly prisma: PrismaService,
|
||||||
private readonly livekitService: LiveKitService,
|
private readonly livekitService: LiveKitService,
|
||||||
private readonly minioService: MinioService
|
private readonly minioService: MinioService,
|
||||||
) {
|
) {
|
||||||
super();
|
super()
|
||||||
}
|
}
|
||||||
@PothosRef()
|
@PothosRef()
|
||||||
meetingRoom() {
|
meetingRoom() {
|
||||||
return this.builder.prismaObject("MeetingRoom", {
|
return this.builder.prismaObject('MeetingRoom', {
|
||||||
fields: (t) => ({
|
fields: (t) => ({
|
||||||
id: t.exposeID("id"),
|
id: t.exposeID('id'),
|
||||||
collaborationSessionId: t.exposeString("collaborationSessionId"),
|
collaborationSessionId: t.exposeString('collaborationSessionId'),
|
||||||
collaborationSession: t.relation("collaborationSession"),
|
collaborationSession: t.relation('collaborationSession'),
|
||||||
collaborators: t.relation("collaborators"),
|
collaborators: t.relation('collaborators'),
|
||||||
createdAt: t.expose("createdAt", { type: "DateTime" }),
|
createdAt: t.expose('createdAt', { type: 'DateTime' }),
|
||||||
updatedAt: t.expose("updatedAt", { type: "DateTime" }),
|
updatedAt: t.expose('updatedAt', { type: 'DateTime' }),
|
||||||
recordUrl: t.string({
|
recordUrl: t.string({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
resolve: async (meetingRoom) => {
|
resolve: async (meetingRoom) => {
|
||||||
return await this.minioService.getRoomRecordUrl(meetingRoom.id);
|
return await this.minioService.getRoomRecordUrl(meetingRoom.id)
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@PothosRef()
|
@PothosRef()
|
||||||
meetingRoomJoinInfo() {
|
meetingRoomJoinInfo() {
|
||||||
return this.builder.simpleObject("MeetingRoomJoinInfo", {
|
return this.builder.simpleObject('MeetingRoomJoinInfo', {
|
||||||
fields: (t) => ({
|
fields: (t) => ({
|
||||||
id: t.string({
|
id: t.string({
|
||||||
description: "The ID of the meeting room.",
|
description: 'The ID of the meeting room.',
|
||||||
}),
|
}),
|
||||||
token: t.string({
|
token: t.string({
|
||||||
description: "The token to join the meeting room.",
|
description: 'The token to join the meeting room.',
|
||||||
}),
|
}),
|
||||||
serverUrl: t.string({
|
serverUrl: t.string({
|
||||||
description: "The URL of the server.",
|
description: 'The URL of the server.',
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@PothosRef()
|
@PothosRef()
|
||||||
meetingRoomCollaborator() {
|
meetingRoomCollaborator() {
|
||||||
return this.builder.prismaObject("MeetingRoomCollaborator", {
|
return this.builder.prismaObject('MeetingRoomCollaborator', {
|
||||||
fields: (t) => ({
|
fields: (t) => ({
|
||||||
id: t.exposeID("id"),
|
id: t.exposeID('id'),
|
||||||
meetingRoomId: t.exposeString("meetingRoomId"),
|
meetingRoomId: t.exposeString('meetingRoomId'),
|
||||||
meetingRoom: t.relation("meetingRoom"),
|
meetingRoom: t.relation('meetingRoom'),
|
||||||
userId: t.exposeString("userId"),
|
userId: t.exposeString('userId'),
|
||||||
user: t.relation("user"),
|
user: t.relation('user'),
|
||||||
}),
|
}),
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@Pothos()
|
@Pothos()
|
||||||
@@ -82,30 +77,29 @@ export class MeetingRoomSchema extends PothosSchema {
|
|||||||
},
|
},
|
||||||
resolve: async (_query, _parent, args, ctx: SchemaContext) => {
|
resolve: async (_query, _parent, args, ctx: SchemaContext) => {
|
||||||
if (ctx.isSubscription) {
|
if (ctx.isSubscription) {
|
||||||
throw new Error("Not allowed");
|
throw new Error('Not allowed')
|
||||||
}
|
}
|
||||||
const collaborationSession =
|
const collaborationSession = await this.prisma.collaborationSession.findUnique({
|
||||||
await this.prisma.collaborationSession.findUnique({
|
where: {
|
||||||
where: {
|
scheduleDateId: args.scheduleDateId,
|
||||||
scheduleDateId: args.scheduleDateId,
|
},
|
||||||
},
|
})
|
||||||
});
|
|
||||||
if (!collaborationSession) {
|
if (!collaborationSession) {
|
||||||
throw new Error("Collaboration session not found");
|
throw new Error('Collaboration session not found')
|
||||||
}
|
}
|
||||||
const meetingRoom = await this.prisma.meetingRoom.findUnique({
|
const meetingRoom = await this.prisma.meetingRoom.findUnique({
|
||||||
where: {
|
where: {
|
||||||
collaborationSessionId: collaborationSession.id,
|
collaborationSessionId: collaborationSession.id,
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
if (meetingRoom) {
|
if (meetingRoom) {
|
||||||
return meetingRoom;
|
return meetingRoom
|
||||||
}
|
}
|
||||||
return await this.prisma.meetingRoom.create({
|
return await this.prisma.meetingRoom.create({
|
||||||
data: {
|
data: {
|
||||||
collaborationSessionId: collaborationSession.id,
|
collaborationSessionId: collaborationSession.id,
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
// get meeting room info by room id and check if user is collaborator of collaboration session then create new token and return it,
|
// get meeting room info by room id and check if user is collaborator of collaboration session then create new token and return it,
|
||||||
@@ -119,38 +113,34 @@ export class MeetingRoomSchema extends PothosSchema {
|
|||||||
},
|
},
|
||||||
resolve: async (_, args, ctx: SchemaContext) => {
|
resolve: async (_, args, ctx: SchemaContext) => {
|
||||||
if (ctx.isSubscription) {
|
if (ctx.isSubscription) {
|
||||||
throw new Error("Not allowed");
|
throw new Error('Not allowed')
|
||||||
}
|
}
|
||||||
if (!ctx.http.me) {
|
if (!ctx.http.me) {
|
||||||
throw new Error("Unauthorized");
|
throw new Error('Unauthorized')
|
||||||
}
|
}
|
||||||
const meetingRoom = await this.prisma.meetingRoom.findUnique({
|
const meetingRoom = await this.prisma.meetingRoom.findUnique({
|
||||||
where: { collaborationSessionId: args.collaborationSessionId },
|
where: { collaborationSessionId: args.collaborationSessionId },
|
||||||
});
|
})
|
||||||
if (!meetingRoom) {
|
if (!meetingRoom) {
|
||||||
throw new Error("Meeting room not found");
|
throw new Error('Meeting room not found')
|
||||||
}
|
}
|
||||||
// check if user is collaborator of collaboration session
|
// check if user is collaborator of collaboration session
|
||||||
const collaborationSession =
|
const collaborationSession = await this.prisma.collaborationSession.findUnique({
|
||||||
await this.prisma.collaborationSession.findUnique({
|
where: { id: meetingRoom.collaborationSessionId },
|
||||||
where: { id: meetingRoom.collaborationSessionId },
|
})
|
||||||
});
|
|
||||||
if (!collaborationSession) {
|
if (!collaborationSession) {
|
||||||
throw new Error("Collaboration session not found");
|
throw new Error('Collaboration session not found')
|
||||||
}
|
}
|
||||||
if (!collaborationSession.collaboratorsIds.includes(ctx.http.me.id)) {
|
if (!collaborationSession.collaboratorsIds.includes(ctx.http.me.id)) {
|
||||||
throw new Error("User is not collaborator");
|
throw new Error('User is not collaborator')
|
||||||
}
|
}
|
||||||
// create new token
|
// create new token
|
||||||
const token = await this.livekitService.createToken(
|
const token = await this.livekitService.createToken(ctx.http.me, meetingRoom.id)
|
||||||
ctx.http.me,
|
|
||||||
meetingRoom.id
|
|
||||||
);
|
|
||||||
return {
|
return {
|
||||||
id: meetingRoom.id,
|
id: meetingRoom.id,
|
||||||
token,
|
token,
|
||||||
serverUrl: this.livekitService.getServerUrl(),
|
serverUrl: this.livekitService.getServerUrl(),
|
||||||
};
|
}
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
interviewJoinInfo: t.field({
|
interviewJoinInfo: t.field({
|
||||||
@@ -162,48 +152,45 @@ export class MeetingRoomSchema extends PothosSchema {
|
|||||||
},
|
},
|
||||||
resolve: async (_, args, ctx: SchemaContext) => {
|
resolve: async (_, args, ctx: SchemaContext) => {
|
||||||
if (ctx.isSubscription) {
|
if (ctx.isSubscription) {
|
||||||
throw new Error("Not allowed");
|
throw new Error('Not allowed')
|
||||||
}
|
}
|
||||||
if (!ctx.http.me) {
|
if (!ctx.http.me) {
|
||||||
throw new Error("Unauthorized");
|
throw new Error('Unauthorized')
|
||||||
}
|
}
|
||||||
const token = await this.livekitService.createToken(
|
const token = await this.livekitService.createToken(ctx.http.me, args.scheduleId)
|
||||||
ctx.http.me,
|
|
||||||
args.scheduleId
|
|
||||||
);
|
|
||||||
return {
|
return {
|
||||||
id: args.scheduleId,
|
id: args.scheduleId,
|
||||||
token,
|
token,
|
||||||
serverUrl: this.livekitService.getServerUrl(),
|
serverUrl: this.livekitService.getServerUrl(),
|
||||||
};
|
}
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
}));
|
}))
|
||||||
this.builder.mutationFields((t) => ({
|
this.builder.mutationFields((t) => ({
|
||||||
createMeetingRoom: t.prismaField({
|
createMeetingRoom: t.prismaField({
|
||||||
type: this.meetingRoom(),
|
type: this.meetingRoom(),
|
||||||
args: {
|
args: {
|
||||||
input: t.arg({
|
input: t.arg({
|
||||||
type: this.builder.generator.getCreateInput("MeetingRoom", [
|
type: this.builder.generator.getCreateInput('MeetingRoom', [
|
||||||
"id",
|
'id',
|
||||||
"createdAt",
|
'createdAt',
|
||||||
"updatedAt",
|
'updatedAt',
|
||||||
"collaborators",
|
'collaborators',
|
||||||
]),
|
]),
|
||||||
required: true,
|
required: true,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
resolve: async (query, _parent, args, ctx: SchemaContext) => {
|
resolve: async (query, _parent, args, ctx: SchemaContext) => {
|
||||||
if (ctx.isSubscription) {
|
if (ctx.isSubscription) {
|
||||||
throw new Error("Not allowed");
|
throw new Error('Not allowed')
|
||||||
}
|
}
|
||||||
if (!ctx.http.me) {
|
if (!ctx.http.me) {
|
||||||
throw new Error("Unauthorized");
|
throw new Error('Unauthorized')
|
||||||
}
|
}
|
||||||
return await this.prisma.meetingRoom.create({
|
return await this.prisma.meetingRoom.create({
|
||||||
...query,
|
...query,
|
||||||
data: args.input,
|
data: args.input,
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
updateMeetingRoomCollaborators: t.prismaField({
|
updateMeetingRoomCollaborators: t.prismaField({
|
||||||
@@ -221,10 +208,10 @@ export class MeetingRoomSchema extends PothosSchema {
|
|||||||
},
|
},
|
||||||
resolve: async (query, _parent, args, ctx: SchemaContext) => {
|
resolve: async (query, _parent, args, ctx: SchemaContext) => {
|
||||||
if (ctx.isSubscription) {
|
if (ctx.isSubscription) {
|
||||||
throw new Error("Not allowed");
|
throw new Error('Not allowed')
|
||||||
}
|
}
|
||||||
if (!ctx.http.me) {
|
if (!ctx.http.me) {
|
||||||
throw new Error("Unauthorized");
|
throw new Error('Unauthorized')
|
||||||
}
|
}
|
||||||
return await this.prisma.meetingRoom.update({
|
return await this.prisma.meetingRoom.update({
|
||||||
...query,
|
...query,
|
||||||
@@ -234,9 +221,7 @@ export class MeetingRoomSchema extends PothosSchema {
|
|||||||
data: {
|
data: {
|
||||||
collaborators: {
|
collaborators: {
|
||||||
createMany: {
|
createMany: {
|
||||||
data: args.addCollaborators
|
data: args.addCollaborators ? args.addCollaborators.map((id) => ({ userId: id })) : [],
|
||||||
? args.addCollaborators.map((id) => ({ userId: id }))
|
|
||||||
: [],
|
|
||||||
},
|
},
|
||||||
deleteMany: {
|
deleteMany: {
|
||||||
userId: {
|
userId: {
|
||||||
@@ -245,9 +230,9 @@ export class MeetingRoomSchema extends PothosSchema {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
}));
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ export class MessageSchema extends PothosSchema {
|
|||||||
data: {
|
data: {
|
||||||
...args.input,
|
...args.input,
|
||||||
context: MessageContextType.CHAT,
|
context: MessageContextType.CHAT,
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
await tx.chatRoom.update({
|
await tx.chatRoom.update({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@@ -1,58 +1,53 @@
|
|||||||
import { Inject, Injectable } from "@nestjs/common";
|
import { Inject, Injectable } from '@nestjs/common'
|
||||||
import { ChatRoomType } from "@prisma/client";
|
import { ChatRoomType } from '@prisma/client'
|
||||||
import {
|
import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
|
||||||
Pothos,
|
import { Builder } from '../Graphql/graphql.builder'
|
||||||
PothosRef,
|
import { LiveKitService } from '../LiveKit/livekit.service'
|
||||||
PothosSchema,
|
import { PrismaService } from '../Prisma/prisma.service'
|
||||||
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()
|
@Injectable()
|
||||||
export class WorkshopMeetingRoomSchema extends PothosSchema {
|
export class WorkshopMeetingRoomSchema extends PothosSchema {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||||
private readonly prisma: PrismaService,
|
private readonly prisma: PrismaService,
|
||||||
private readonly livekitService: LiveKitService
|
private readonly livekitService: LiveKitService,
|
||||||
) {
|
) {
|
||||||
super();
|
super()
|
||||||
}
|
}
|
||||||
|
|
||||||
@PothosRef()
|
@PothosRef()
|
||||||
workshopMeetingRoom() {
|
workshopMeetingRoom() {
|
||||||
return this.builder.prismaObject("WorkshopMeetingRoom", {
|
return this.builder.prismaObject('WorkshopMeetingRoom', {
|
||||||
fields: (t) => ({
|
fields: (t) => ({
|
||||||
id: t.exposeID("id", {
|
id: t.exposeID('id', {
|
||||||
description: "The ID of the workshop meeting room.",
|
description: 'The ID of the workshop meeting room.',
|
||||||
}),
|
}),
|
||||||
workshopId: t.exposeID("workshopId", {
|
workshopId: t.exposeID('workshopId', {
|
||||||
description: "The ID of the workshop that the meeting room is for.",
|
description: 'The ID of the workshop that the meeting room is for.',
|
||||||
}),
|
}),
|
||||||
workshop: t.relation("workshop", {
|
workshop: t.relation('workshop', {
|
||||||
description: "The workshop that the meeting room is for.",
|
description: 'The workshop that the meeting room is for.',
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
@PothosRef()
|
@PothosRef()
|
||||||
workshopMeetingRoomJoinInfo() {
|
workshopMeetingRoomJoinInfo() {
|
||||||
return this.builder.simpleObject("WorkshopMeetingRoomJoinInfo", {
|
return this.builder.simpleObject('WorkshopMeetingRoomJoinInfo', {
|
||||||
fields: (t) => ({
|
fields: (t) => ({
|
||||||
id: t.string({
|
id: t.string({
|
||||||
description: "The ID of the workshop meeting room.",
|
description: 'The ID of the workshop meeting room.',
|
||||||
}),
|
}),
|
||||||
token: t.string({
|
token: t.string({
|
||||||
description: "The token to join the workshop meeting room.",
|
description: 'The token to join the workshop meeting room.',
|
||||||
}),
|
}),
|
||||||
serverUrl: t.string({
|
serverUrl: t.string({
|
||||||
description: "The URL of the server.",
|
description: 'The URL of the server.',
|
||||||
}),
|
}),
|
||||||
chatRoomId: t.string({
|
chatRoomId: t.string({
|
||||||
description: "The ID of the chat room.",
|
description: 'The ID of the chat room.',
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@Pothos()
|
@Pothos()
|
||||||
@@ -60,59 +55,56 @@ export class WorkshopMeetingRoomSchema extends PothosSchema {
|
|||||||
this.builder.queryFields((t) => ({
|
this.builder.queryFields((t) => ({
|
||||||
workshopMeetingRoom: t.prismaField({
|
workshopMeetingRoom: t.prismaField({
|
||||||
type: this.workshopMeetingRoom(),
|
type: this.workshopMeetingRoom(),
|
||||||
args: this.builder.generator.findUniqueArgs("WorkshopMeetingRoom"),
|
args: this.builder.generator.findUniqueArgs('WorkshopMeetingRoom'),
|
||||||
resolve: async (query, _root, args, _ctx, _info) => {
|
resolve: async (query, _root, args, _ctx, _info) => {
|
||||||
return await this.prisma.workshopMeetingRoom.findUnique({
|
return await this.prisma.workshopMeetingRoom.findUnique({
|
||||||
...query,
|
...query,
|
||||||
where: args.where,
|
where: args.where,
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
workshopMeetingRoomJoinInfo: t.field({
|
workshopMeetingRoomJoinInfo: t.field({
|
||||||
type: this.workshopMeetingRoomJoinInfo(),
|
type: this.workshopMeetingRoomJoinInfo(),
|
||||||
args: {
|
args: {
|
||||||
workshopId: t.arg({
|
workshopId: t.arg({
|
||||||
type: "String",
|
type: 'String',
|
||||||
required: true,
|
required: true,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
resolve: async (_, args, ctx) => {
|
resolve: async (_, args, ctx) => {
|
||||||
if (ctx.isSubscription) {
|
if (ctx.isSubscription) {
|
||||||
throw new Error("Not allowed");
|
throw new Error('Not allowed')
|
||||||
}
|
}
|
||||||
if (!ctx.http?.me) {
|
if (!ctx.http?.me) {
|
||||||
throw new Error("Unauthorized");
|
throw new Error('Unauthorized')
|
||||||
}
|
}
|
||||||
const meetingRoom = await this.prisma.workshopMeetingRoom.findUnique({
|
const meetingRoom = await this.prisma.workshopMeetingRoom.findUnique({
|
||||||
where: {
|
where: {
|
||||||
workshopId: args.workshopId,
|
workshopId: args.workshopId,
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
// query chat room
|
// query chat room
|
||||||
const chatRoom = await this.prisma.chatRoom.findFirst({
|
const chatRoom = await this.prisma.chatRoom.findFirst({
|
||||||
where: {
|
where: {
|
||||||
workshopId: args.workshopId,
|
workshopId: args.workshopId,
|
||||||
type: ChatRoomType.WORKSHOP,
|
type: ChatRoomType.WORKSHOP,
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
if (!meetingRoom) {
|
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 {
|
return {
|
||||||
id: meetingRoom.id,
|
id: meetingRoom.id,
|
||||||
token: await this.livekitService.createToken(
|
token: await this.livekitService.createToken(ctx.http?.me, meetingRoom.id),
|
||||||
ctx.http?.me,
|
|
||||||
meetingRoom.id
|
|
||||||
),
|
|
||||||
serverUrl,
|
serverUrl,
|
||||||
chatRoomId: chatRoom?.id,
|
chatRoomId: chatRoom?.id,
|
||||||
};
|
}
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
workshopMeetingRooms: t.prismaField({
|
workshopMeetingRooms: t.prismaField({
|
||||||
type: [this.workshopMeetingRoom()],
|
type: [this.workshopMeetingRoom()],
|
||||||
args: this.builder.generator.findManyArgs("WorkshopMeetingRoom"),
|
args: this.builder.generator.findManyArgs('WorkshopMeetingRoom'),
|
||||||
resolve: async (query, _root, args, _ctx, _info) => {
|
resolve: async (query, _root, args, _ctx, _info) => {
|
||||||
return await this.prisma.workshopMeetingRoom.findMany({
|
return await this.prisma.workshopMeetingRoom.findMany({
|
||||||
...query,
|
...query,
|
||||||
@@ -121,9 +113,9 @@ export class WorkshopMeetingRoomSchema extends PothosSchema {
|
|||||||
cursor: args.cursor ?? undefined,
|
cursor: args.cursor ?? undefined,
|
||||||
take: args.take ?? undefined,
|
take: args.take ?? undefined,
|
||||||
skip: args.skip ?? undefined,
|
skip: args.skip ?? undefined,
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
}));
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user