Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 {
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)
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',
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,
} 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);
}
}
@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 && 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>
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> {
return this.service.querySearch(keyword, page, size, sort);
}
@Delete(':id')
async remove(@Param('id') id: string): Promise {
);
} 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;
}
}
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,
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',