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

81 lines
2.1 KiB
TypeScript
Raw Normal View History

import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
2024-10-03 22:03:49 +08:00
import { CrudController } from '@certd/lib-server';
2024-07-15 00:30:33 +08:00
import { AccessService } from '../service/access-service.js';
2024-10-03 22:03:49 +08:00
import { Constants } from '@certd/lib-server';
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-10-13 01:27:08 +08:00
userId() {
return this.getUserId();
}
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-13 01:27:08 +08:00
body.query.userId = this.userId();
return await super.page(body);
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) {
2024-10-13 01:27:08 +08:00
body.userId = this.userId();
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-13 01:27:08 +08:00
bean.userId = this.userId();
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-13 01:27:08 +08:00
await this.service.checkUserId(bean.id, this.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-13 01:27:08 +08:00
await this.service.checkUserId(id, this.userId());
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-13 01:27:08 +08:00
await this.service.checkUserId(id, this.userId());
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
}
2023-06-27 09:29:43 +08:00
@Post('/accessTypeDict', { summary: Constants.per.authOnly })
2023-01-29 13:44:19 +08:00
async getAccessTypeDict() {
const list = this.service.getDefineList();
const dict = [];
for (const item of list) {
2024-09-29 14:57:20 +08:00
if (item?.deprecated) {
continue;
}
2023-01-29 13:44:19 +08:00
dict.push({
value: item.name,
label: item.title,
});
}
return this.ok(dict);
}
}