How to use the @nestjs/common.Delete 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 compodoc / compodoc / test / fixtures / nest-app / src / auth.controller.ts View on Github external
import { Controller, Headers, Post, Res, HttpStatus, Delete } from '@nestjs/common';

@Controller('auth')
export class AuthController {
    constructor() {}

    @Post()
    async login(@Headers() headers, @Res() res) {}

    @Delete()
    async logout(@Res() res) {}
}
github m24927605 / Nestjs30Days / day22 / Day22_MongoDB / project / src / app / Users / modules / users.controller.ts View on Github external
@ApiResponse({ status: 201, description: 'The record has been successfully created.' })
    @ApiResponse({ status: 403, description: 'Forbidden.' })
    public async createUser( @Response() res, @Body() createUsersDTO: CreateUsersDTO) {

        const users = await this.usersServices.create(createUsersDTO);
        return res.status(HttpStatus.OK).json(createUsersDTO);
    }

    @Patch('users/:ID')
    public async updateUser( @Param() param, @Response() res, @Body() body) {

        const users = await this.usersServices.update(param.ID, body);
        return res.status(HttpStatus.OK).json(users);
    }

    @Delete('users/:ID')
    public async deleteUser( @Param() param, @Response() res) {

        const users = await this.usersServices.delete(param.ID);
        return res.status(HttpStatus.OK).json(users);
    }
}
github bs32g1038 / node-blog / node-blog-api / src / modules / file / file.controller.ts View on Github external
});
        const totalCount = await this.fileService.count({ parentId: query.parentId });
        return {
            items,
            totalCount
        };
    }

    @Get('/files/getFolderName/:id')
    @JoiValidationPipe(FileController.idSchema)
    @Roles('admin')
    async getFile(@Param() params: { id: string }): Promise {
        return await this.fileService.getFile(params.id);
    }

    @Delete('/files/:id')
    @JoiValidationPipe(FileController.idSchema)
    @Roles('admin')
    async deleteFile(@Param() params: { id: string }): Promise {
        return await this.fileService.deleteFile(params.id);
    }
}
github vellengs / nestx-server / packages / common / src / services / controller.service.ts View on Github external
@Param("id") id: string | number | Date | ObjectID
  ): Promise {
    return await this.service.findOne(id);
  }

  @Post()
  async create(@Body() entity: any): Promise {
    return await this.service.create(entity);
  }

  @Put()
  async update(@Body() entity: any): Promise {
    return await this.service.update(entity);
  }

  @Delete(":id")
  async remove(@Param("id") id: string): Promise {
    return await this.service.remove(id);
  }
}
github dzzzzzy / Nestjs-Learning / demo / zoo / src / animals / animal.controller.ts View on Github external
import { Animal } from './animal.entity';
import { AnimalService } from './animal.service';

@Controller('animal')
export class AnimalController {
    constructor(
        @Inject(AnimalService) private readonly animalService: AnimalService,
    ) { }

    @Post()
    async createAnimal(@Body() animal: Animal): Promise {
        await this.animalService.createAnimal(animal);
        return { code: 200, message: 'ๅˆ›ๅปบๅŠจ็‰ฉๆˆๅŠŸ' };
    }

    @Delete(':id')
    async deleteAnimal(@Param('id') id: number): Promise {
        await this.animalService.deleteAnimal(id);
        return { code: 200, message: 'ๅˆ ้™คๅŠจ็‰ฉๆˆๅŠŸ' };
    }

    @Put(':id')
    async updateAnimal(@Param('id') id: number, @Body() animal: Animal): Promise {
        await this.animalService.updateAnimal(id, animal);
        return { code: 200, message: 'ๆ›ดๆ–ฐๅŠจ็‰ฉๆˆๅŠŸ' };
    }

    @Get(':id')
    async findOneAnimal(@Param('id') id: number): Promise {
        const data = await this.animalService.findOneAnimal(id);
        return { code: 200, message: 'ๆŸฅ่ฏขๅŠจ็‰ฉๆˆๅŠŸ', data };
    }
github saltyshiomix / ark / server / api / users / users.controller.ts View on Github external
@Get(':id')
  @UseInterceptors(ClassSerializerInterceptor)
  public async findOne(@Param('id') id): Promise {
    return await this.service.findOne(id);
  }

  @Put(':id')
  public async update(@Param('id') id, @Body() updateUserDto: UpdateUserDto): Promise {
    const user: User = await this.service.findOne(id);
    const { name } = updateUserDto;
    user.name = name;
    await this.service.save(user);
  }

  @Delete(':id')
  public async delete(@Param('id') id): Promise {
    await this.service.delete(id);
  }
}
github rucken / todo-nestjs / src / libs / core / controllers / users.controller.ts View on Github external
})
      );
    } 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) {
      throw error;
    }
  }
  @Roles('isSuperuser')
  @Permissions('read_user')
  @HttpCode(HttpStatus.OK)
  @ApiResponse({
github tsmean / tsmean / backend / src / animal-list / animal-list.controller.ts View on Github external
if (!animalList.owner || animalList.owner.id !== currentUser.id) {
      throw new ForbiddenException('Access denied!');
    }
    return this.animalListService.update(id, partialEntry);
  }

  @ApiBearerAuth()
  @ApiOperation({title: 'Delete animals list'})
  @ApiResponse({
    status: 204,
    description: 'The list has been successfully deleted.'
  })
  @ApiResponse({status: 401, description: 'You have to be logged to delete the list!'})
  @ApiResponse({status: 403, description: 'You need to be an owner for the list to delete it!'})
  @Authorized()
  @Delete(':id')
  async remove(
    @Param('id', new ParseIntPipe())
    id: number,
    @CurrentUser() currentUser: User
  ) {
    const animalList = await this.animalListService.findOneById(id);
    if (!animalList.owner || animalList.owner.id !== currentUser.id) {
      throw new ForbiddenException('Access denied!');
    }
    return this.animalListService.remove(animalList.id);
  }
}
github backstopmedia / nest-book-example / src / modules / comment / comment.controller.ts View on Github external
@Put('comments/:commentId')
    public async update(
        @User() user: IUser,
        @Comment() comment: IComment,
        @Body() body: any,
        @Res() res
    ) {
        if (user.id !== comment.userId)
            return res
                .status(HttpStatus.NOT_FOUND)
                .send('Unable to find the comment.');
        await this.commentService.update(comment.id, body);
        return res.status(HttpStatus.OK).send();
    }

    @Delete('comments/:commentId')
    public async delete(
        @User() user: IUser,
        @Comment() comment: IComment,
        @Res() res
    ) {
        if (user.id !== comment.userId)
            return res
                .status(HttpStatus.NOT_FOUND)
                .send('Unable to find the comment.');
        await this.commentService.delete(comment.id);
        return res.status(HttpStatus.OK).send();
    }
}
github bs32g1038 / node-blog / server / modules / comment / comment.controller.ts View on Github external
}

    @Delete('/comments/:id')
    @Roles('admin')
    @JoiValidationPipe(CommentController.idSchema)
    async deleteComment(@Param() params: { id: string }) {
        return await this.commentService.deleteComment(params.id);
    }

    @Get('/recent-comments')
    @Roles('admin')
    async recentComments() {
        return await this.commentService.recentComments();
    }

    @Delete('/comments')
    @Roles('admin')
    @JoiValidationPipe(CommentController.deleteCommentsSchema)
    deleteComments(@Body() body: { commentIds: string[] }): Promise {
        return this.commentService.batchDelete(body.commentIds);
    }
}