chore: completed subscription to create a SharedRequest

This commit is contained in:
Balu Babu
2023-10-25 21:49:04 +05:30
parent b74c1abf6f
commit b7462ab014
3 changed files with 23 additions and 2 deletions

View File

@@ -27,6 +27,7 @@ import {
UserCollectionReorderData,
} from 'src/user-collection/user-collections.model';
import { Shortcode } from 'src/shortcode/shortcode.model';
import { SharedRequest } from 'src/shared-request/shared-requests.model';
// A custom message type that defines the topic and the corresponding payload.
// For every module that publishes a subscription add its type def and the possible subscription type.
@@ -70,4 +71,5 @@ export type TopicDef = {
[topic: `team/${string}/invite_added`]: TeamInvitation;
[topic: `team/${string}/invite_removed`]: string;
[topic: `shortcode/${string}/${'created' | 'revoked'}`]: Shortcode;
[topic: `shared_request/${string}/${'created' | 'revoked'}`]: SharedRequest;
};

View File

@@ -1,4 +1,11 @@
import { Args, ID, Resolver, Query, Mutation } from '@nestjs/graphql';
import {
Args,
ID,
Resolver,
Query,
Mutation,
Subscription,
} from '@nestjs/graphql';
import { SharedRequest } from './shared-requests.model';
import { GqlThrottlerGuard } from 'src/guards/gql-throttler.guard';
import { UseGuards } from '@nestjs/common';
@@ -10,6 +17,7 @@ import { GqlAuthGuard } from 'src/guards/gql-auth.guard';
import { throwErr } from 'src/utils';
import { GqlUser } from 'src/decorators/gql-user.decorator';
import { AuthUser } from 'src/types/AuthUser';
import { SkipThrottle } from '@nestjs/throttler';
@UseGuards(GqlThrottlerGuard)
@Resolver(() => SharedRequest)
@@ -67,4 +75,15 @@ export class SharedRequestResolver {
if (E.isLeft(result)) throwErr(result.left);
return result.right;
}
/* Subscriptions */
@Subscription(() => SharedRequest, {
description: 'Listen for shortcode creation',
resolve: (value) => value,
})
@SkipThrottle()
@UseGuards(GqlAuthGuard)
mySharedRequestCreated(@GqlUser() user: AuthUser) {
return this.pubsub.asyncIterator(`shared_request/${user.uid}/created`);
}
}

View File

@@ -119,7 +119,7 @@ export class SharedRequestService {
});
this.pubsub.publish(
`shortcode/${createdSharedRequest.creatorUid}/created`,
`shared_request/${createdSharedRequest.creatorUid}/created`,
this.cast(createdSharedRequest),
);