How to use the type-graphql.Authorized function in type-graphql

To help you get started, we’ve selected a few type-graphql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NoQuarterTeam / split / packages / api / src / modules / invite / invite.resolver.ts View on Github external
import { InviteInput } from "./invite.input"
import { InviteService } from "./invite.service"
import { InviteMailer } from "./invite.mailer"
import { Group } from "../group/group.entity"
import { GroupRepository } from "../group/group.repository"

@Resolver(() => Invite)
export class InviteResolver {
  constructor(
    private readonly inviteService: InviteService,
    private readonly inviteMailer: InviteMailer,
    private readonly groupRepository: GroupRepository,
  ) {}

  // CREATE INVITE
  @Authorized()
  @Mutation(() => Invite, { nullable: true })
  async createInvite(@Arg("data") data: InviteInput): Promise {
    if (!data.groupId) return null
    const group = await this.groupRepository.findById(data.groupId)
    const invite = await this.inviteService.create(data, group)
    this.inviteMailer.sendInvitationLink(data.email, invite, group)
    return invite
  }

  // DESTROY INVITE
  @Authorized()
  @Mutation(() => Boolean, { nullable: true })
  async destroyInvite(@Arg("inviteId") inviteId: string): Promise {
    return this.inviteService.destroy(inviteId)
  }
github NoQuarterTeam / split / packages / api / src / modules / user / user.resolver.ts View on Github external
import { ResetPasswordInput } from "./inputs/resetPassword.input"
import { UserRepository } from "./user.repository"
import { CurrentUser } from "../shared/middleware/currentUser"
import { SlackService } from "../shared/slack.service"

@Resolver(() => User)
export class UserResolver {
  constructor(
    private readonly userService: UserService,
    private readonly userRepository: UserRepository,
    private readonly userMailer: UserMailer,
    private readonly slackService: SlackService,
  ) {}

  // ME
  @Authorized()
  @Query(() => User, { nullable: true })
  me(@CurrentUser() currentUser: User): Promise {
    return this.userRepository.findById(currentUser.id)
  }

