feat: enhance message retrieval logic with context-based filtering
- Updated the MessageSchema to include context-aware filtering for notifications, allowing retrieval of messages based on recipientId when the context is NOTIFICATION. - Improved the resolve function to handle subscription checks, ensuring that unauthorized access is properly managed. - Added error handling for cases where the context is not allowed, enhancing overall robustness of the message retrieval process.
This commit is contained in:
@@ -77,7 +77,14 @@ export class MessageSchema extends PothosSchema {
|
||||
type: [this.message()],
|
||||
description: 'Retrieve a list of messages with optional filtering, ordering, and pagination.',
|
||||
args: this.builder.generator.findManyArgs('Message'),
|
||||
resolve: async (query, _root, args) => {
|
||||
resolve: async (query, _root, args, ctx, _info) => {
|
||||
if (ctx.isSubscription) {
|
||||
throw new Error('Not allowed')
|
||||
}
|
||||
// if message.context is NOTIFICATION, filter by recipientId
|
||||
if (args.filter?.context === MessageContextType.NOTIFICATION) {
|
||||
args.filter.recipientId = ctx.http.me?.id
|
||||
}
|
||||
return await this.prisma.message.findMany({
|
||||
...query,
|
||||
skip: args.skip ?? undefined,
|
||||
|
||||
Reference in New Issue
Block a user