mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2025-12-11 16:52:49 +00:00
fix tenant
This commit is contained in:
parent
2edbd2ef6d
commit
fb46db45d3
@ -29,7 +29,7 @@
|
|||||||
"mysql2": "^3.12.0",
|
"mysql2": "^3.12.0",
|
||||||
"svg-captcha": "^1.4.0",
|
"svg-captcha": "^1.4.0",
|
||||||
"tslib": "^2.8.1",
|
"tslib": "^2.8.1",
|
||||||
"typeorm": "npm:@cool-midway/typeorm@8.0.0",
|
"typeorm": "npm:@cool-midway/typeorm@0.3.20",
|
||||||
"uuid": "^11.0.5",
|
"uuid": "^11.0.5",
|
||||||
"ws": "^8.18.0"
|
"ws": "^8.18.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -15,7 +15,6 @@ import {
|
|||||||
Config,
|
Config,
|
||||||
IMidwayApplication,
|
IMidwayApplication,
|
||||||
IMidwayContext,
|
IMidwayContext,
|
||||||
Init,
|
|
||||||
Inject,
|
Inject,
|
||||||
} from '@midwayjs/core';
|
} from '@midwayjs/core';
|
||||||
import { Utils } from '../../../comm/utils';
|
import { Utils } from '../../../comm/utils';
|
||||||
@ -67,7 +66,7 @@ export class TenantSubscriber implements EntitySubscriberInterface<any> {
|
|||||||
];
|
];
|
||||||
|
|
||||||
// 不进行租户过滤的用户
|
// 不进行租户过滤的用户
|
||||||
ignoreUsername = ['admin'];
|
ignoreUsername = [];
|
||||||
|
|
||||||
@Inject()
|
@Inject()
|
||||||
utils: Utils;
|
utils: Utils;
|
||||||
@ -163,7 +162,7 @@ export class TenantSubscriber implements EntitySubscriberInterface<any> {
|
|||||||
if (!this.tenant?.enable) return;
|
if (!this.tenant?.enable) return;
|
||||||
const tenantId = this.getTenantId();
|
const tenantId = this.getTenantId();
|
||||||
if (tenantId) {
|
if (tenantId) {
|
||||||
queryBuilder.where(
|
queryBuilder.andWhere(
|
||||||
`${
|
`${
|
||||||
queryBuilder.alias ? queryBuilder.alias + '.' : ''
|
queryBuilder.alias ? queryBuilder.alias + '.' : ''
|
||||||
}tenantId = ${tenantId}`
|
}tenantId = ${tenantId}`
|
||||||
@ -175,11 +174,16 @@ export class TenantSubscriber implements EntitySubscriberInterface<any> {
|
|||||||
* 插入时添加租户ID
|
* 插入时添加租户ID
|
||||||
* @param queryBuilder
|
* @param queryBuilder
|
||||||
*/
|
*/
|
||||||
async afterInsertQueryBuilder(queryBuilder: InsertQueryBuilder<any>) {
|
afterInsertQueryBuilder(queryBuilder: InsertQueryBuilder<any>) {
|
||||||
if (!this.tenant?.enable) return;
|
if (!this.tenant?.enable) return;
|
||||||
const tenantId = await this.getTenantId();
|
const tenantId = this.getTenantId();
|
||||||
if (tenantId) {
|
if (tenantId) {
|
||||||
queryBuilder.setParameter('tenantId', tenantId);
|
const values = queryBuilder.expressionMap.valuesSet;
|
||||||
|
if (Array.isArray(values)) {
|
||||||
|
queryBuilder.values(values.map(item => ({ ...item, tenantId })));
|
||||||
|
} else if (typeof values === 'object') {
|
||||||
|
queryBuilder.values({ ...values, tenantId });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,12 +191,12 @@ export class TenantSubscriber implements EntitySubscriberInterface<any> {
|
|||||||
* 更新时添加租户ID和条件
|
* 更新时添加租户ID和条件
|
||||||
* @param queryBuilder
|
* @param queryBuilder
|
||||||
*/
|
*/
|
||||||
async afterUpdateQueryBuilder(queryBuilder: UpdateQueryBuilder<any>) {
|
afterUpdateQueryBuilder(queryBuilder: UpdateQueryBuilder<any>) {
|
||||||
if (!this.tenant?.enable) return;
|
if (!this.tenant?.enable) return;
|
||||||
const tenantId = await this.getTenantId();
|
const tenantId = this.getTenantId();
|
||||||
if (tenantId) {
|
if (tenantId) {
|
||||||
queryBuilder.set({ tenantId });
|
queryBuilder.set({ tenantId });
|
||||||
queryBuilder.where(`tenantId = ${tenantId}`);
|
queryBuilder.andWhere(`tenantId = ${tenantId}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,11 +204,11 @@ export class TenantSubscriber implements EntitySubscriberInterface<any> {
|
|||||||
* 删除时添加租户ID和条件
|
* 删除时添加租户ID和条件
|
||||||
* @param queryBuilder
|
* @param queryBuilder
|
||||||
*/
|
*/
|
||||||
async afterDeleteQueryBuilder(queryBuilder: DeleteQueryBuilder<any>) {
|
afterDeleteQueryBuilder(queryBuilder: DeleteQueryBuilder<any>) {
|
||||||
if (!this.tenant?.enable) return;
|
if (!this.tenant?.enable) return;
|
||||||
const tenantId = await this.getTenantId();
|
const tenantId = this.getTenantId();
|
||||||
if (tenantId) {
|
if (tenantId) {
|
||||||
queryBuilder.where(`tenantId = ${tenantId}`);
|
queryBuilder.andWhere(`tenantId = ${tenantId}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user