mirror of
https://github.com/certd/certd.git
synced 2026-07-09 06:07:37 +08:00
feat: 新增推广等级激励功能
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { PermissionException, ValidateException } from './exception/index.js';
|
||||
import { FindOneOptions, In, Repository, SelectQueryBuilder } from 'typeorm';
|
||||
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';
|
||||
@@ -20,6 +20,10 @@ export type ListReq<T = any> = {
|
||||
select?: any;
|
||||
};
|
||||
|
||||
export type ServiceContext = {
|
||||
manager?: EntityManager;
|
||||
};
|
||||
|
||||
/**
|
||||
* 服务基类
|
||||
*/
|
||||
@@ -34,6 +38,14 @@ export abstract class BaseService<T> {
|
||||
return await dataSource.transaction(callback as any);
|
||||
}
|
||||
|
||||
protected getRepo<E>(ctx: ServiceContext, entity: EntityTarget<E>): Repository<E> {
|
||||
if (ctx.manager) {
|
||||
return ctx.manager.getRepository(entity);
|
||||
}
|
||||
const dataSource = this.dataSourceManager.getDataSource('default');
|
||||
return dataSource.getRepository(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得单个ID
|
||||
* @param id ID
|
||||
@@ -81,7 +93,7 @@ export abstract class BaseService<T> {
|
||||
if (idArr.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
await this.getRepository().delete({
|
||||
id: In(idArr),
|
||||
...where,
|
||||
@@ -283,4 +295,4 @@ export function checkUserProjectParam(userId: number, projectId: number) {
|
||||
}
|
||||
throw new ValidateException('userId不能为空');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user