  // REGISTER
  @Mutation(() => User)
  async register(
    @Arg("data") data: RegisterInput,
    @Ctx() { req }: ResolverContext,
  ): Promise {
    const user = await this.userService.create(data)
    if (req.session) req.session.user = user
    this.userMailer.sendWelcomeEmail(user)
    this.slackService.sendChatMessage(
      `${user.firstName} ${user.lastName} signed up!`,
github NoQuarterTeam / split / packages / api / src / modules / cost / cost.resolver.ts View on Github external
// ALL COSTS
  @Authorized()
  @Query(() => AllCostsResponse, { nullable: true })
  allCosts(@Args() args: AllCostArgs): Promise {
    return this.costRepository.findAllAndCount(args)
  }

  // GET COST
  @Authorized()
  @Query(() => Cost, { nullable: true })
  getCost(@Arg("costId") costId: string): Promise {
    return this.costRepository.findById(costId)
  }

  // CREATE COST
  @Authorized()
  @Mutation(() => Cost, { nullable: true })
  createCost(
    @Arg("data") data: CostInput,
    @CurrentUser() currentUser: User,
  ): Promise {
    return this.costService.create(currentUser.id, data)
  }

  // DESTROY COST
  @Authorized()
  @Mutation(() => Boolean, { nullable: true })
  destroyCost(@Arg("costId") costId: string): Promise {
    return this.costService.destroy(costId)
  }

  // EDIT COST
github goldcaddy77 / warthog / test / modules / kitchen-sink / kitchen-sink.resolver.ts View on Github external
@Query(() => [KitchenSink])
  async kitchenSinks(
    @Args()
    { where, orderBy, limit, offset }: KitchenSinkWhereArgs,
    @Fields() fields: string[]
  ): Promise {
    return this.service.find(where, orderBy, limit, offset, fields);
  }

  @Authorized('kitchenSink:read')
  @Query(() => KitchenSink)
  async kitchenSink(@Arg('where') where: KitchenSinkWhereUniqueInput): Promise {
    return this.service.findOne(where);
  }

  @Authorized('kitchenSink:create')
  @Mutation(() => KitchenSink)
  async createKitchenSink(
    @Arg('data') data: KitchenSinkCreateInput,
    @UserId() userId: string
  ): Promise {
    return this.service.create(data, userId);
  }

  @Authorized('kitchenSink:create')
  @Mutation(() => [KitchenSink])
  async createManyKitchenSinks(
    @Args() { data }: KitchenSinkCreateManyArgs,
    @UserId() userId: string
  ): Promise {
    return this.service.createMany(data, userId);
  }
github goldcaddy77 / warthog / test / modules / dish / dish.resolver.ts View on Github external
import { KitchenSink } from '../kitchen-sink/kitchen-sink.model';

import { Dish } from './dish.model';
import { DishService } from './dish.service';

@Resolver(Dish)
export class DishResolver {
  constructor(@Inject('DishService') public readonly service: DishService) {}

  @Authorized('kitchenSink:read')
  @FieldResolver(() => KitchenSink)
  kitchenSink(@Root() dish: Dish, @Ctx() ctx: BaseContext): Promise {
    return ctx.dataLoader.loaders.Dish.kitchenSink.load(dish);
  }

  @Authorized('dish:read')
  @Query(() => [Dish])
  async dishes(
    @Args() { where, orderBy, limit, offset }: DishWhereArgs,
    @Fields() fields: string[]
  ): Promise {
    return this.service.find(where, orderBy, limit, offset, fields);
  }

  @Authorized('dish:read')
  @Query(() => Dish)
  async dish(@Arg('where') where: DishWhereUniqueInput): Promise {
    return this.service.findOne(where);
  }

  @Authorized('dish:create')
  @Mutation(() => Dish)
github goldcaddy77 / warthog / test / modules / dish / dish.resolver.ts View on Github external
@Authorized('dish:read')
  @Query(() => [Dish])
  async dishes(
    @Args() { where, orderBy, limit, offset }: DishWhereArgs,
    @Fields() fields: string[]
  ): Promise {
    return this.service.find(where, orderBy, limit, offset, fields);
  }

  @Authorized('dish:read')
  @Query(() => Dish)
  async dish(@Arg('where') where: DishWhereUniqueInput): Promise {
    return this.service.findOne(where);
  }

  @Authorized('dish:create')
  @Mutation(() => Dish)
  async createDish(@Arg('data') data: DishCreateInput, @UserId() userId: string): Promise {
    return this.service.create(data, userId);
  }

  @Authorized('dish:update')
  @Mutation(() => Dish)
  async updateDish(
    @Args() { data, where }: DishUpdateArgs,
    @UserId() userId: string
  ): Promise {
    return this.service.update(data, where, userId);
  }

  @Authorized('dish:create')
  @Mutation(() => [Dish])
github goldcaddy77 / warthog / test / modules / dish / dish.resolver.ts View on Github external
return this.service.find(where, orderBy, limit, offset, fields);
  }

  @Authorized('dish:read')
  @Query(() => Dish)
  async dish(@Arg('where') where: DishWhereUniqueInput): Promise {
    return this.service.findOne(where);
  }

  @Authorized('dish:create')
  @Mutation(() => Dish)
  async createDish(@Arg('data') data: DishCreateInput, @UserId() userId: string): Promise {
    return this.service.create(data, userId);
  }

  @Authorized('dish:update')
  @Mutation(() => Dish)
  async updateDish(
    @Args() { data, where }: DishUpdateArgs,
    @UserId() userId: string
  ): Promise {
    return this.service.update(data, where, userId);
  }

  @Authorized('dish:create')
  @Mutation(() => [Dish])
  async createManyDishs(
    @Args() { data }: DishCreateManyArgs,
    @UserId() userId: string
  ): Promise {
    return this.service.createMany(data, userId);
  }
github mgm-interns / team-radio / server / src / resolver / user / UserResolver.ts View on Github external
import { UserRepository } from 'repositories';
import { Logger } from 'services';
import { Arg, Authorized, Query, Resolver } from 'type-graphql';
import { Inject } from 'typedi';
import { InjectRepository } from 'typeorm-typedi-extensions';
import { BaseResolver } from '..';

@Resolver(of => User)
export class UserResolver extends BaseResolver {
  @Inject()
  private logger: Logger;

  @InjectRepository()
  private userRepository: UserRepository;

  @Authorized()
  @Query(returns => [User], { description: 'Get all the users in system.' })
  public async users(): Promise {
    return this.userRepository.find({});
  }

  @Query(returns => User, { description: 'Get user by id' })
  public async user(@Arg('id') id: string): Promise {
    const user = await this.userRepository.findById(id);
    if (!user) throw new UserNotFoundException();
    return user;
  }
}