@nestjs/common#Header TypeScript Examples

The following examples show how to use @nestjs/common#Header. 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: cms.controller.ts    From Cromwell with MIT License 6 votes vote down vote up
@Post('upload-public-file')
    @UseGuards(JwtAuthGuard)
    @Roles('administrator', 'author')
    @Header('content-type', 'multipart/form-data')
    @ApiOperation({
        description: 'Uploads a file to specified subfolder of "public" files',
        parameters: [
            { name: 'inPath', in: 'query' },
            { name: 'fileName', in: 'query' }]
    })
    @ApiResponse({
        status: 200,
    })
    @ApiForbiddenResponse({ description: 'Forbidden.' })
    async uploadFile(@Query('inPath') inPath: string, @Query('fileName') fileName: string,
        @Req() req: any): Promise<string> {
        logger.log('CmsController::uploadFile');
        try {
            const fullPath = join(getPublicDir(), inPath ?? '');
            await this.cmsService.uploadFile(req, fullPath);
        } catch (error) {
            logger.error(error);
            return 'false';
        }

        return 'true';
    }
Example #2
Source File: project.controller.ts    From barista with Apache License 2.0 6 votes vote down vote up
@Get('/:id/attributions/download')
  @Header('Content-Type', 'text/plain')
  @Header('Content-Disposition', 'attachment; filename=attribution.txt')
  async attributionsDownload(@Param('id') id: string, @Res() res: Response): Promise<any> {
    const project = await this.service.db.findOne(Number(id));
    if (project) {
      const attribution = await this.service.getprojectAttribution(project);
      return res.status(200).send(attribution.licenseText).end();
    }
  }
Example #3
Source File: stats.controller.ts    From barista with Apache License 2.0 6 votes vote down vote up
@Get('/badges/:id/licensestate')
  @Header('Content-Type', 'image/svg+xml')
  @Header('Content-Disposition', 'attachment; filename=licensestate.svg')
  async getLicenseState(@Param('id') id: string, @Res() res: Response) {
    const project = await this.service.db.findOne(Number(id));

    let licenseStatus = await ProjectScanStatusTypeService.Unknown();
    let latestScanDate = 'unknown';
    if (project) {
      const checklicenseStatus = await this.service.highestLicenseStatus(project);
      if (checklicenseStatus) {
        licenseStatus = checklicenseStatus;
      }
      latestScanDate = await this.getLatestScanDate(project);
    }

    const svg = this.createSVG(this.createFormat('barista license state', latestScanDate, licenseStatus.code));
    return res
      .status(200)
      .send(svg)
      .end();
  }
Example #4
Source File: stats.controller.ts    From barista with Apache License 2.0 6 votes vote down vote up
@Get('/badges/:id/securitystate')
  @Header('Content-Type', 'image/svg+xml')
  @Header('Content-Disposition', 'attachment; filename=securitystate.svg')
  async getSecurityState(@Param('id') id: string, @Res() res: Response) {
    const project = await this.service.db.findOne(Number(id));

    let securityStatus = await ProjectScanStatusTypeService.Unknown();
    let latestScanDate = 'unknown';
    if (project) {
      const checksecurityStatus = await this.service.highestSecurityStatus(project);
      if (checksecurityStatus) {
        securityStatus = checksecurityStatus;
      }
      latestScanDate = await this.getLatestScanDate(project);
    }

    const svg = this.createSVG(this.createFormat('barista security state', latestScanDate, securityStatus.code));
    return res
      .status(200)
      .send(svg)
      .end();
  }
Example #5
Source File: stats.controller.ts    From barista with Apache License 2.0 6 votes vote down vote up
@Get('/badges/:id/vulnerabilities')
  @Header('Content-Type', 'image/svg+xml')
  @Header('Content-Disposition', 'attachment; filename=vulnerabilities.svg')
  async getvulnerabilities(@Param('id') id: string, @Res() res: Response) {
    const project = await this.service.db.findOne(Number(id));

    let securityStatus = await ProjectScanStatusTypeService.Unknown();
    let valueString = '';
    if (project) {
      const vulnerabilities = await this.service.distinctSeverities(project);
      securityStatus = await this.service.highestSecurityStatus(project);
      if (vulnerabilities.length === 0) {
        valueString = 'none detected';
      }
      vulnerabilities.forEach(vul => (valueString = valueString + vul.severity + ':' + vul.count + ' '));
    }

    const svg = this.createSVG(this.createFormat('barista vulnerabilities', valueString, securityStatus.code));
    return res
      .status(200)
      .send(svg)
      .end();
  }
