How to use the @nestjs/common.Get 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 Coding-Coach / find-a-mentor-api / src / modules / lists / favorites.controller.ts View on Github external
import { List } from './interfaces/list.interface';
import { UsersService } from '../common/users.service';
import { ListsService } from './lists.service';
import { ListDto } from './dto/list.dto';

@ApiUseTags('/users/:userid/favorites')
@ApiBearerAuth()
@Controller('users/:userid/favorites')
export class FavoritesController {
  constructor(
    private readonly usersService: UsersService,
    private readonly listsService: ListsService,
  ) {}

  @ApiOperation({ title: 'Returns the favorite list for the given user' })
  @Get()
  async list(@Req() request: Request, @Param('userid') userId: string) {
    const current: User = await this.usersService.findByAuth0Id(
      request.user.auth0Id,
    );
    const user: User = await this.usersService.findById(userId);

    // Make sure user exist
    if (!user) {
      throw new BadRequestException('User not found');
    }

    // Only admins or current user can get the favorites
    if (!current._id.equals(user._id) && !current.roles.includes(Role.ADMIN)) {
      throw new UnauthorizedException(
        'Not authorized to perform this operation',
      );
github kuangshp / nestjs-mysql-api / src / core / role / role.controller.ts View on Github external
@ApiUseTags('role')
@ApiBearerAuth()
@Controller('role')
export class RoleController {
  constructor(private readonly roleService: RoleService) {}

  @ApiOperation({ title: 'ๆทปๅŠ ่ง’่‰ฒ' })
  @HttpCode(HttpStatus.CREATED)
  @Post()
  async create(@Body() data: CreateRoleDto): Promise {
    return this.roleService.create(data);
  }

  @ApiOperation({ title: 'ๆŸฅ่ฏขๆ‰€ๆœ‰็š„่ง’่‰ฒ', description: 'ๆ”ฏๆŒๅˆ†้กตๆŸฅ่ฏข' })
  @Get()
  @UseInterceptors(PaginateInterceptor)
  @HttpCode(HttpStatus.OK)
  async showAll(
    @Query('pageSize', new ParseIntPipe()) pageSize: number,
    @Query('pageNumber', new ParseIntPipe()) pageNumber: number,
  ): Promise {
    return await this.roleService.showAll(pageSize, pageNumber);
  }

  @ApiOperation({ title: 'ๆ นๆฎ่ง’่‰ฒidๆŸฅ่ฏข่ง’่‰ฒ' })
  @Get(':id')
  @HttpCode(HttpStatus.OK)
  async getById(
    @Param('id', new ParseIntPipe()) id: string,
  ): Promise {
    return await this.roleService.getById(id);
github ramesaliyev / mom / services / be-api / .backups / tutorial / app.controller.ts View on Github external
@Controller()
@UseFilters(HttpExceptionFilter)
@UseInterceptors(LoggingInterceptor)
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  root(): string {
    if (Math.random() > 0.5) {
      throw new HttpException('FuckYou', HttpStatus.FORBIDDEN);
    }

    return this.appService.root();
  }

  @Get('user/:id')
  findOne(@User() userInfo) {
    return userInfo;
  }
}
github danielwii / asuna-node-server / src / modules / search / search.controller.ts View on Github external
import { BadRequestException, Controller, Get, Param, Query } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import * as _ from 'lodash';
import * as R from 'ramda';
import { getConnection } from 'typeorm';
import { Profile } from '../common';
import { DBHelper, parseListParam, parseNormalWhereAndRelatedFields, parseOrder, parseWhere } from '../core/db';
import { LoggerFactory } from '../common/logger';

const logger = LoggerFactory.getLogger('SearchController');

@ApiTags('core')
@Controller('api/search')
export class SearchController {
  @Get(':model')
  async search(
    @Param('model') model: string,
    @Query('keywords') keywords: string,
    @Query('page') page = 1,
    @Query('size') size = 10,
    @Query('profile') profile?: Profile,
    @Query('fields') fields?: string | string[],
    @Query('on') onFields?: string | string[],
    @Query('where') whereStr?: string,
    @Query('sort') sortStr?: string,
    @Query('relations') relationsStr?: string,
  ): Promise<{ query: object; items: any[]; total: number; page: number; size: number }> {
    const repository = DBHelper.repo(model);
    const select = parseListParam(fields, field => `${model}.${field}`);
    const on = parseListParam(onFields);
github jmcdo29 / zeldaPlay / src / server / app / character / characters / characters.controller.ts View on Github external
import { Controller, Get, Post } from '@nestjs/common';

import { Character } from '../../entities/character_schema';
import { CharactersService } from '../characters.service';

@Controller('characters')
export class CharactersController {
  constructor(private readonly characterService: CharactersService) {}

  @Get('/')
  async getAll(): Promise>> {
    const characters = await this.characterService.getAll();
    return characters;
  }

  @Post(':userId')
  upsertOne() {
    return this.characterService.upsertChar();
  }

  @Get('/user/:userId')
  getUser() {
    return this.characterService.getUserChars();
  }

  @Get(':characterId')
github nestjs / bull / sample / app.controller.ts View on Github external
import { InjectQueue } from 'nest-bull';
import { Queue } from 'bull';

@Controller()
export class AppController {
  constructor(@InjectQueue('test_queue') private readonly queue: Queue) {}

  @Get('twice/:x')
  async createTwiceJob(@Param('x', new ParseIntPipe()) x: number) {
    return {
      message: 'Twice job created',
      data: await this.queue.add('twice', x),
    };
  }

  @Get('thrice/:x')
  async createThriceJob(@Param('x', new ParseIntPipe()) x: number) {
    return {
      message: 'Thrice job created',
      data: await this.queue.add('thrice', x),
    };
  }
}
github wix / quix / quix-frontend / service / src / modules / auth / auth.controller.ts View on Github external
import {User} from './user-decorator';
import {UsersService} from './users.service';

@Controller('/api/')
export class AuthController {
  private readonly logger = new Logger(AuthController.name);
  private readonly envSettings: EnvSettings;
  constructor(
    private readonly authService: AuthService,
    private readonly configService: ConfigService,
    private readonly userService: UsersService,
  ) {
    this.envSettings = this.configService.getEnvSettings();
  }

  @Get('user')
  @UseGuards(AuthGuard())
  async getUser(@User() user: IGoogleUser) {
    await this.userService.doUserLogin(user);
    return user;
  }

  @Get('authenticate')
  async doAuth(@Query('code') code: string, @Res() response: Response) {
    try {
      const up = await this.authService.getUserProfileFromCode(code);
      if (up) {
        const token = await this.authService.createUserJwtToken(up);
        response.cookie(this.envSettings.AuthCookieName, token, {
          maxAge: this.envSettings.CookieAge,
        });
        await this.userService.doUserLogin(up);
github vellengs / nestx / packages / servers / nestx-base / src / controllers / menus.controller.ts View on Github external
): Promise {
    return this.menuService.search(keyword, value);
  }

  @Get("query")
  async query(
    @Query("isMenu") isMenu: boolean,
    @Query("keyword") keyword?: string,
    @Query("page", new NullableParseIntPipe()) page: number = 1,
    @Query("size", new NullableParseIntPipe()) size: number = 10,
    @Query("sort") sort?: string
  ): Promise> {
    return this.menuService.querySearch(isMenu, keyword, page, size, sort);
  }

  @Get("permissions")
  async getPermissionTags(): Promise<
    {
      id: string;
      name: string;
      desc: string;
    }[]
  > {
    return this.menuService.getAllPermissionTags();
  }

  @Get("auth")
  async getUserMenus(@Req() request: any): Promise {
    return this.menuService.getAuthenticatedMenus(request.user);
  }

  @Get(":id")
github brucx / mp-push-nestjs / src / user / user.controller.ts View on Github external
import { Controller, Param, Get } from '@nestjs/common';
import { UserService } from './user.service';
import { User } from './user.entity';

@Controller()
export class UserController {
  constructor(
    private readonly userService: UserService,
    ) {}

  @Get('user/:openid')
  login(@Param('openid') openid): Promise {
    return this.userService.login(openid);
  }

  @Get('users')
  getUsers(): Promise {
    return this.userService.findAll();
  }
}
github TechEmpower / FrameworkBenchmarks / frameworks / TypeScript / nest / src / bench / bench.controller.ts View on Github external
@Header('Server', 'NestJS')
    @Header('Content-Type', 'application/json')
    sayHello() {

        return JSON.stringify({message: 'Hello, World!'});
    }

    @Get('/plaintext')
    @Header('Server', 'NestJS')
    @Header('Content-Type', 'text/plain')
    plaintext() {

        return 'Hello, World!';
    }

    @Get('/fortunes')
    @Render('fortunes')
    @Header('Server', 'NestJS')
    fortunes(@Res() res: Response) {
        return this.benchService.getFortunes().then( fortunes => ({
            fortunes,
        }));
    }

}