@nestjs/common#Get TypeScript Examples

The following examples show how to use @nestjs/common#Get. 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: user.controller.ts    From nestjs-api-example with MIT License 7 votes vote down vote up
  @ApiOperation({ summary: '유저 정보 조회 API' })
    description: 'Id가 일치하는 유저 정보를 조회한다.',
    type: UserResponseDto,
  async findOne(
    @Param('id', new ParseIntPipe()) id: number,
    @Res() res: Response,
  ) {
    const responseDto = await this.userService.findById(id);

    return res.status(HttpStatus.OK).json(instanceToPlain(responseDto));
Example #2
Source File: user.controller.ts    From 42_checkIn with GNU General Public License v3.0 6 votes vote down vote up
  async callback(@Req() req: any, @Res({ passthrough: true }) res: Response) {
    if (req.user) {
      const token = await this.userService.login(req.user);
      res.cookie('w_auth', token);
Example #3
Source File: plugin-newsletter.controller.ts    From Cromwell with MIT License 6 votes vote down vote up
     * The same method as pluginNewsletterStats in PluginNewsletterResolver. 
     * Added for documentation purposes of custom Controllers.
     * */
    /** You can restrict route by assigning JwtAuthGuard and passing allowed roles as a decorator: */
    @Roles('administrator', 'guest', 'author')
    @ApiOperation({ description: 'Get newsletters count' })
        status: 200,
        type: String,
    @ApiForbiddenResponse({ description: 'Forbidden.' })
    async getStats(@Request() request: TRequestWithUser): Promise<string> {

        // Or you can retrieve user info and validate permissions in the method:
        const allowedRoles: TUserRole[] = ['administrator', 'guest', 'author'];
        if (!allowedRoles.includes(request.user?.role))
            throw new ForbiddenException('Forbidden');

        return (await getManager().find(PluginNewsletter) ?? []).length + '';
Example #4
Source File: users.controller.ts    From nest-js-boilerplate with MIT License 6 votes vote down vote up
    schema: {
      type: 'object',
      properties: {
        data: {
          $ref: getSchemaPath(User),
    description: '200. Success. Returns a user',
    description: '404. NotFoundException. User was not found',
    schema: {
      type: 'object',
      example: {
        message: 'string',
    description: '401. UnauthorizedException.',
  @ApiParam({ name: 'id', type: String })
  async getById(
    @Param('id', ParseObjectIdPipe) id: Types.ObjectId,
  ): Promise<User> {
    const foundUser = await this.usersService.getVerifiedUserById(id);

    if (!foundUser) {
      throw new NotFoundException('The user does not exist');

    return foundUser;
Example #5
Source File: attribution.ts    From barista with Apache License 2.0 6 votes vote down vote up
  @ApiResponse({ status: 200, type: [ProjectDistinctLicenseAttributionDto] })
  async getAttributions(@Param('id') id: number): Promise<ProjectDistinctLicenseAttributionDto[]> {
    if (id) {
      const scan = await this.service.findOne(id);
      if (scan) {
        return this.service.distinctLicenseAttributions(scan.id);