2023-01-29 13:44:19 +08:00
|
|
|
import {
|
|
|
|
|
ALL,
|
|
|
|
|
Body,
|
|
|
|
|
Controller,
|
|
|
|
|
Inject,
|
|
|
|
|
Post,
|
|
|
|
|
Provide,
|
|
|
|
|
Query,
|
|
|
|
|
} from '@midwayjs/decorator';
|
|
|
|
|
import { CrudController } from '../../../basic/crud-controller';
|
|
|
|
|
import { AccessService } from '../service/access-service';
|
2023-06-27 09:29:43 +08:00
|
|
|
import { Constants } from '../../../basic/constants';
|
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;
|
|
|
|
|
|
|
|
|
|
getService() {
|
|
|
|
|
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 ?? {};
|
|
|
|
|
body.query.userId = this.ctx.user.id;
|
|
|
|
|
return super.page(body);
|
|
|
|
|
}
|
|
|
|
|
|
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.userId = this.ctx.user.id;
|
|
|
|
|
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) {
|
|
|
|
|
bean.userId = this.ctx.user.id;
|
|
|
|
|
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) {
|
|
|
|
|
await this.service.checkUserId(bean.id, this.ctx.user.id);
|
|
|
|
|
return super.update(bean);
|
|
|
|
|
}
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/info', { summary: Constants.per.authOnly })
|
2023-01-29 13:44:19 +08:00
|
|
|
async info(@Query('id') id) {
|
|
|
|
|
await this.service.checkUserId(id, this.ctx.user.id);
|
|
|
|
|
return super.info(id);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/delete', { summary: Constants.per.authOnly })
|
2023-01-29 13:44:19 +08:00
|
|
|
async delete(@Query('id') id) {
|
|
|
|
|
await this.service.checkUserId(id, this.ctx.user.id);
|
|
|
|
|
return super.delete(id);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/define', { summary: Constants.per.authOnly })
|
2023-01-29 13:44:19 +08:00
|
|
|
async define(@Query('type') type) {
|
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) {
|
|
|
|
|
dict.push({
|
|
|
|
|
value: item.name,
|
|
|
|
|
label: item.title,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return this.ok(dict);
|
|
|
|
|
}
|
|
|
|
|
}
|