Newer
Older
} from '@nestjs/graphql';
import { Group } from './models/group.model';
import { PrismaService } from '../prisma/prisma.service';
import { GraphQLString } from 'graphql';
import * as seedWords from 'mnemonic-words';
import {
NotFoundException,
UnauthorizedException,
UseGuards,
} from '@nestjs/common';
import { GroupAuthGuard } from '../auth/group-auth.guard';
import { Request } from 'express';
import { pubSub } from '../pubSub.instance';
import { AgentAuthGuard } from '../auth/agent-auth.guard';
payload.updateToken.slug === variables.groupSlug,
@Args({ name: 'groupSlug', type: () => GraphQLString })
groupSlug: string,
if (!groupSlug) throw new UnauthorizedException();
const group = await this.prismaService.group.findFirst({
where: {
if (!group) throw new NotFoundException('That Group does not exist');
return pubSub.asyncIterator('updateToken');
}
@Mutation(() => Group)
@UseGuards(AgentAuthGuard)
@Args({ name: 'groupSlug', type: () => GraphQLString })
groupSlug: string,
let group = await this.prismaService.group.findFirst({
where: { slug: groupSlug },
});
if (!group) throw new NotFoundException('That Group does not exist');
group = await this.prismaService.group.update({
await pubSub.publish('updateToken', { updateToken: group });
@Mutation(() => Group)
async createGroup(
@Args({ name: 'name', type: () => GraphQLString }) name: string,
@Args({ name: 'code', type: () => GraphQLString }) agentCode: string,
if (!agentCode) throw new UnauthorizedException();
// TODO: refactor agent auth, modify auth guard
const agent = await this.prismaService.agent.findFirst({
where: {
slug: agentCode,
},
});
if (!agent) throw new NotFoundException('That Agent does not exist');
function generateWord() {
return seedWords[Math.round(Math.random() * seedWords.length)];
}
generateWord(),
generateWord(),
generateWord(),
generateWord(),
].join('-');
return this.prismaService.group.create({
data: {
name,
@UseGuards(GroupAuthGuard)
async getGroup(@Context() { req }: { req: Request }) {
}
@ResolveField('unlocks')
async unlocks(@Parent() group: Group) {
const result = await this.prismaService.group.findFirst({
where: { id: group.id },
select: { unlocks: true },
});
return result.unlocks.map((unlock) => ({
...unlock,
locked: false,
}));