refactor source code

This commit is contained in:
2024-10-29 17:42:54 +07:00
parent 3b23d9e0b7
commit 152bb50da8
83 changed files with 8473 additions and 7577 deletions

View File

@@ -1,12 +1,12 @@
import { Inject, Injectable } from '@nestjs/common';
import { Inject, Injectable } from '@nestjs/common'
import {
Pothos,
PothosRef,
PothosSchema,
SchemaBuilderToken,
} from '@smatch-corp/nestjs-pothos';
import { Builder } from '../Graphql/graphql.builder';
import { PrismaService } from '../Prisma/prisma.service';
} from '@smatch-corp/nestjs-pothos'
import { Builder } from '../Graphql/graphql.builder'
import { PrismaService } from '../Prisma/prisma.service'
@Injectable()
export class MessageSchema extends PothosSchema {
@@ -14,7 +14,7 @@ export class MessageSchema extends PothosSchema {
@Inject(SchemaBuilderToken) private readonly builder: Builder,
private readonly prisma: PrismaService,
) {
super();
super()
}
@PothosRef()
@@ -47,7 +47,7 @@ export class MessageSchema extends PothosSchema {
description: 'The chat room.',
}),
}),
});
})
}
@Pothos()
@@ -61,7 +61,7 @@ export class MessageSchema extends PothosSchema {
return await this.prisma.message.findUnique({
...query,
where: args.where,
});
})
},
}),
messages: t.prismaField({
@@ -76,7 +76,7 @@ export class MessageSchema extends PothosSchema {
take: args.take ?? undefined,
orderBy: args.orderBy ?? undefined,
where: args.filter ?? undefined,
});
})
},
}),
messagesByChatRoomId: t.prismaField({
@@ -87,10 +87,10 @@ export class MessageSchema extends PothosSchema {
return await this.prisma.message.findMany({
...query,
where: args.filter ?? undefined,
});
})
},
}),
}));
}))
// mutations
this.builder.mutationFields((t) => ({
@@ -108,15 +108,15 @@ export class MessageSchema extends PothosSchema {
const message = await this.prisma.message.create({
...query,
data: args.input,
});
})
if (ctx.isSubscription) {
throw new Error('Not allowed');
throw new Error('Not allowed')
}
ctx.http.pubSub.publish('MESSAGE_SENT', message);
return message;
ctx.http.pubSub.publish('MESSAGE_SENT', message)
return message
},
}),
}));
}))
// subscriptions
/* The code snippet `subscriptions` is currently commented out in the provided TypeScript class. It
@@ -128,23 +128,23 @@ export class MessageSchema extends PothosSchema {
messageSent: t.field({
subscribe: (_, __, ctx) => {
if (!ctx.isSubscription) {
throw new Error('Not allowed');
throw new Error('Not allowed')
}
return {
[Symbol.asyncIterator]: () =>
ctx.websocket.pubSub.asyncIterator('MESSAGE_SENT'),
};
}
},
type: this.message(), // Add the type property
resolve: (payload) =>
payload as {
message: 'Json';
id: string;
senderId: string;
chatRoomId: string;
sentAt: Date;
message: 'Json'
id: string
senderId: string
chatRoomId: string
sentAt: Date
},
}),
}));
}))
}
}