Files
certd/packages/ui/certd-server/src/controller/user/basic/group-controller.ts
T

88 lines
2.6 KiB
TypeScript
Raw Normal View History

import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { Constants, CrudController } from '@certd/lib-server';
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
import { GroupService } from '../../../modules/basic/service/group-service.js';
/**
* 通知
*/
@Provide()
@Controller('/api/basic/group')
export class GroupController extends CrudController<GroupService> {
@Inject()
service: GroupService;
@Inject()
authService: AuthService;
getService(): GroupService {
return this.service;
}
@Post('/page', { summary: Constants.per.authOnly })
async page(@Body(ALL) body: any) {
2026-02-13 21:28:17 +08:00
const {projectId,userId} = await this.getProjectUserIdRead();
body.query = body.query ?? {};
2026-02-13 21:28:17 +08:00
body.query.projectId = projectId;
delete body.query.userId;
const buildQuery = qb => {
2026-02-13 21:28:17 +08:00
qb.andWhere('user_id = :userId', { userId });
};
const res = await this.service.page({
query: body.query,
page: body.page,
sort: body.sort,
buildQuery,
});
return this.ok(res);
}
@Post('/list', { summary: Constants.per.authOnly })
async list(@Body(ALL) body: any) {
2026-02-13 21:28:17 +08:00
const {projectId,userId} = await this.getProjectUserIdRead();
body.query = body.query ?? {};
2026-02-13 21:28:17 +08:00
body.query.projectId = projectId;
body.query.userId = userId;
return await super.list(body);
}
@Post('/add', { summary: Constants.per.authOnly })
async add(@Body(ALL) bean: any) {
2026-02-13 21:28:17 +08:00
const {projectId,userId} = await this.getProjectUserIdRead();
bean.projectId = projectId;
bean.userId = userId;
return await super.add(bean);
}
@Post('/update', { summary: Constants.per.authOnly })
async update(@Body(ALL) bean) {
2026-02-13 21:28:17 +08:00
await this.checkOwner(this.getService(), bean.id, "write");
delete bean.userId;
2026-02-13 21:28:17 +08:00
delete bean.projectId;
return await super.update(bean);
}
@Post('/info', { summary: Constants.per.authOnly })
async info(@Query('id') id: number) {
2026-02-13 21:28:17 +08:00
await this.checkOwner(this.getService(), id, "read");
return await super.info(id);
}
@Post('/delete', { summary: Constants.per.authOnly })
async delete(@Query('id') id: number) {
2026-02-13 21:28:17 +08:00
await this.checkOwner(this.getService(), id, "write");
return await super.delete(id);
}
@Post('/all', { summary: Constants.per.authOnly })
async all(@Query('type') type: string) {
2026-02-13 21:28:17 +08:00
const {projectId,userId} = await this.getProjectUserIdRead();
const list: any = await this.service.find({
where: {
2026-02-13 21:28:17 +08:00
projectId,
userId,
type,
},
});
return this.ok(list);
}
}