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

102 lines
3.0 KiB
TypeScript
Raw Normal View History

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';
import { AccessService } from '../../modules/pipeline/service/access-service.js';
2024-11-20 18:12:10 +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')
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;
const buildQuery = qb => {
qb.andWhere('user_id = :userId', { userId: this.getUserId() });
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() {
2024-11-30 01:57:09 +08:00
const list: AccessDefine[] = this.service.getDefineList();
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);
}
2023-01-29 13:44:19 +08:00
}