Skip to content
Snippets Groups Projects
Commit a84592f2 authored by Daniel Gerdes's avatar Daniel Gerdes
Browse files

Add Subscription 'updateToken'

- auth workaround with args
parent bdfe5d72
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ import {
Query,
ResolveField,
Resolver,
Subscription,
} from '@nestjs/graphql';
import { Group } from './models/group.model';
import { PrismaService } from '../prisma/prisma.service';
......@@ -14,13 +15,43 @@ import * as seedWords from 'mnemonic-words';
import { UseGuards } from '@nestjs/common';
import { GraphQLAuthGuard } from '../auth/graphql-auth.guard';
import { Request } from 'express';
import { pubSub } from '../pubSub.instance';
@Resolver(() => Group)
@UseGuards(GraphQLAuthGuard)
export class GroupResolver {
constructor(private prismaService: PrismaService) {}
@Subscription(() => Group, {
filter: (payload, variables) =>
payload.updateToken.code === variables.code
})
updateToken(@Args('code') code: string){
return pubSub.asyncIterator('updateToken');
}
@Mutation(() => Group)
async addToken(
@Args({ name: 'code', type: () => GraphQLString }) code: string
){
var group = await this.prismaService.group.findFirst({
where:{code: code}
});
group = await this.prismaService.group.update({
where:{
code: code,
},
data:{
tokens: group.tokens+1
}
});
pubSub.publish("updateToken", {updateToken: group});
return group;
}
@Mutation(() => Group)
@UseGuards(GraphQLAuthGuard)
async createGroup(
@Args({ name: 'name', type: () => GraphQLString }) name: string,
) {
......@@ -44,6 +75,7 @@ export class GroupResolver {
}
@Query(() => Group)
@UseGuards(GraphQLAuthGuard)
async getGroup(@Context() { req }: { req: Request }) {
return req.group;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment