chore: completed subscription to create a SharedRequest
This commit is contained in:
@@ -27,6 +27,7 @@ import {
|
|||||||
UserCollectionReorderData,
|
UserCollectionReorderData,
|
||||||
} from 'src/user-collection/user-collections.model';
|
} from 'src/user-collection/user-collections.model';
|
||||||
import { Shortcode } from 'src/shortcode/shortcode.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.
|
// 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.
|
// 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_added`]: TeamInvitation;
|
||||||
[topic: `team/${string}/invite_removed`]: string;
|
[topic: `team/${string}/invite_removed`]: string;
|
||||||
[topic: `shortcode/${string}/${'created' | 'revoked'}`]: Shortcode;
|
[topic: `shortcode/${string}/${'created' | 'revoked'}`]: Shortcode;
|
||||||
|
[topic: `shared_request/${string}/${'created' | 'revoked'}`]: SharedRequest;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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 { SharedRequest } from './shared-requests.model';
|
||||||
import { GqlThrottlerGuard } from 'src/guards/gql-throttler.guard';
|
import { GqlThrottlerGuard } from 'src/guards/gql-throttler.guard';
|
||||||
import { UseGuards } from '@nestjs/common';
|
import { UseGuards } from '@nestjs/common';
|
||||||
@@ -10,6 +17,7 @@ import { GqlAuthGuard } from 'src/guards/gql-auth.guard';
|
|||||||
import { throwErr } from 'src/utils';
|
import { throwErr } from 'src/utils';
|
||||||
import { GqlUser } from 'src/decorators/gql-user.decorator';
|
import { GqlUser } from 'src/decorators/gql-user.decorator';
|
||||||
import { AuthUser } from 'src/types/AuthUser';
|
import { AuthUser } from 'src/types/AuthUser';
|
||||||
|
import { SkipThrottle } from '@nestjs/throttler';
|
||||||
|
|
||||||
@UseGuards(GqlThrottlerGuard)
|
@UseGuards(GqlThrottlerGuard)
|
||||||
@Resolver(() => SharedRequest)
|
@Resolver(() => SharedRequest)
|
||||||
@@ -67,4 +75,15 @@ export class SharedRequestResolver {
|
|||||||
if (E.isLeft(result)) throwErr(result.left);
|
if (E.isLeft(result)) throwErr(result.left);
|
||||||
return result.right;
|
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`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ export class SharedRequestService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.pubsub.publish(
|
this.pubsub.publish(
|
||||||
`shortcode/${createdSharedRequest.creatorUid}/created`,
|
`shared_request/${createdSharedRequest.creatorUid}/created`,
|
||||||
this.cast(createdSharedRequest),
|
this.cast(createdSharedRequest),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user