How to use the @nestjs/common.Put 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 vellengs / nestx / packages / server / src / cms / controllers / article.controller.ts View on Github external
constructor(private readonly service: ArticleService) {}

  @Get('search')
  async search(
    @Query('keyword') keyword?: string,
    @Query('value') value?: string,
  ): Promise {
    return this.service.search(keyword, value);
  }

  @Post()
  async create(entry: CreateArticleDto): Promise {
    return this.service.create(entry);
  }

  @Put()
  async update(entry: EditArticleDto): Promise {
    return this.service.update(entry);
  }

  @Get('query')
  async query(
    @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.service.querySearch(keyword, page, size, sort);
  }

  @Delete(':id')
  async remove(@Param('id') id: string): Promise {
github EndyKaufman / nest-permissions-seed / src / libs / core / controllers / groups.controller.ts View on Github external
object = await this.groupsRepository.save(object)
            return plainToClass(OutGroupDto, object);
        } catch (error) {
            throw error;
        }
    }
    @Roles('isSuperuser')
    @Permissions('change_group')
    @HttpCode(HttpStatus.OK)
    @ApiResponse({
        status: HttpStatus.OK, type: OutGroupDto,
        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: InGroupDto
        ) {
        try {
            let object = plainToClass(Group, dto);
            object.id = id;
            object = await this.groupsRepository.save(object);
            return plainToClass(OutGroupDto, object);
        } catch (error) {
            throw error;
        }
    }
    @Roles('isSuperuser')
    @Permissions('delete_group')
    @HttpCode(HttpStatus.NO_CONTENT)
github vellengs / nestx / packages / servers / nestx-base / src / controllers / dicts.controller.ts View on Github external
import { CreateDictReq, EditDictReq, KeyValueDto } from './../dto';
import { Tags } from 'nest-swagger';

@Tags('core')
@Controller('dict')
@UseGuards(AuthGuard('jwt'), RolesGuard)
@UseInterceptors(LoggingInterceptor)
export class DictsController {
  constructor(private readonly dictService: DictsService) {}

  @Post()
  async create(@Body() entry: CreateDictReq) {
    return this.dictService.create(plainToClass(CreateDictReq, entry));
  }

  @Put()
  async update(@Body() entry: EditDictReq): Promise {
    return this.dictService.update(plainToClass(EditDictReq, entry));
  }

  @Get('search')
  async search(
    @Query('keyword') keyword?: string,
    @Query('value') value?: string,
    @Query('category') category?: string,
  ): Promise {
    return this.dictService.search(
      keyword,
      value,
      category,
      10,
      'name',
github vellengs / nestx / packages / servers / nestx-base / src / controllers / roles.controller.ts View on Github external
import { CreateRoleReq, EditRoleReq, KeyValueDto } from "./../dto";
import { Tags } from "nest-swagger";

@Tags("core")
@Controller("role")
@UseGuards(AuthGuard("jwt"), RolesGuard)
@UseInterceptors(LoggingInterceptor)
export class RolesController {
  constructor(private readonly roleService: RolesService) {}

  @Post()
  async create(@Body() entry: CreateRoleReq) {
    return this.roleService.create(plainToClass(CreateRoleReq, entry));
  }

  @Put()
  async update(@Body() entry: EditRoleReq): Promise {
    return this.roleService.update(plainToClass(EditRoleReq, entry));
  }

  @Get("search")
  async search(
    @Query("keyword") keyword?: string,
    @Query("value") value?: string
  ): Promise {
    return this.roleService.search(keyword, value);
  }

  @Get("query")
  async query(
    @Query("keyword") keyword?: string,
    @Query("page", new NullableParseIntPipe()) page: number = 1,
github ahmetuysal / nest-hackathon-starter / src / user / user.controller.ts View on Github external
} from '@nestjs/common';
import { ApiUseTags, ApiBearerAuth } from '@nestjs/swagger';
import { UserService } from './user.service';
import { AuthGuard } from '@nestjs/passport';
import { UpdateUserRequest } from '../contract';
import { User } from './user.entity';
import { Usr } from './user.decorator';
import { updateUserEntityFields } from './user.mapper';

@ApiUseTags('users')
@Controller('users')
export class UserController {
  constructor(private readonly userService: UserService) {}

  @ApiBearerAuth()
  @Put(':id')
  @HttpCode(HttpStatus.OK)
  @UseGuards(AuthGuard())
  async updateUser(
    @Param('id', ParseIntPipe) id: number,
    @Body() updateRequest: UpdateUserRequest,
    @Usr() user: User,
  ): Promise {
    if (id !== user.id || id !== updateRequest.user.id) {
      throw new UnauthorizedException();
    }
    updateUserEntityFields(user, updateRequest.user);
    await this.userService.updateUser(user);
  }
}
github surmon-china / nodepress / src / modules / article / article.controller.ts View on Github external
@HttpProcessor.handle('ๆ‰น้‡ๅˆ ้™คๆ–‡็ซ ')
  delArticles(@Body() body: DelArticles): Promise {
    return this.articleService.batchDelete(body.article_ids);
  }

  @Get(':id')
  @UseGuards(HumanizedJwtAuthGuard)
  @HttpProcessor.handle({ message: '่Žทๅ–ๆ–‡็ซ ่ฏฆๆƒ…', error: HttpStatus.NOT_FOUND })
  getArticle(@QueryParams() { params, isAuthenticated }): Promise<article> {
    const isObjectId = isNaN(Number(params.id));
    return isAuthenticated &amp;&amp; isObjectId
      ? this.articleService.getDetailByObjectId(params.id)
      : this.articleService.getFullDetailForUser(params.id);
  }

  @Put(':id')
  @UseGuards(JwtAuthGuard)
  @HttpProcessor.handle('ไฟฎๆ”นๆ–‡็ซ ')
  putArticle(@QueryParams() { params }, @Body() article: Article): Promise<article> {
    return this.articleService.update(params.id, article);
  }

  @Delete(':id')
  @UseGuards(JwtAuthGuard)
  @HttpProcessor.handle('ๅˆ ้™คๅ•ไธชๆ–‡็ซ ')
  delArticle(@QueryParams() { params }): Promise<article> {
    return this.articleService.delete(params.id);
  }
}
</article></article></article>
github vellengs / nestx / packages / server / src / cms / controllers / widget.controller.ts View on Github external
constructor(private readonly service: WidgetService) {}

  @Get('search')
  async search(
    @Query('keyword') keyword?: string,
    @Query('value') value?: string,
  ): Promise {
    return this.service.search(keyword, value);
  }

  @Post()
  async create(@Body() entry: CreateWidgetDto): Promise {
    return this.service.create(entry);
  }

  @Put()
  async update(@Body() entry: EditWidgetDto): Promise {
    return this.service.update(entry);
  }

  @Get('query')
  async query(
    @Query('keyword') keyword?: string,
    @Query('page', new NullableParseIntPipe()) page: number = 1,
    @Query('size', new NullableParseIntPipe()) size: number = 10,
    @Query('sort') sort?: string,
  ): Promise&gt; {
    return this.service.querySearch(keyword, page, size, sort);
  }

  @Delete(':id')
  async remove(@Param('id') id: string): Promise {
github rucken / todo-nestjs / src / libs / core / controllers / content-types.controller.ts View on Github external
);
    } catch (error) {
      throw error;
    }
  }
  @Roles('isSuperuser')
  @Permissions('change_content-type')
  @HttpCode(HttpStatus.OK)
  @ApiResponse({
    status: HttpStatus.OK,
    type: OutContentTypeDto,
    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: InContentTypeDto
  ) {
    try {
      return plainToClass(
        OutContentTypeDto,
        await this.service.update({
          id,
          item: plainToClass(ContentType, dto)
        })
      );
    } catch (error) {
      throw error;
    }
  }
github vellengs / nestx-server / src / core / controllers / dicts.controller.ts View on Github external
import { ResultList } from './../../common/interfaces/result.interface';
import { DictsService } from './dicts.service';
import { Dict } from './../interfaces/dict.interface';
import { CreateDictReq, EditDictReq, KeyValueDto } from './../dto';

@Controller('dicts')
@UseGuards(AuthGuard('jwt'))
export class DictsController {
  constructor(private readonly dictService: DictsService) { }

  @Post()
  async create(@Body() entry: CreateDictReq) {
    return this.dictService.create(plainToClass(CreateDictReq, entry));
  }

  @Put()
  async update(@Body() entry: EditDictReq): Promise {
    return this.dictService.update(plainToClass(EditDictReq, entry));
  }

  @Get('search')
  async search(
    @Query('keyword') keyword?: string,
    @Query('value') value?: string,
  ): Promise {
    return this.dictService.search(keyword, value);
  }

  @Get('query')
  async query(
    @Query('keyword') keyword?: string,
    @Query('index', new ParseIntPipe()) index: number = 1,
github devonfw / devon4node / template / src / todo / todo.controller.ts View on Github external
const { description } = params;
      if (!description || description.trim() === '') {
        throw new HttpException(
          'Description is required',
          HttpStatus.BAD_REQUEST,
        );
      }
      const newTodo = await this._todoService.createTodo(params);
      const { id, ...result } = newTodo;
      return result as TodoDTO;
    } catch (error) {
      throw new HttpException(error, HttpStatus.INTERNAL_SERVER_ERROR);
    }
  }

  @Put()
  @ApiResponse({ status: HttpStatus.CREATED, type: TodoDTO })
  @ApiResponse({ status: HttpStatus.BAD_REQUEST, type: ApiException })
  @ApiOperation(getOperationId('Todo', 'Update'))
  async update(@Body() viewmodel: TodoDTO): Promise {
    try {
      if (!viewmodel || !viewmodel.id) {
        throw new HttpException('Missing Parameters', HttpStatus.BAD_REQUEST);
      }

      const updated = await this._todoService.update(viewmodel.id, viewmodel);
      if (updated) {
        const { id, ...result } = updated;
        return result as TodoDTO;
      } else {
        throw new HttpException(
          'An internal error has occurred and the object has not been updated',