mirror of
https://github.com/certd/certd.git
synced 2026-05-15 20:47:31 +08:00
chore: admin mode
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { BaseController, Constants } from '@certd/lib-server';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
|
||||
import { ProjectService } from '../../../modules/sys/enterprise/service/project-service.js';
|
||||
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/enterprise/project')
|
||||
export class UserProjectController extends BaseController {
|
||||
@Inject()
|
||||
service: ProjectService;
|
||||
@Inject()
|
||||
authService: AuthService;
|
||||
|
||||
getService(): ProjectService {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Post('/list', { summary: Constants.per.authOnly })
|
||||
async list(@Body(ALL) body: any) {
|
||||
const userId= this.getUserId();
|
||||
const res = await this.service.getByUserId(userId);
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,9 @@ export class AuditLogEntity {
|
||||
@Column({ name: 'project_name', comment: '项目名称' })
|
||||
projectName: string;
|
||||
|
||||
@Column({ name: 'type', comment: '类型' })
|
||||
type: string;
|
||||
|
||||
@Column({ name: 'action', comment: '操作' })
|
||||
action: string;
|
||||
|
||||
|
||||
@@ -28,4 +28,7 @@ export class ProjectEntity {
|
||||
default: () => 'CURRENT_TIMESTAMP',
|
||||
})
|
||||
updateTime: Date;
|
||||
|
||||
// user permission read write admin
|
||||
permission:string
|
||||
}
|
||||
|
||||
@@ -38,4 +38,12 @@ export class ProjectMemberService extends BaseService<ProjectMemberEntity> {
|
||||
return await super.add(bean)
|
||||
}
|
||||
|
||||
async getByUserId(userId: number) {
|
||||
return await this.repository.find({
|
||||
where: {
|
||||
userId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import {Inject, Provide, Scope, ScopeEnum} from '@midwayjs/core';
|
||||
import {BaseService, SysSettingsService} from '@certd/lib-server';
|
||||
import {InjectEntityModel} from '@midwayjs/typeorm';
|
||||
import {Repository} from 'typeorm';
|
||||
import {In, Repository} from 'typeorm';
|
||||
import { ProjectEntity } from '../entity/project.js';
|
||||
import { ProjectMemberService } from './project-member-service.js';
|
||||
|
||||
@Provide()
|
||||
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
||||
@@ -10,6 +11,8 @@ export class ProjectService extends BaseService<ProjectEntity> {
|
||||
@InjectEntityModel(ProjectEntity)
|
||||
repository: Repository<ProjectEntity>;
|
||||
|
||||
@Inject()
|
||||
projectMemberService: ProjectMemberService;
|
||||
|
||||
@Inject()
|
||||
sysSettingsService: SysSettingsService;
|
||||
@@ -56,4 +59,26 @@ export class ProjectService extends BaseService<ProjectEntity> {
|
||||
project.disabled = disabled;
|
||||
await this.repository.save(project);
|
||||
}
|
||||
|
||||
async getByUserId(userId: number) {
|
||||
|
||||
const memberList = await this.projectMemberService.getByUserId(userId);
|
||||
const projectIds = memberList.map(item => item.projectId);
|
||||
const projectList = await this.repository.find({
|
||||
where: {
|
||||
id: In(projectIds),
|
||||
},
|
||||
});
|
||||
|
||||
const memberPermissionMap = memberList.reduce((prev, cur) => {
|
||||
prev[cur.projectId] = cur.permission;
|
||||
return prev;
|
||||
}, {} as Record<number, string>);
|
||||
|
||||
projectList.forEach(item => {
|
||||
item.permission = memberPermissionMap[item.id] || 'read';
|
||||
})
|
||||
|
||||
return projectList
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user