@nestjs/swagger#ApiExcludeEndpoint TypeScript Examples

The following examples show how to use @nestjs/swagger#ApiExcludeEndpoint. 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: auth.controller.ts    From ironfish-api with Mozilla Public License 2.0 6 votes vote down vote up
@ApiExcludeEndpoint()
  @Post('login')
  async login(@Req() req: Request, @Res() res: Response): Promise<void> {
    if (this.config.get<boolean>('DISABLE_LOGIN')) {
      throw new UnauthorizedException();
    }

    let email;

    const { authorization } = req.headers;
    if (!authorization) {
      throw new UnauthorizedException();
    }

    try {
      email = await this.magicLinkService.getEmailFromHeader(authorization);
    } catch {
      throw new UnauthorizedException();
    }

    if (email) {
      const user = await this.usersService.findByEmail(email);
      if (user) {
        await this.usersService.updateLastLoginAt(user);
      } else {
        throw new UnauthorizedException({ error: 'user_invalid' });
      }
    }

    res.sendStatus(HttpStatus.OK);
  }
Example #2
Source File: versions.controller.ts    From ironfish-api with Mozilla Public License 2.0 6 votes vote down vote up
@ApiExcludeEndpoint()
  @UseGuards(ApiKeyGuard)
  @UsePipes(
    new ValidationPipe({
      errorHttpStatusCode: HttpStatus.UNPROCESSABLE_ENTITY,
      transform: true,
    }),
  )
  @Post()
  async updateVersion(
    @Body()
    { version }: CreateVersionDto,
  ): Promise<SerializedVersion> {
    return serializedVersionFromRecord(
      await this.versionsService.create(version),
    );
  }
Example #3
Source File: users.controller.ts    From ironfish-api with Mozilla Public License 2.0 6 votes vote down vote up
@ApiExcludeEndpoint()
  @Put(':id')
  @UseGuards(MagicLinkGuard)
  async update(
    @Context() { user }: MagicLinkContext,
    @Param('id', new IntIsSafeForPrismaPipe())
    id: number,
    @Body(
      new ValidationPipe({
        errorHttpStatusCode: HttpStatus.UNPROCESSABLE_ENTITY,
        transform: true,
      }),
    )
    dto: UpdateUserDto,
  ): Promise<User> {
    if (id !== user.id) {
      throw new ForbiddenException();
    }
    return this.usersUpdater.update(user, {
      countryCode: dto.country_code,
      discord: dto.discord,
      github: dto.github,
      graffiti: dto.graffiti,
      telegram: dto.telegram,
    });
  }
Example #4
Source File: users.controller.ts    From ironfish-api with Mozilla Public License 2.0 6 votes vote down vote up
@ApiExcludeEndpoint()
  @Post()
  async create(
    @Body(
      new ValidationPipe({
        errorHttpStatusCode: HttpStatus.UNPROCESSABLE_ENTITY,
        transform: true,
      }),
    )
    dto: CreateUserDto,
  ): Promise<User> {
    return this.usersService.create(dto);
  }
Example #5
Source File: faucet-transactions.controller.ts    From ironfish-api with Mozilla Public License 2.0 6 votes vote down vote up
@ApiExcludeEndpoint()
  @Post(':id/complete')
  @HttpCode(HttpStatus.OK)
  @UseGuards(ApiKeyGuard)
  async complete(
    @Param('id', new IntIsSafeForPrismaPipe())
    id: number,
    @Body(
      new ValidationPipe({
        errorHttpStatusCode: HttpStatus.UNPROCESSABLE_ENTITY,
      }),
    )
    dto: CompleteFaucetTransactionDto,
  ): Promise<SerializedFaucetTransaction> {
    const record = await this.faucetTransactionsService.findOrThrow(id);
    return serializedFaucetTransactionFromRecord(
      await this.faucetTransactionsService.complete(record, dto),
    );
  }
