mirror of
https://github.com/certd/certd.git
synced 2026-05-15 12:37:30 +08:00
chore: project manager
This commit is contained in:
@@ -54,7 +54,6 @@ export class SubDomainService extends BaseService<SubDomainEntity> {
|
||||
throw new Error('域名已存在');
|
||||
}
|
||||
return await super.add(bean)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
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 { ProjectEntity } from '../entity/project.js';
|
||||
|
||||
@Provide()
|
||||
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
||||
export class ProjectService extends BaseService<ProjectEntity> {
|
||||
@InjectEntityModel(ProjectEntity)
|
||||
repository: Repository<ProjectEntity>;
|
||||
|
||||
|
||||
@Inject()
|
||||
sysSettingsService: SysSettingsService;
|
||||
|
||||
//@ts-ignore
|
||||
getRepository() {
|
||||
return this.repository;
|
||||
}
|
||||
|
||||
async add(bean: ProjectEntity) {
|
||||
const {name} = bean;
|
||||
if (!name) {
|
||||
throw new Error('项目名称不能为空');
|
||||
}
|
||||
const exist = await this.repository.findOne({
|
||||
where: {
|
||||
name,
|
||||
userId:0,
|
||||
},
|
||||
});
|
||||
if (exist) {
|
||||
throw new Error('项目名称已存在');
|
||||
}
|
||||
bean.userId = 0
|
||||
bean.disabled = false
|
||||
return await super.add(bean)
|
||||
}
|
||||
|
||||
async setDisabled(id: number, disabled: boolean) {
|
||||
const project = await this.repository.findOne({
|
||||
where: {
|
||||
id,
|
||||
userId:0,
|
||||
},
|
||||
});
|
||||
if (!project) {
|
||||
throw new Error('项目不存在');
|
||||
}
|
||||
await this.repository.update({
|
||||
userId:0,
|
||||
}, {
|
||||
disabled,
|
||||
});
|
||||
project.disabled = disabled;
|
||||
await this.repository.save(project);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
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 { ProjectUserEntity } from '../entity/project-user.js';
|
||||
|
||||
@Provide()
|
||||
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
||||
export class ProjectUserService extends BaseService<ProjectUserEntity> {
|
||||
@InjectEntityModel(ProjectUserEntity)
|
||||
repository: Repository<ProjectUserEntity>;
|
||||
|
||||
@Inject()
|
||||
sysSettingsService: SysSettingsService;
|
||||
|
||||
//@ts-ignore
|
||||
getRepository() {
|
||||
return this.repository;
|
||||
}
|
||||
|
||||
async add(bean: ProjectUserEntity) {
|
||||
const {projectId, userId} = bean;
|
||||
if (!projectId) {
|
||||
throw new Error('项目ID不能为空');
|
||||
}
|
||||
if (!userId) {
|
||||
throw new Error('用户ID不能为空');
|
||||
}
|
||||
const exist = await this.repository.findOne({
|
||||
where: {
|
||||
projectId,
|
||||
userId,
|
||||
},
|
||||
});
|
||||
if (exist) {
|
||||
throw new Error('项目用户已存在');
|
||||
}
|
||||
return await super.add(bean)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user