feat: added subscriber for update user settings
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { UseGuards } from '@nestjs/common';
|
import { UseGuards } from '@nestjs/common';
|
||||||
import { Args, Mutation, Resolver } from '@nestjs/graphql';
|
import { Args, Mutation, Resolver, Subscription } from '@nestjs/graphql';
|
||||||
import { GqlUser } from 'src/decorators/gql-user.decorator';
|
import { GqlUser } from 'src/decorators/gql-user.decorator';
|
||||||
import { GqlAuthGuard } from 'src/guards/gql-auth.guard';
|
import { GqlAuthGuard } from 'src/guards/gql-auth.guard';
|
||||||
import { User } from 'src/user/user.model';
|
import { User } from 'src/user/user.model';
|
||||||
@@ -7,10 +7,14 @@ import * as E from 'fp-ts/Either';
|
|||||||
import { throwErr } from 'src/utils';
|
import { throwErr } from 'src/utils';
|
||||||
import { UserSettings } from './user-settings.model';
|
import { UserSettings } from './user-settings.model';
|
||||||
import { UserSettingsService } from './user-settings.service';
|
import { UserSettingsService } from './user-settings.service';
|
||||||
|
import { PubSubService } from 'src/pubsub/pubsub.service';
|
||||||
|
|
||||||
@Resolver()
|
@Resolver()
|
||||||
export class UserSettingsResolver {
|
export class UserSettingsResolver {
|
||||||
constructor(private readonly userSettingsService: UserSettingsService) {}
|
constructor(
|
||||||
|
private readonly userSettingsService: UserSettingsService,
|
||||||
|
private readonly pubsub: PubSubService,
|
||||||
|
) {}
|
||||||
|
|
||||||
/* Mutations */
|
/* Mutations */
|
||||||
|
|
||||||
@@ -55,4 +59,13 @@ export class UserSettingsResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Subscriptions */
|
/* Subscriptions */
|
||||||
|
|
||||||
|
@Subscription(() => UserSettings, {
|
||||||
|
description: 'Listen for user setting updating',
|
||||||
|
resolve: (value) => value,
|
||||||
|
})
|
||||||
|
@UseGuards(GqlAuthGuard)
|
||||||
|
userSettingsUpdated(@GqlUser() user: User) {
|
||||||
|
return this.pubsub.asyncIterator(`user_settings/${user.uid}/updated`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user