-
Notifications
You must be signed in to change notification settings - Fork 18
/
dict.controller.ts
120 lines (108 loc) · 2.52 KB
/
dict.controller.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import {
GET,
Path,
PathParam,
POST,
PUT,
DELETE,
QueryParam,
Context,
ServiceContext,
Preprocessor,
} from 'typescript-rest';
import { Tags } from 'typescript-rest-swagger';
import * as passport from 'passport';
import {
LoginDto,
LocalStrategyInfo,
LoginResponse,
ProfileResponse,
} from './dto/login.dto';
import { Appearance } from '../../types/appearance';
import { DictService } from './dict.service';
import { DictResponse, CreateDictDto, EditDictDto, PaginateDict } from './dto/dict.dto';
import { KeyValue } from '../../types/data.types';
import { interceptor } from '../../interceptor/interceptor';
/**
* 字典表.
*/
@Tags('core')
@Path('/api/dict')
@Preprocessor(interceptor)
export class DictController {
@Context context: ServiceContext;
constructor(private readonly service = new DictService()) { }
/**
* 获取帐号管理界面配置信息.
*/
@Path('config')
@GET
async getConfig(): Promise<Appearance> {
return this.service.getAppearance();
}
/**
* 搜索字典表
* @param keyword 关键词
* @param value 键
*/
@Path('search')
@GET
async search(
@QueryParam('keyword') keyword?: string,
@QueryParam('value') value?: string,
@QueryParam('category') category?: string,
): Promise<Array<KeyValue>> {
return this.service.search(keyword, value, category);
}
/**
* 创建字典
* @param entry 设置项实体
*/
@POST
async create(entry: CreateDictDto): Promise<DictResponse> {
return this.service.create(entry);
}
/**
* 更新字典
* @param entry 设置项实体
*/
@PUT
async update(entry: EditDictDto): Promise<DictResponse> {
return this.service.update(entry);
}
/**
* 分页查询字典
* @param keyword 关键词
* @param page 第几页
* @param size 页大小
* @param sort 排序
*/
@Path('query')
@GET
async query(
@QueryParam('keyword') keyword?: string,
@QueryParam('category') category?: string,
@QueryParam('page') page?: number,
@QueryParam('size') size?: number,
@QueryParam('sort') sort?: string): Promise<PaginateDict> {
return this.service.query(keyword, category, page, size, sort);
}
/**
* 按编号获取字典
* @param id 键
*/
@Path(':id')
@GET
async get(@PathParam('id') id: string): Promise<DictResponse> {
return this.service.get(id);
}
/**
* 删除字典
* @param id 键
*/
@Path(':id')
@DELETE
async remove(@PathParam('id') id: string): Promise<boolean> {
return this.service.remove(id);
}
}