69 lines
2.4 KiB
TypeScript
69 lines
2.4 KiB
TypeScript
import { Body, Controller, Delete, Get, Param, Post, Query } from '@nestjs/common';
|
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
|
|
import { ApiResult } from '~/common/decorators/api-result.decorator';
|
|
import { IdParam } from '~/common/decorators/id-param.decorator';
|
|
import { ApiSecurityAuth } from '~/common/decorators/swagger.decorator';
|
|
import { Pagination } from '~/helper/paginate/pagination';
|
|
import { AuthUser } from '~/modules/auth/decorators/auth-user.decorator';
|
|
import { Perm, definePermission } from '~/modules/auth/decorators/permission.decorator';
|
|
import { DictItemEntity } from '~/modules/system/dict-item/dict-item.entity';
|
|
|
|
import { DictItemDto, DictItemQueryDto } from './dict-item.dto';
|
|
import { DictItemService } from './dict-item.service';
|
|
|
|
export const permissions = definePermission('system:dict-item', {
|
|
CREATE: 'create',
|
|
UPDATE: 'update',
|
|
DELETE: 'delete'
|
|
} as const);
|
|
|
|
@ApiTags('System - 字典项模块')
|
|
@ApiSecurityAuth()
|
|
@Controller('dict-item')
|
|
export class DictItemController {
|
|
constructor(private dictItemService: DictItemService) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: '获取字典项列表' })
|
|
@ApiResult({ type: [DictItemEntity], isPage: true })
|
|
async list(@Query() dto: DictItemQueryDto): Promise<Pagination<DictItemEntity>> {
|
|
return this.dictItemService.page(dto);
|
|
}
|
|
|
|
@Get('all/:typeId')
|
|
@ApiOperation({ summary: '一次性通过字典类型获取所有所属的字典项(不分页)' })
|
|
@ApiResult({ type: [DictItemEntity] })
|
|
async getAll(@Param('typeId') typeId: number): Promise<DictItemEntity[]> {
|
|
return this.dictItemService.getAllByType(typeId);
|
|
}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: '新增字典项' })
|
|
@Perm(permissions.CREATE)
|
|
async create(@Body() dto: DictItemDto, @AuthUser() user: IAuthUser): Promise<void> {
|
|
await this.dictItemService.isExistKey(dto);
|
|
dto.createBy = dto.updateBy = user.uid;
|
|
await this.dictItemService.create(dto);
|
|
}
|
|
|
|
@Post(':id')
|
|
@ApiOperation({ summary: '更新字典项' })
|
|
@Perm(permissions.UPDATE)
|
|
async update(
|
|
@IdParam() id: number,
|
|
@Body() dto: DictItemDto,
|
|
@AuthUser() user: IAuthUser
|
|
): Promise<void> {
|
|
dto.updateBy = user.uid;
|
|
await this.dictItemService.update(id, dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@ApiOperation({ summary: '删除指定的字典项' })
|
|
@Perm(permissions.DELETE)
|
|
async delete(@IdParam() id: number): Promise<void> {
|
|
await this.dictItemService.delete(id);
|
|
}
|
|
}
|