type-graphql#Int TypeScript Examples

The following examples show how to use type-graphql#Int. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: order.resolver.ts    From Cromwell with MIT License 6 votes vote down vote up
@Authorized<TAuthRole>("all")
    @Query(() => PagedOrder)
    async [getOrdersOfUser](
        @Ctx() ctx: TGraphQLContext,
        @Arg("userId", () => Int) userId: number,
        @Arg("pagedParams", { nullable: true }) pagedParams?: PagedParamsInput<TOrder>
    ): Promise<TPagedList<TOrder> | undefined> {
        if (!ctx?.user?.role) throw new HttpException('Access denied.', HttpStatus.UNAUTHORIZED);

        if (!(ctx.user.role === 'guest' || ctx.user.role === 'administrator' ||
            ctx.user.id + '' === userId + '')) {
            throw new HttpException('Access denied.', HttpStatus.FORBIDDEN);
        }
        const orders = await this.repository.getOrdersOfUser(userId, pagedParams);
        return orders;
    }
Example #2
Source File: DepartmentService.ts    From graphql-ts-client with MIT License 6 votes vote down vote up
@Query(() => DepartmentConnection)
    async findDepartmentsLikeName(
        @Arg("name", () => String, {nullable: true}) name?: string | null,
        @Arg("first", () => Int, {nullable: true}) first?: number | null,
        @Arg("after", () => String, {nullable: true}) after?: string | null,
        @Arg("last", () => Int, {nullable: true}) last?: number | null,
        @Arg("before", () => String, {nullable: true}) before?: string | null
    ): Promise<DepartmentConnection> {

        /*
         * Mock the network delay
         */
        await delay(1000);

        const lowercaseName = name?.toLocaleLowerCase();
        const predicate: Predicate<TDepartment> | undefined = 
            lowercaseName !== undefined && lowercaseName !== "" ?
            d => d.name.toLowerCase().indexOf(lowercaseName) !== -1 :
            undefined
        const departments = departmentTable
            .find([], predicate)
            .map(row => new Department(row))
            .sort((a, b) => a.name > b.name ? + 1 : a.name < b.name ? -1 :0);
        return createConnection<DepartmentConnection, DepartmentEdge, Department>({
            totalCount: departments.length,
            getNodes: (offset, count) => departments.slice(offset, offset + count),
            createConnection: (totalCount, edges, pageInfo) => new DepartmentConnection(totalCount, edges, pageInfo),
            createEdge: (node, cursor) => new DepartmentEdge(node, cursor),
            first,
            after,
            last,
            before
        });
    }
Example #3
Source File: post.ts    From lireddit with MIT License 6 votes vote down vote up
@FieldResolver(() => Int, { nullable: true })
  async voteStatus(
    @Root() post: Post,
    @Ctx() { updootLoader, req }: MyContext
  ) {
    if (!req.session.userId) {
      return null;
    }

    const updoot = await updootLoader.load({
      postId: post.id,
      userId: req.session.userId,
    });

    return updoot ? updoot.value : null;
  }
Example #4
Source File: Comment.resolver.ts    From bouncecode-cms with GNU General Public License v3.0 6 votes vote down vote up
@Query(() => [CommentObject])
  async comments(
    @Arg('where') where: CommentWhereInput,
    @Arg('skip', () => Int, {nullable: true}) skip: number = 0,
    @Arg('take', () => Int, {nullable: true}) take: number = 10,
  ) {
    try {
      const queryBuilder = getRepository(CommentEntity)
        .createQueryBuilder('comment')
        .leftJoinAndSelect('comment.user', 'user');

      if (where.postId) {
        queryBuilder.andWhere('comment.postId = :postId', {
          postId: where.postId,
        });
      }

      if (where.user?.id) {
        queryBuilder.andWhere('user.userId = :userId', {
          userId: where.user?.id,
        });
      } else if (where.user?.email) {
        queryBuilder.andWhere('user.userEmail = :userEmail', {
          userEmail: where.user?.email,
        });
      }

      const result = await queryBuilder
        .orderBy('comment.id', 'DESC')
        .offset(skip)
        .limit(take)
        .getMany();

      return result;
    } catch (e) {
      console.log(e);
      return new ApolloError(e);
    }
  }
Example #5
Source File: comment.resolver.ts    From hakka with MIT License 6 votes vote down vote up
@FieldResolver((returns) => Int)
  async likesCount(@Root() comment: Comment) {
    const count = await prisma.userCommentLike.count({
      where: {
        commentId: comment.id,
      },
    })
    return count
  }
Example #6
Source File: newsletter-form.entity.ts    From Cromwell with MIT License 5 votes vote down vote up
@Field(() => Int)
    @PrimaryGeneratedColumn()
    id: number;