Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) {}
}
@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);
}
}
});
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);
}
}
@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);
}
}
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 };
}
@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);
}
}
})
);
} 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({
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);
}
}
@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();
}
}
}
@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);
}
}