chore: domain manager

This commit is contained in:
xiaojunnuo
2025-07-10 17:00:47 +08:00
parent f3002e4fb6
commit 39dc5c8160
6 changed files with 110 additions and 7 deletions
@@ -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);
}
}