How to use the @nestjs/common.HttpCode function in @nestjs/common

To help you get started, weโ€™ve selected a few @nestjs/common 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 lonelyhentai / minellius / server / src / role / controllers / permissions.controller.ts View on Github external
@Post()
  async create(@Body() dto: InPermissionDto) {
    try {
      return plainToClass(
        OutPermissionDto,
        await this.service.create({
          item: plainToClass(Permission, dto)
        })
      );
    } catch (error) {
      throw error;
    }
  }
  @Roles('isSuperuser')
  @Permissions('change_permission')
  @HttpCode(HttpStatus.OK)
  @ApiResponse({
    status: HttpStatus.OK,
    type: OutPermissionDto,
    description: 'The record has been successfully updated.'
  })
  @ApiResponse({ status: HttpStatus.FORBIDDEN, description: 'Forbidden.' })
  @ApiImplicitParam({ name: 'id', type: Number })
  @Put(':id')
  async update(@Param('id', new ParseIntPipe()) id, @Body() dto: InPermissionDto) {
    try {
      return plainToClass(
        OutPermissionDto,
        await this.service.update({
          id,
          item: plainToClass(Permission, dto)
        })
github jmcdo29 / zeldaPlay / src / server / app / webhooks / webhooks.controller.ts View on Github external
import { Body, Controller, Headers, HttpCode, Post } from '@nestjs/common';
import { WebhooksService } from './webhooks.service';

@Controller('webhooks')
export class WebhooksController {
  constructor(private readonly whService: WebhooksService) {}

  @Post('/heroku')
  @HttpCode(204)
  herokuWebhook(
    @Headers('heroku-webhook-hmac-sha256') header: string,
    @Body() body: any
  ) {
    this.whService.herokuWebhook(header, body);
  }
}
github nestjs / nest / integration / microservices / src / grpc / grpc.controller.ts View on Github external
import { join } from 'path';
import { Observable, of } from 'rxjs';

@Controller()
export class GrpcController {
  @Client({
    transport: Transport.GRPC,
    options: {
      package: 'math',
      protoPath: join(__dirname, 'math.proto'),
    },
  })
  client: ClientGrpc;

  @Post()
  @HttpCode(200)
  call(@Body() data: number[]): Observable {
    const svc = this.client.getService('Math');
    return svc.sum({ data });
  }

  @GrpcMethod('Math')
  async sum({ data }: { data: number[] }): Promise {
    return of({
      result: data.reduce((a, b) => a + b),
    });
  }
}
github rucken / todo-nestjs / src / libs / core / controllers / users.controller.ts View on Github external
import { OutUserDto } from '../dto/out-user.dto';
import { OutUsersDto } from '../dto/out-users.dto';
import { User } from '../entities/user.entity';
import { AccessGuard } from '../guards/access.guard';
import { ParseIntWithDefaultPipe } from '../pipes/parse-int-with-default.pipe';
import { UsersService } from '../services/users.service';

@ApiUseTags('users')
@ApiBearerAuth()
@Controller('/api/users')
@UseGuards(AccessGuard)
export class UsersController {
  constructor(private readonly service: UsersService) {}
  @Roles('isSuperuser')
  @Permissions('add_user')
  @HttpCode(HttpStatus.CREATED)
  @ApiResponse({
    status: HttpStatus.CREATED,
    type: OutUserDto,
    description: 'The record has been successfully created.'
  })
  @ApiResponse({ status: HttpStatus.FORBIDDEN, description: 'Forbidden.' })
  @Post()
  async create(@Body() dto: InCreateUserDto) {
    try {
      return plainToClass(
        OutUserDto,
        await this.service.create({
          item: await plainToClass(User, dto).setPassword(dto.password)
        })
      );
    } catch (error) {
github jiayisheji / jianshu / libs / database / src / lib / crud.controller.ts View on Github external
}

  @ApiOperation({ title: 'Update an existing record' })
  @ApiCreatedResponse({ description: 'The record has been successfully edited.' })
  @ApiNotFoundResponse({ description: 'Record not found' })
  @ApiBadRequestResponse({ description: 'Invalid input, The response body may contain clues as to what went wrong' })
  @HttpCode(HttpStatus.CREATED)
  @Put(':id')
  public async update(@Param('id') id: string, @Body() entity: Partial>): Promise> {
    return this.crudService.update(id, entity);
  }

  @ApiOperation({ title: 'Delete record' })
  @ApiResponse({ status: HttpStatus.NO_CONTENT, description: 'The record has been successfully deleted' })
  @ApiNotFoundResponse({ description: 'Record not found' })
  @HttpCode(HttpStatus.NO_CONTENT)
  @Delete(':id')
  public async delete(@Param('id') id: string): Promise>> {
    return this.crudService.delete(id);
  }
}
github rucken / core-nestjs / libs / rucken / core-nestjs / src / controllers / groups.controller.ts View on Github external
async findById(@Param('id', new ParseIntPipe()) id) {
    try {
      return plainToClass(
        OutGroupDto,
        await this.service.findById({
          id
        })
      );
    } catch (error) {
      throw error;
    }
  }

  @Roles('isSuperuser')
  @Permissions('read_group')
  @HttpCode(HttpStatus.OK)
  @ApiResponse({
    status: HttpStatus.OK,
    type: OutGroupsDto,
    description: ''
  })
  @ApiResponse({ status: HttpStatus.FORBIDDEN, description: 'Forbidden.' })
  @ApiImplicitQuery({
    name: 'q',
    required: false,
    type: String,
    description: 'Text for search (default: empty)'
  })
  @ApiImplicitQuery({
    name: 'sort',
    required: false,
    type: String,
github rucken / todo-nestjs / src / libs / core / controllers / users.controller.ts View on Github external
async update(@Param('id', new ParseIntPipe()) id, @Body() dto: InUserDto) {
    try {
      return plainToClass(
        OutUserDto,
        await this.service.update({
          id,
          item: await plainToClass(User, dto).setPassword(dto.password)
        })
      );
    } catch (error) {
      throw error;
    }
  }
  @Roles('isSuperuser')
  @Permissions('delete_user')
  @HttpCode(HttpStatus.NO_CONTENT)
  @ApiResponse({
    status: HttpStatus.NO_CONTENT,
    description: 'The record has been successfully deleted.'
  })
  @ApiResponse({ status: HttpStatus.FORBIDDEN, description: 'Forbidden.' })
  @ApiImplicitParam({ name: 'id', type: Number })
  @Delete(':id')
  async delete(@Param('id', new ParseIntPipe()) id) {
    try {
      return plainToClass(
        OutUserDto,
        await this.service.delete({
          id
        })
      );
    } catch (error) {
github nestjs / nest / integration / microservices / src / rmq / rmq.controller.ts View on Github external
@Post()
  @HttpCode(200)
  call(@Query('command') cmd, @Body() data: number[]) {
    return this.client.send({ cmd }, data);
  }

  @Post('stream')
  @HttpCode(200)
  stream(@Body() data: number[]): Observable {
    return this.client
      .send({ cmd: 'streaming' }, data)
      .pipe(scan((a, b) => a + b));
  }

  @Post('concurrent')
  @HttpCode(200)
  concurrent(@Body() data: number[][]): Promise {
    const send = async (tab: number[]) => {
      const expected = tab.reduce((a, b) => a + b);
      const result = await this.client
        .send({ cmd: 'sum' }, tab)
        .toPromise();

      return result === expected;
    };
    return data
      .map(async tab => send(tab))
      .reduce(async (a, b) => (await a) && b);
  }

  @MessagePattern({ cmd: 'sum' })
  sum(data: number[]): number {
github nestjs / nest / integration / microservices / src / rmq / rmq.controller.ts View on Github external
client: ClientProxy;

  constructor() {
    this.client = ClientProxyFactory.create({
      transport: Transport.RMQ,
      options: {
        urls: [`amqp://localhost:5672`],
        queue: 'test',
        queueOptions: { durable: false },
        socketOptions: { noDelay: true },
      },
    });
  }

  @Post()
  @HttpCode(200)
  call(@Query('command') cmd, @Body() data: number[]) {
    return this.client.send({ cmd }, data);
  }

  @Post('stream')
  @HttpCode(200)
  stream(@Body() data: number[]): Observable {
    return this.client
      .send({ cmd: 'streaming' }, data)
      .pipe(scan((a, b) => a + b));
  }

  @Post('concurrent')
  @HttpCode(200)
  concurrent(@Body() data: number[][]): Promise {
    const send = async (tab: number[]) => {
github lonelyhentai / minellius / server / src / data / controllers / period-event.controller.ts View on Github external
@ApiUseTags('period-events')
@Controller('api/period-events')
@UseGuards(AccessGuard)
export class PeriodEventController {

  constructor(
    private readonly periodEventService: PeriodEventService,
  ) {
  }

  @ApiBearerAuth()
  @ApiCreatedResponse({ description: 'Successfully created query and query values.', type: OutPeriodEventDto, isArray: true })
  @ApiResponse({ status: HttpStatus.FORBIDDEN, description: 'Forbidden.' })
  @ApiBadRequestResponse({description: 'Invalid query.' })
  @HttpCode(HttpStatus.CREATED)
  @Post('query')
  async find(
    @Request() req,
    @Body(new ValidationPipe()) createPeriodEventQuery: CreatePeriodEventQueryDto,
  ): Promise {
    Logger.log(`${req.user?req.user.id:''} try to`,PeriodEventService.name+':query');
    const entities = await this.periodEventService.find(createPeriodEventQuery);
    return plainToClass(OutPeriodEventDto,entities);
  }

  @ApiBearerAuth()
  @ApiCreatedResponse({ description: 'Successfully created query and count values.', type: Number })
  @ApiResponse({ status: HttpStatus.FORBIDDEN, description: 'Forbidden.' })
  @ApiBadRequestResponse({description: 'Invalid query.' })
  @HttpCode(HttpStatus.CREATED)
  @Post('count')