Files
certd/packages/ui/certd-server/src/controller/user/pipeline/access-controller.ts
T

116 lines
3.4 KiB
TypeScript
Raw Normal View History

2024-08-27 13:46:19 +08:00
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
2024-11-01 00:59:09 +08:00
import { Constants, CrudController } from '@certd/lib-server';
2024-12-22 14:00:46 +08:00
import { AccessService } from '@certd/lib-server';
2025-01-15 01:05:34 +08:00
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
2024-11-30 01:57:09 +08:00
import { AccessDefine } from '@certd/pipeline';
2023-01-29 13:44:19 +08:00
/**
* 授权
*/
@Provide()
@Controller('/api/pi/access')
2023-05-23 18:01:20 +08:00
export class AccessController extends CrudController<AccessService> {
2023-01-29 13:44:19 +08:00
@Inject()
service: AccessService;
2024-11-20 18:12:10 +08:00
@Inject()
authService: AuthService;
2023-01-29 13:44:19 +08:00
2024-10-03 22:03:49 +08:00
getService(): AccessService {
2023-01-29 13:44:19 +08:00
return this.service;
}
2023-06-27 09:29:43 +08:00
@Post('/page', { summary: Constants.per.authOnly })
2023-01-29 13:44:19 +08:00
async page(@Body(ALL) body) {
body.query = body.query ?? {};
2024-10-14 00:19:55 +08:00
delete body.query.userId;
2025-07-28 23:36:10 +08:00
body.query.userId = this.getUserId()
let name = body.query?.name;
delete body.query.name;
2024-10-14 00:19:55 +08:00
const buildQuery = qb => {
2025-07-28 23:36:10 +08:00
if (name) {
qb.andWhere('name like :name', { name: `%${name.trim()}%` });
}
2024-10-14 00:19:55 +08:00
};
const res = await this.service.page({
query: body.query,
page: body.page,
2024-10-14 14:00:24 +08:00
sort: body.sort,
2024-10-14 00:19:55 +08:00
buildQuery,
});
return this.ok(res);
2023-01-29 13:44:19 +08:00
}
2023-06-27 09:29:43 +08:00
@Post('/list', { summary: Constants.per.authOnly })
2023-01-29 13:44:19 +08:00
async list(@Body(ALL) body) {
body.query = body.query ?? {};
body.query.userId = this.getUserId();
2023-01-29 13:44:19 +08:00
return super.list(body);
}
2023-06-27 09:29:43 +08:00
@Post('/add', { summary: Constants.per.authOnly })
2023-01-29 13:44:19 +08:00
async add(@Body(ALL) bean) {
2024-10-14 00:19:55 +08:00
bean.userId = this.getUserId();
2023-01-29 13:44:19 +08:00
return super.add(bean);
}
2023-06-27 09:29:43 +08:00
@Post('/update', { summary: Constants.per.authOnly })
2023-01-29 13:44:19 +08:00
async update(@Body(ALL) bean) {
2024-10-14 00:19:55 +08:00
await this.service.checkUserId(bean.id, this.getUserId());
delete bean.userId;
2023-01-29 13:44:19 +08:00
return super.update(bean);
}
2023-06-27 09:29:43 +08:00
@Post('/info', { summary: Constants.per.authOnly })
async info(@Query('id') id: number) {
2024-10-14 00:19:55 +08:00
await this.service.checkUserId(id, this.getUserId());
2023-01-29 13:44:19 +08:00
return super.info(id);
}
2023-06-27 09:29:43 +08:00
@Post('/delete', { summary: Constants.per.authOnly })
async delete(@Query('id') id: number) {
2024-10-14 00:19:55 +08:00
await this.service.checkUserId(id, this.getUserId());
2023-01-29 13:44:19 +08:00
return super.delete(id);
}
2023-06-27 09:29:43 +08:00
@Post('/define', { summary: Constants.per.authOnly })
2024-09-29 14:57:20 +08:00
async define(@Query('type') type: string) {
2024-03-22 00:50:02 +08:00
const access = this.service.getDefineByType(type);
return this.ok(access);
2023-01-29 13:44:19 +08:00
}
2024-10-28 18:20:10 +08:00
@Post('/getSecretPlain', { summary: Constants.per.authOnly })
async getSecretPlain(@Body(ALL) body: { id: number; key: string }) {
const value = await this.service.getById(body.id, this.getUserId());
return this.ok(value[body.key]);
}
2023-06-27 09:29:43 +08:00
@Post('/accessTypeDict', { summary: Constants.per.authOnly })
2023-01-29 13:44:19 +08:00
async getAccessTypeDict() {
2025-04-28 23:34:08 +08:00
let list: AccessDefine[] = this.service.getDefineList();
list = list.sort((a,b) => {
return (a.order??10) - (b.order??10);
});
2023-01-29 13:44:19 +08:00
const dict = [];
for (const item of list) {
dict.push({
value: item.name,
label: item.title,
2024-11-30 01:57:09 +08:00
icon: item.icon,
2023-01-29 13:44:19 +08:00
});
}
return this.ok(dict);
}
2024-11-20 18:12:10 +08:00
@Post('/simpleInfo', { summary: Constants.per.authOnly })
async simpleInfo(@Query('id') id: number) {
await this.authService.checkEntityUserId(this.ctx, this.service, id);
const res = await this.service.getSimpleInfo(id);
return this.ok(res);
}
2025-07-12 23:00:04 +08:00
@Post('/getDictByIds', { summary: Constants.per.authOnly })
async getDictByIds(@Body('ids') ids: number[]) {
const res = await this.service.getSimpleByIds(ids, this.getUserId());
return this.ok(res);
}
2023-01-29 13:44:19 +08:00
}