-
Notifications
You must be signed in to change notification settings - Fork 18
/
role.controller.ts
117 lines (105 loc) · 2.41 KB
/
role.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
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 { KeyValue } from '../../types/data.types';
import { CreateRoleDto, RoleResponse, EditRoleDto, PaginateRole } from './dto/role.dto';
import { RoleService } from './role.service';
import { interceptor } from '../../interceptor/interceptor';
/**
* 角色管理.
*/
@Tags('core')
@Path('/api/role')
@Preprocessor(interceptor)
export class RoleController {
@Context context: ServiceContext;
constructor(private readonly service = new RoleService()) { }
/**
* 获取角色管理界面配置信息.
*/
@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,
): Promise<Array<KeyValue>> {
return this.service.search(keyword, value);
}
/**
* 创建角色
* @param entry 设置项实体
*/
@POST
async create(entry: CreateRoleDto): Promise<RoleResponse> {
return this.service.create(entry);
}
/**
* 更新角色
* @param entry 设置项实体
*/
@PUT
async update(entry: EditRoleDto): Promise<RoleResponse> {
return this.service.update(entry);
}
/**
* 分页查询角色
* @param keyword 关键词
* @param page 第几页
* @param size 页大小
* @param sort 排序
*/
@Path('query')
@GET
async query(
@QueryParam('keyword') keyword?: string,
@QueryParam('page') page?: number,
@QueryParam('size') size?: number,
@QueryParam('sort') sort?: string): Promise<PaginateRole> {
return this.service.query(keyword, page, size, sort);
}
/**
* 按编号获取角色
* @param id 键
*/
@Path(':id')
@GET
async get(@PathParam('id') id: string): Promise<RoleResponse> {
return this.service.get(id);
}
/**
* 删除角色
* @param id 键
*/
@Path(':id')
@DELETE
async remove(@PathParam('id') id: string): Promise<boolean> {
return this.service.remove(id);
}
}