mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:52:20 +08:00
chore: domain manager
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {Inject, Provide, Scope, ScopeEnum} from '@midwayjs/core';
|
||||
import {InjectEntityModel} from '@midwayjs/typeorm';
|
||||
import {Repository} from 'typeorm';
|
||||
import {Not, Repository} from 'typeorm';
|
||||
import {AccessService, BaseService} from '@certd/lib-server';
|
||||
import {DomainEntity} from '../entity/domain.js';
|
||||
|
||||
@@ -22,4 +22,49 @@ export class DomainService extends BaseService<DomainEntity> {
|
||||
return this.repository;
|
||||
}
|
||||
|
||||
async add(param) {
|
||||
if (param.userId == null ){
|
||||
throw new Error('userId 不能为空');
|
||||
}
|
||||
if (!param.domain) {
|
||||
throw new Error('domain 不能为空');
|
||||
}
|
||||
const old = await this.repository.findOne({
|
||||
where: {
|
||||
domain: param.domain,
|
||||
userId: param.userId
|
||||
}
|
||||
});
|
||||
if (old) {
|
||||
throw new Error(`域名(${param.domain})不能重复`);
|
||||
}
|
||||
return await super.add(param);
|
||||
}
|
||||
|
||||
async update(param) {
|
||||
if (!param.id) {
|
||||
throw new Error('id 不能为空');
|
||||
}
|
||||
const old = await this.info(param.id)
|
||||
if (!old) {
|
||||
throw new Error('domain记录不存在');
|
||||
}
|
||||
|
||||
const same = await this.repository.findOne({
|
||||
where: {
|
||||
domain: param.domain,
|
||||
userId: old.userId,
|
||||
id: Not(param.id)
|
||||
}
|
||||
});
|
||||
|
||||
if (same) {
|
||||
throw new Error(`域名(${param.domain})不能重复`);
|
||||
}
|
||||
delete param.userId
|
||||
return await super.update(param);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user