Example #6
Source File: faucet-transactions.controller.ts    From ironfish-api with Mozilla Public License 2.0 6 votes vote down vote up
@ApiExcludeEndpoint()
  @Post(':id/start')
  @HttpCode(HttpStatus.OK)
  @UseGuards(ApiKeyGuard)
  async start(
    @Param('id', new IntIsSafeForPrismaPipe())
    id: number,
  ): Promise<SerializedFaucetTransaction> {
    const record = await this.faucetTransactionsService.findOrThrow(id);
    return serializedFaucetTransactionFromRecord(
      await this.faucetTransactionsService.start(record),
    );
  }
Example #7
Source File: faucet-transactions.controller.ts    From ironfish-api with Mozilla Public License 2.0 6 votes vote down vote up
@ApiExcludeEndpoint()
  @Get('next')
  @UseGuards(ApiKeyGuard)
  async next(
    @Query(
      new ValidationPipe({
        errorHttpStatusCode: HttpStatus.UNPROCESSABLE_ENTITY,
        transform: true,
      }),
    )
    { count }: NextFaucetTransactionsDto,
  ): Promise<List<SerializedFaucetTransaction>> {
    const nextFaucetTransactions = await this.faucetTransactionsService.next({
      count,
    });

    return {
      object: 'list',
      data: nextFaucetTransactions.map((nextFaucetTransaction) =>
        serializedFaucetTransactionFromRecord(nextFaucetTransaction),
      ),
    };
  }
Example #8
Source File: faucet-transactions.controller.ts    From ironfish-api with Mozilla Public License 2.0 6 votes vote down vote up
@ApiExcludeEndpoint()
  @Post()
  async create(
    @Body(
      new ValidationPipe({
        errorHttpStatusCode: HttpStatus.UNPROCESSABLE_ENTITY,
      }),
    )
    { email, public_key: publicKey }: CreateFaucetTransactionDto,
  ): Promise<SerializedFaucetTransaction> {
    if (this.config.get<boolean>('DISABLE_FAUCET')) {
      throw new HttpException(
        {
          status: HttpStatus.FORBIDDEN,
          message: 'The faucet has been disabled, try joining a mining pool!',
        },
        HttpStatus.FORBIDDEN,
      );
    }
    return serializedFaucetTransactionFromRecord(
      await this.faucetTransactionsService.create({ email, publicKey }),
    );
  }
Example #9
Source File: events.controller.ts    From ironfish-api with Mozilla Public License 2.0 6 votes vote down vote up
@ApiExcludeEndpoint()
  @Post()
  @UseGuards(ApiKeyGuard)
  async create(
    @Body(
      new ValidationPipe({
        errorHttpStatusCode: HttpStatus.UNPROCESSABLE_ENTITY,
        transform: true,
      }),
    )
    { graffiti, points, type, occurred_at: occurredAt, url }: CreateEventDto,
  ): Promise<SerializedEvent | null> {
    const user = await this.usersService.findByGraffitiOrThrow(graffiti);

    const event = await this.eventsService.create({
      type,
      points,
      occurredAt,
      userId: user.id,
      url,
    });

    if (!event) {
      return null;
    }

    return serializedEventFromRecordWithMetadata(event);
  }
Example #10
Source File: deposits.controller.ts    From ironfish-api with Mozilla Public License 2.0 6 votes vote down vote up
@ApiExcludeEndpoint()
  @Post()
  @UseGuards(ApiKeyGuard)
  async bulkUpsert(
    @Body(
      new ValidationPipe({
        errorHttpStatusCode: HttpStatus.UNPROCESSABLE_ENTITY,
        transform: true,
      }),
    )
    data: UpsertDepositsDto,
    @Res() res: Response,
  ): Promise<void> {
    await this.depositsUpsert.bulkUpsert(data.operations);
    res.sendStatus(HttpStatus.ACCEPTED);
  }
Example #11
Source File: deposits.controller.ts    From ironfish-api with Mozilla Public License 2.0 6 votes vote down vote up
@ApiOperation({ summary: 'Gets the head of the chain' })
  @ApiExcludeEndpoint()
  @Get('head')
  async head(): Promise<{ block_hash: string }> {
    const depositHead = await this.deposits.head();

    if (!depositHead) {
      throw new NotFoundException();
    }

    return {
      block_hash: depositHead.block_hash,
    };
  }