Example #6
Source File: stats.controller.ts    From barista with Apache License 2.0 6 votes vote down vote up
@Get('/badges/:id/components')
  @Header('Content-Type', 'image/svg+xml')
  @Header('Content-Disposition', 'attachment; filename=components.svg')
  async getComponentsResults(@Param('id') id: string, @Res() res: Response) {
    const project = await this.service.db.findOne(Number(id));
    let valueString = 'unknown';
    let color = 'lightgrey';
    if (project) {
      const scan = await this.service.latestCompletedScan(project);
      if (scan) {
        const query = await this.licenseScanResultItemService.db
          .createQueryBuilder('resultItem')
          .leftJoin('resultItem.licenseScan', 'licenseScan')
          .leftJoinAndSelect('resultItem.projectScanStatus', 'projectScanStatus')
          .leftJoinAndSelect('resultItem.license', 'license')
          .leftJoin('licenseScan.scan', 'scan')
          .where('scan.id = :id', { id: scan.id })
          .getMany();

        valueString = query.length.toString();
        color = '#edb';
      }
    }

    const svg = this.createSVG(this.createFormat('barista open source components', valueString, color));
    return res
      .status(200)
      .send(svg)
      .end();
  }
Example #7
Source File: organizations.controller.ts    From nestjs-rest-microservices with MIT License 6 votes vote down vote up
@Get()
  @Header('Content-Type', 'application/json')
  async findOrganizations(@Query() query: RequestQuery): Promise<QueryResponse> {
    this.logger.info('OrganizationController#findOrganizations.call', query)

    const args = {
      ...(await this.queryUtils.getQueryParams(query))
    }

    const { count } = await this.organizationsService
      .count({
        where: !isEmpty(query.q) ? JSON.stringify({ name: { $like: query.q } }) : undefined
      })
      .toPromise()

    const data: OrganizationsQueryResult = await this.organizationsService
      .findAll({
        attributes: args.attributes,
        where: !isEmpty(query.q) ? JSON.stringify({ name: { $like: query.q } }) : undefined,
        order: JSON.stringify(args.order),
        offset: args.offset,
        limit: args.limit
      })
      .toPromise()

    const result: QueryResponse = {
      totalRecords: count,
      totalPages: Math.ceil(count / args.limit),
      page: args.page,
      limit: args.limit,
      ...data
    }

    this.logger.info('OrganizationController#findOrganizations.result', result)

    return result
  }
Example #8
Source File: organizations.controller.ts    From nestjs-rest-microservices with MIT License 6 votes vote down vote up
@Post(':name/comments')
  @Header('Content-Type', 'application/json')
  async createOrganizationComment(@Param('name') name: string, @Body() comment: CommentDto): Promise<Comment> {
    this.logger.info('OrganizationController#createOrganizationComment.call', name)

    const organization: Organization = await this.organizationsService
      .findByName({
        name
      })
      .toPromise()

    if (!organization) throw new NotFoundException('NOT_FOUND', 'Organization not found.')

    const result: Comment = await this.commentsService
      .create({
        ...comment,
        organization: organization.id
      })
      .toPromise()

    this.logger.info('OrganizationController#createOrganizationComment.result', result)

    return result
  }
Example #9
Source File: notification.controller.ts    From office-hours with GNU General Public License v3.0 6 votes vote down vote up
// Webhook from twilio
  @Post('/phone/verify')
  @Header('Content-Type', 'text/xml')
  async verifyPhoneUser(
    @Body() body: TwilioBody,
    @Headers('x-twilio-signature') twilioSignature: string,
  ): Promise<string> {
    const message = body.Body.trim().toUpperCase();
    const senderNumber = body.From;

    const twilioAuthToken = this.configService.get('TWILIOAUTHTOKEN');

    const isValidated = twilio.validateRequest(
      twilioAuthToken,
      twilioSignature.trim(),
      `${this.configService.get('DOMAIN')}/api/v1/notifications/phone/verify`,
      body,
    );

    if (!isValidated) {
      throw new UnauthorizedException(
        ERROR_MESSAGES.notificationController.messageNotFromTwilio,
      );
    }

    const messageToUser = await this.notifService.verifyPhone(
      senderNumber,
      message,
    );
    const MessagingResponse = twilio.twiml.MessagingResponse;
    const twiml = new MessagingResponse();
    twiml.message(messageToUser);

    return twiml.toString();
  }
