Newer
Older
import {
Args,
Context,
Parent,
Query,
ResolveField,
Resolver,
} from '@nestjs/graphql';
import { Agent } from './models/agent.model';
import { PrismaService } from '../prisma/prisma.service';
import { GraphQLString } from 'graphql';
import { NotFoundException, UseGuards } from '@nestjs/common';
import { GroupAuthGuard } from '../auth/group-auth.guard';
import { Request } from 'express';
@UseGuards(GroupAuthGuard)
return this.prismaService.agent.findMany({
}
@Query(() => Agent)
async getAgent(
@Args({ name: 'code', type: () => GraphQLString }) code: string,
) {
const agent = await this.prismaService.agent.findFirst({
where: { slug: code },
include: { tokenCode: true },
if (!agent) throw new NotFoundException('That Agent does not exist');
@UseGuards(GroupAuthGuard)
async entries(
@Parent() entry: Agent,
@Context() { req }: { req: Request },
) {
const unlocks = await this.prismaService.group
.findFirst({
where: { id: req.group.id },
select: {
unlocks: true,
},
})
.then((value) => value.unlocks)
.then((unlocks) => unlocks.map((value) => value.id));
if (!entry.private || unlocks.includes(entry.id))
return {
...entry,
locked: false,
};
return {
id: entry.id,
agentId: entry.agentId,
private: true,
createdAt: entry.createdAt,
locked: true,
};
});