Example #12
Source File: blocks.controller.ts    From ironfish-api with Mozilla Public License 2.0 6 votes vote down vote up
@ApiExcludeEndpoint()
  @Post('disconnect')
  @UseGuards(ApiKeyGuard)
  async disconnect(
    @Body(
      new ValidationPipe({
        errorHttpStatusCode: HttpStatus.UNPROCESSABLE_ENTITY,
        transform: true,
      }),
    )
    { sequence_gt: sequenceGt }: DisconnectBlocksDto,
    @Res() res: Response,
  ): Promise<void> {
    await this.blocksService.disconnectAfter(sequenceGt);
    res.sendStatus(HttpStatus.OK);
  }
Example #13
Source File: blocks.controller.ts    From ironfish-api with Mozilla Public License 2.0 6 votes vote down vote up
@ApiExcludeEndpoint()
  @Post()
  @UseGuards(ApiKeyGuard)
  async bulkUpsert(
    @Body(
      new ValidationPipe({
        errorHttpStatusCode: HttpStatus.UNPROCESSABLE_ENTITY,
        transform: true,
      }),
    )
    upsertBlocksDto: UpsertBlocksDto,
  ): Promise<List<SerializedBlock>> {
    const blocks = await this.blocksTransactionsLoader.bulkUpsert(
      upsertBlocksDto,
    );
    return {
      object: 'list',
      data: blocks.map((block) =>
        serializedBlockFromRecordWithTransactions(block),
      ),
    };
  }
Example #14
Source File: telemetry.controller.ts    From ironfish-api with Mozilla Public License 2.0 5 votes vote down vote up
@ApiExcludeEndpoint()
  @Post()
  async write(
    @Req() request: Request,
    @Body(
      new ValidationPipe({
        errorHttpStatusCode: HttpStatus.UNPROCESSABLE_ENTITY,
        transform: true,
      }),
    )
    { points, graffiti }: WriteTelemetryPointsDto,
  ): Promise<void> {
    const options = [];
    let nodeVersion;
    for (const { fields, measurement, tags, timestamp } of points) {
      const version = tags.find((tag) => tag.name === 'version');
      if (!version || !this.isValidTelemetryVersion(version.value)) {
        continue;
      }
      nodeVersion = version.value;

      options.push({
        fields,
        measurement,
        tags,
        timestamp,
      });
    }

    if (options.length) {
      this.influxDbService.writePoints(options);
    }

    this.submitIpWithoutNodeFieldsToTelemetry(request);

    if (!graffiti || !nodeVersion) {
      return;
    }

    const nodeUptimeEnabled = this.config.get<boolean>('NODE_UPTIME_ENABLED');
    if (!nodeUptimeEnabled) {
      return;
    }

    const oneWeekAgo = new Date();
    oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);

    const minVersion = await this.versionsService.getLatestAtDate(oneWeekAgo);

    // If the API fails to fetch a version, we don't want to punish the user
    if (!minVersion || gte(nodeVersion, minVersion.version)) {
      const user = await this.usersService.findByGraffiti(graffiti);

      if (user) {
        await this.nodeUptimes.addUptime(user);
      }
    }
  }
Example #15
Source File: user-points.controller.ts    From ironfish-api with Mozilla Public License 2.0 5 votes vote down vote up
@ApiExcludeEndpoint()
  @UseGuards(ApiKeyGuard)
  @Post('refresh')
  async refresh(): Promise<void> {
    await this.graphileWorkerService.addJob(
      GraphileWorkerPattern.REFRESH_USERS_POINTS,
    );
  }
Example #16
Source File: app.controller.ts    From aqualink-app with MIT License 5 votes vote down vote up
@ApiExcludeEndpoint()
  @Get()
  @Redirect('/api/docs')
  getDocs() {
    this.logger.log('Redirecting to /api/docs');
  }
Example #17
Source File: app.controller.ts    From MyAPI with MIT License 5 votes vote down vote up
@Get()
  @Render('home')
  @ApiExcludeEndpoint()
  getHome(): { message: string } {
    return {
      message: this.appService.getHello()
    }
  }