Example #10
Source File: organizations.controller.ts    From nestjs-rest-microservices with MIT License 5 votes vote down vote up
@Get(':name/members')
  @Header('Content-Type', 'application/json')
  async findOrganizationMembers(@Param('name') name: string, @Query() query: RequestQuery): Promise<QueryResponse> {
    this.logger.info('OrganizationController#findOrganizationMembers.call', query)

    const organization: Organization = await this.organizationsService
      .findByName({
        name
      })
      .toPromise()

    if (!organization) throw new NotFoundException('NOT_FOUND', 'Organization not found.')

    const where = { organization: organization.id }

    if (!isEmpty(query.q)) {
      Object.assign(where, {
        name: { $like: query.q }
      })
    }

    const args = {
      ...(await this.queryUtils.getQueryParams(query))
    }

    const { count } = await this.usersService
      .count({
        where: JSON.stringify(where)
      })
      .toPromise()

    const data: UsersQueryResult = await this.usersService
      .findAll({
        attributes: args.attributes,
        where: JSON.stringify(where),
        order: !isEmpty(args.order) ? JSON.stringify(args.order) : JSON.stringify([['followers', 'DESC']]),
        offset: args.offset,
        limit: args.limit
      })
      .toPromise()

    const result: QueryResponse = {
      totalRecords: count,
      totalPages: Math.ceil(count / args.limit),
      page: args.page,
      limit: args.limit,
      ...data
    }

    this.logger.info('OrganizationController#findOrganizationMembers.result', result)

    return result
  }
Example #11
Source File: organizations.controller.ts    From nestjs-rest-microservices with MIT License 5 votes vote down vote up
@Get(':name/comments')
  @Header('Content-Type', 'application/json')
  async findOrganizationComments(@Param('name') name: string, @Query() query: RequestQuery): Promise<QueryResponse> {
    this.logger.info('OrganizationController#findOrganizationComments.call', query)

    const organization: Organization = await this.organizationsService
      .findByName({
        name
      })
      .toPromise()

    if (!organization) throw new NotFoundException('NOT_FOUND', 'Organization not found.')

    const where = { organization: organization.id }

    if (!isEmpty(query.q)) {
      Object.assign(where, {
        name: { $like: query.q }
      })
    }

    const args = {
      ...(await this.queryUtils.getQueryParams(query))
    }

    const { count } = await this.commentsService
      .count({
        where: JSON.stringify(where)
      })
      .toPromise()

    const data: CommentsQueryResult = await this.commentsService
      .findAll({
        attributes: args.attributes,
        where: JSON.stringify(where),
        order: JSON.stringify(args.order),
        offset: args.offset,
        limit: args.limit
      })
      .toPromise()

    const result: QueryResponse = {
      totalRecords: count,
      totalPages: Math.ceil(count / args.limit),
      page: args.page,
      limit: args.limit,
      ...data
    }

    this.logger.info('OrganizationController#findOrganizationComments.call', result)

    return result
  }
Example #12
Source File: organizations.controller.ts    From nestjs-rest-microservices with MIT License 5 votes vote down vote up
@Delete(':name/comments')
  @Header('Content-Type', 'application/json')
  async deleteOrganizationComments(@Param('name') name: string): Promise<Count> {
    this.logger.info('OrganizationController#deleteOrganizationComments.call', name)

    const organization: Organization = await this.organizationsService
      .findByName({
        name
      })
      .toPromise()

    if (!organization) throw new NotFoundException('NOT_FOUND', 'Organization not found.')

    const result: Count = await this.commentsService
      .destroy({
        where: JSON.stringify({ organization: organization.id })
      })
      .toPromise()

    this.logger.info('OrganizationController#deleteOrganizationComments.result', result)

    return result
  }
Example #13
Source File: health.controller.ts    From erda-ui with GNU Affero General Public License v3.0 5 votes vote down vote up
@Get()
  @Header('content-type', 'application/json')
  checkHealth(): string {
    const res = { name: 'erdaUI', status: 'ok' };
    return JSON.stringify(res);
  }