mirror of
https://github.com/certd/certd.git
synced 2026-07-06 12:07:32 +08:00
perf: 支持全自动匹配部署宝塔网站证书
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { PermissionException, ValidateException } from './exception/index.js';
|
||||
import { EntityTarget, FindOneOptions, In, Repository, SelectQueryBuilder } from 'typeorm';
|
||||
import { Inject } from '@midwayjs/core';
|
||||
import { TypeORMDataSourceManager } from '@midwayjs/typeorm';
|
||||
import { EntityManager } from 'typeorm/entity-manager/EntityManager.js';
|
||||
import { FindManyOptions } from 'typeorm';
|
||||
import { Constants } from './constants.js';
|
||||
import { PermissionException, ValidateException } from "./exception/index.js";
|
||||
import { EntityTarget, FindOneOptions, In, Repository, SelectQueryBuilder } from "typeorm";
|
||||
import { Inject } from "@midwayjs/core";
|
||||
import { TypeORMDataSourceManager } from "@midwayjs/typeorm";
|
||||
import { EntityManager } from "typeorm/entity-manager/EntityManager.js";
|
||||
import { FindManyOptions } from "typeorm";
|
||||
import { Constants } from "./constants.js";
|
||||
|
||||
export type PageReq<T = any> = {
|
||||
page?: { offset: number; limit: number };
|
||||
@@ -34,7 +34,7 @@ export abstract class BaseService<T> {
|
||||
abstract getRepository(): Repository<T>;
|
||||
|
||||
async transaction(callback: (entityManager: EntityManager) => Promise<any>) {
|
||||
const dataSource = this.dataSourceManager.getDataSource('default');
|
||||
const dataSource = this.dataSourceManager.getDataSource("default");
|
||||
return await dataSource.transaction(callback as any);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ export abstract class BaseService<T> {
|
||||
if (ctx.manager) {
|
||||
return ctx.manager.getRepository(entity);
|
||||
}
|
||||
const dataSource = this.dataSourceManager.getDataSource('default');
|
||||
const dataSource = this.dataSourceManager.getDataSource("default");
|
||||
return dataSource.getRepository(entity);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ export abstract class BaseService<T> {
|
||||
*/
|
||||
async info(id, infoIgnoreProperty?): Promise<T | null> {
|
||||
if (!id) {
|
||||
throw new ValidateException('id不能为空');
|
||||
throw new ValidateException("id不能为空");
|
||||
}
|
||||
const info = await this.getRepository().findOneBy({ id } as any);
|
||||
if (info && infoIgnoreProperty) {
|
||||
@@ -119,18 +119,18 @@ export abstract class BaseService<T> {
|
||||
...where,
|
||||
});
|
||||
await this.modifyAfter(idArr);
|
||||
return ids
|
||||
return ids;
|
||||
}
|
||||
|
||||
resolveIdArr(ids: string | any[]) {
|
||||
if (!ids) {
|
||||
throw new ValidateException('ids不能为空');
|
||||
throw new ValidateException("ids不能为空");
|
||||
}
|
||||
if (typeof ids === 'string') {
|
||||
return ids.split(',');
|
||||
} else if(!Array.isArray(ids)){
|
||||
if (typeof ids === "string") {
|
||||
return ids.split(",");
|
||||
} else if (!Array.isArray(ids)) {
|
||||
return [ids];
|
||||
}else {
|
||||
} else {
|
||||
return ids;
|
||||
}
|
||||
}
|
||||
@@ -147,7 +147,7 @@ export abstract class BaseService<T> {
|
||||
* 新增
|
||||
* @param param 数据
|
||||
*/
|
||||
async add(param: any) {
|
||||
async add(param: any): Promise<{ id: number; [key: string]: any }> {
|
||||
const now = new Date();
|
||||
param.createTime = now;
|
||||
param.updateTime = now;
|
||||
@@ -163,7 +163,7 @@ export abstract class BaseService<T> {
|
||||
* @param param 数据
|
||||
*/
|
||||
async update(param: any) {
|
||||
if (!param.id) throw new ValidateException('id 不能为空');
|
||||
if (!param.id) throw new ValidateException("id 不能为空");
|
||||
param.updateTime = new Date();
|
||||
await this.addOrUpdate(param);
|
||||
await this.modifyAfter(param);
|
||||
@@ -201,10 +201,10 @@ export abstract class BaseService<T> {
|
||||
}
|
||||
|
||||
private buildListQuery(listReq: ListReq<T>) {
|
||||
const { query, sort, buildQuery,select } = listReq;
|
||||
const qb = this.getRepository().createQueryBuilder('main');
|
||||
const { query, sort, buildQuery, select } = listReq;
|
||||
const qb = this.getRepository().createQueryBuilder("main");
|
||||
if (select) {
|
||||
qb.setFindOptions({select});
|
||||
qb.setFindOptions({ select });
|
||||
}
|
||||
if (query) {
|
||||
const keys = Object.keys(query);
|
||||
@@ -223,10 +223,10 @@ export abstract class BaseService<T> {
|
||||
}
|
||||
});
|
||||
if (found) {
|
||||
qb.addOrderBy('main.' + sort.prop, sort.asc ? 'ASC' : 'DESC');
|
||||
qb.addOrderBy("main." + sort.prop, sort.asc ? "ASC" : "DESC");
|
||||
}
|
||||
}
|
||||
qb.addOrderBy('id', 'DESC');
|
||||
qb.addOrderBy("id", "DESC");
|
||||
//自定义query
|
||||
if (buildQuery) {
|
||||
buildQuery(qb);
|
||||
@@ -243,12 +243,12 @@ export abstract class BaseService<T> {
|
||||
return await qb.getMany();
|
||||
}
|
||||
|
||||
async checkUserId(ids: number | number[] = 0, userId: number, userKey = 'userId') {
|
||||
async checkUserId(ids: number | number[] = 0, userId: number, userKey = "userId") {
|
||||
if (ids == null) {
|
||||
throw new ValidateException('id不能为空');
|
||||
throw new ValidateException("id不能为空");
|
||||
}
|
||||
if (userId == null) {
|
||||
throw new ValidateException('userId不能为空');
|
||||
throw new ValidateException("userId不能为空");
|
||||
}
|
||||
if (!Array.isArray(ids)) {
|
||||
ids = [ids];
|
||||
@@ -268,20 +268,20 @@ export abstract class BaseService<T> {
|
||||
if (!res || res.length === ids.length) {
|
||||
return;
|
||||
}
|
||||
throw new PermissionException('权限不足');
|
||||
throw new PermissionException("权限不足");
|
||||
}
|
||||
|
||||
filterIds(ids: any[]) {
|
||||
filterIds(ids: any[]) {
|
||||
if (!ids) {
|
||||
throw new ValidateException('ids不能为空');
|
||||
throw new ValidateException("ids不能为空");
|
||||
}
|
||||
return ids.filter((item) => {
|
||||
return item!=null && item != ""
|
||||
return ids.filter(item => {
|
||||
return item != null && item != "";
|
||||
});
|
||||
}
|
||||
async batchDelete(ids: number[], userId: number,projectId?:number) {
|
||||
async batchDelete(ids: number[], userId: number, projectId?: number) {
|
||||
ids = this.filterIds(ids);
|
||||
if(userId!=null){
|
||||
if (userId != null) {
|
||||
const userProjectQuery = this.buildUserProjectQuery(userId, projectId);
|
||||
const list = await this.getRepository().find({
|
||||
where: {
|
||||
@@ -289,9 +289,9 @@ export abstract class BaseService<T> {
|
||||
id: In(ids),
|
||||
...userProjectQuery,
|
||||
},
|
||||
})
|
||||
});
|
||||
// @ts-ignore
|
||||
ids = list.map(item => item.id)
|
||||
ids = list.map(item => item.id);
|
||||
}
|
||||
|
||||
await this.delete(ids);
|
||||
@@ -300,19 +300,18 @@ export abstract class BaseService<T> {
|
||||
async findOne(options: FindOneOptions<T>) {
|
||||
return await this.getRepository().findOne(options);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export function checkUserProjectParam(userId: number, projectId: number) {
|
||||
if (projectId != null ){
|
||||
if( userId !== Constants.enterpriseUserId) {
|
||||
throw new ValidateException('userId projectId 错误');
|
||||
if (projectId != null) {
|
||||
if (userId !== Constants.enterpriseUserId) {
|
||||
throw new ValidateException("userId projectId 错误");
|
||||
}
|
||||
return true
|
||||
}else{
|
||||
if( userId != null) {
|
||||
return true
|
||||
return true;
|
||||
} else {
|
||||
if (userId != null) {
|
||||
return true;
|
||||
}
|
||||
throw new ValidateException('userId不能为空');
|
||||
throw new ValidateException("userId不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user