增加了relation接口
This commit is contained in:
parent
870547941c
commit
8ff4c1407b
|
|
@ -64,4 +64,7 @@ export declare type CommonAspectDict<ED extends EntityDict & BaseEntityDict, Cxt
|
|||
detail: string;
|
||||
coordinate: [number, number];
|
||||
}[]>;
|
||||
loadRelations: (params: {
|
||||
entities: keyof ED[];
|
||||
}, context: Cxt) => Promise<ED['userRelation']['OpSchema'][]>;
|
||||
};
|
||||
|
|
|
|||
24
lib/crud.js
24
lib/crud.js
|
|
@ -4,7 +4,6 @@ exports.count = exports.fetchRows = exports.aggregate = exports.select = exports
|
|||
const tslib_1 = require("tslib");
|
||||
const types_1 = require("oak-domain/lib/types");
|
||||
const relation_1 = require("oak-domain/lib/store/relation");
|
||||
const filter_1 = require("oak-domain/lib/store/filter");
|
||||
const assert_1 = tslib_1.__importDefault(require("assert"));
|
||||
async function operate(params, context) {
|
||||
const { entity, operation, option } = params;
|
||||
|
|
@ -91,33 +90,38 @@ async function select(params, context) {
|
|||
* 如 sku的create权限(jichuang项目), sku.companyService.company上有user relation
|
||||
* 如果sku为空,也应当试着把companyService数据返回给前台
|
||||
* by Xc 20230320
|
||||
*
|
||||
* 感觉已经不需要了,新的权限判定可以判定filter或者data上的cascade路径条件
|
||||
* by Xc 20230519
|
||||
*/
|
||||
const { data, filter } = selection;
|
||||
/* const { data, filter } = selection;
|
||||
for (const attr in data) {
|
||||
const rel = (0, relation_1.judgeRelation)(context.getSchema(), entity, attr);
|
||||
const rel = judgeRelation<ED>(context.getSchema(), entity, attr);
|
||||
if (rel === 2) {
|
||||
const f = filter && (0, filter_1.getCascadeEntityFilter)(filter, attr);
|
||||
const f = filter && getCascadeEntityFilter(filter, attr);
|
||||
if (f) {
|
||||
await context.select(attr, {
|
||||
data: data[attr],
|
||||
filter: f,
|
||||
indexFrom: 0,
|
||||
count: 1, // 取一行应该就够了
|
||||
}, option || {});
|
||||
count: 1, // 取一行应该就够了
|
||||
},
|
||||
option || {})
|
||||
}
|
||||
}
|
||||
else if (typeof rel === 'string') {
|
||||
const f = filter && (0, filter_1.getCascadeEntityFilter)(filter, attr);
|
||||
const f = filter && getCascadeEntityFilter(filter, attr);
|
||||
if (f) {
|
||||
await context.select(rel, {
|
||||
data: data[attr],
|
||||
filter: f,
|
||||
indexFrom: 0,
|
||||
count: 1, // 取一行应该就够了
|
||||
}, option || {});
|
||||
count: 1, // 取一行应该就够了
|
||||
},
|
||||
option || {})
|
||||
}
|
||||
}
|
||||
}
|
||||
} */
|
||||
}
|
||||
else {
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { amap } from './amap';
|
|||
import { getTranslations } from './locales';
|
||||
import { registerPorts, clearPorts, importEntity, exportEntity, getImportationTemplate } from './port';
|
||||
import { searchPoi } from './geo';
|
||||
import { loadRelations } from './relation';
|
||||
declare const aspectDict: {
|
||||
operate: typeof operate;
|
||||
select: typeof select;
|
||||
|
|
@ -15,6 +16,7 @@ declare const aspectDict: {
|
|||
exportEntity: typeof exportEntity;
|
||||
getImportationTemplate: typeof getImportationTemplate;
|
||||
searchPoi: typeof searchPoi;
|
||||
loadRelations: typeof loadRelations;
|
||||
};
|
||||
export default aspectDict;
|
||||
export * from './AspectDict';
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ const port_1 = require("./port");
|
|||
Object.defineProperty(exports, "registerPorts", { enumerable: true, get: function () { return port_1.registerPorts; } });
|
||||
Object.defineProperty(exports, "clearPorts", { enumerable: true, get: function () { return port_1.clearPorts; } });
|
||||
const geo_1 = require("./geo");
|
||||
const relation_1 = require("./relation");
|
||||
const aspectDict = {
|
||||
operate: crud_1.operate,
|
||||
select: crud_1.select,
|
||||
|
|
@ -21,6 +22,7 @@ const aspectDict = {
|
|||
exportEntity: port_1.exportEntity,
|
||||
getImportationTemplate: port_1.getImportationTemplate,
|
||||
searchPoi: geo_1.searchPoi,
|
||||
loadRelations: relation_1.loadRelations,
|
||||
};
|
||||
exports.default = aspectDict;
|
||||
tslib_1.__exportStar(require("./AspectDict"), exports);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
import { EntityDict } from 'oak-domain/lib/types';
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
|
||||
export declare function loadRelations<ED extends BaseEntityDict & EntityDict, Cxt extends AsyncContext<ED>>(params: {
|
||||
entities: (keyof ED)[];
|
||||
}, context: Cxt): Promise<ED["userRelation"]["OpSchema"][]>;
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.loadRelations = void 0;
|
||||
const types_1 = require("oak-domain/lib/types");
|
||||
const lodash_1 = require("oak-domain/lib/utils/lodash");
|
||||
async function loadRelations(params, context) {
|
||||
const { entities } = params;
|
||||
const userId = context.getCurrentUserId();
|
||||
if (!userId) {
|
||||
throw new types_1.OakUnloggedInException();
|
||||
}
|
||||
const userRelations = await context.select('userRelation', {
|
||||
data: {
|
||||
id: 1,
|
||||
userId: 1,
|
||||
relationId: 1,
|
||||
entity: 1,
|
||||
entityId: 1,
|
||||
relation: {
|
||||
id: 1,
|
||||
entity: 1,
|
||||
entityId: 1,
|
||||
name: 1,
|
||||
display: 1,
|
||||
actionAuth$relation: {
|
||||
$entity: 'actionAuth',
|
||||
data: {
|
||||
id: 1,
|
||||
path: 1,
|
||||
destEntity: 1,
|
||||
deActions: 1,
|
||||
},
|
||||
},
|
||||
relationAuth$sourceRelation: {
|
||||
$entity: 'relationAuth',
|
||||
data: {
|
||||
id: 1,
|
||||
sourceRelationId: 1,
|
||||
destRelationId: 1,
|
||||
destRelation: {
|
||||
id: 1,
|
||||
entity: 1,
|
||||
entityId: 1,
|
||||
name: 1,
|
||||
display: 1,
|
||||
},
|
||||
path: 1,
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
filter: {
|
||||
userId,
|
||||
entity: {
|
||||
$in: entities,
|
||||
},
|
||||
},
|
||||
}, {});
|
||||
const result = userRelations.map((userRelation) => (0, lodash_1.omit)(userRelation, 'relation'));
|
||||
return result;
|
||||
}
|
||||
exports.loadRelations = loadRelations;
|
||||
|
|
@ -76,4 +76,7 @@ export type CommonAspectDict<ED extends EntityDict & BaseEntityDict, Cxt extends
|
|||
count?: number;
|
||||
typeCode?: string;
|
||||
}) => Promise<{ id: string; areaId: string; poiName: string; detail: string; coordinate: [number, number] }[]>;
|
||||
loadRelations: (params: {
|
||||
entities: keyof ED[],
|
||||
}, context: Cxt) => Promise<ED['userRelation']['OpSchema'][]>;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -158,8 +158,11 @@ export async function select<
|
|||
* 如 sku的create权限(jichuang项目), sku.companyService.company上有user relation
|
||||
* 如果sku为空,也应当试着把companyService数据返回给前台
|
||||
* by Xc 20230320
|
||||
*
|
||||
* 感觉已经不需要了,新的权限判定可以判定filter或者data上的cascade路径条件
|
||||
* by Xc 20230519
|
||||
*/
|
||||
const { data, filter } = selection;
|
||||
/* const { data, filter } = selection;
|
||||
for (const attr in data) {
|
||||
const rel = judgeRelation<ED>(context.getSchema(), entity, attr);
|
||||
if (rel === 2) {
|
||||
|
|
@ -186,7 +189,7 @@ export async function select<
|
|||
option || {})
|
||||
}
|
||||
}
|
||||
}
|
||||
} */
|
||||
}
|
||||
else {
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { amap } from './amap';
|
|||
import { getTranslations } from './locales';
|
||||
import { registerPorts, clearPorts, importEntity, exportEntity, getImportationTemplate } from './port';
|
||||
import { searchPoi } from './geo';
|
||||
import { loadRelations } from './relation';
|
||||
|
||||
const aspectDict = {
|
||||
operate,
|
||||
|
|
@ -16,6 +17,7 @@ const aspectDict = {
|
|||
exportEntity,
|
||||
getImportationTemplate,
|
||||
searchPoi,
|
||||
loadRelations,
|
||||
};
|
||||
|
||||
export default aspectDict;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,75 @@
|
|||
import {
|
||||
OperateOption,
|
||||
EntityDict,
|
||||
SelectOption,
|
||||
OakUnloggedInException,
|
||||
OakUserUnpermittedException,
|
||||
StorageSchema,
|
||||
} from 'oak-domain/lib/types';
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
|
||||
import { omit } from 'oak-domain/lib/utils/lodash';
|
||||
|
||||
export async function loadRelations<
|
||||
ED extends BaseEntityDict & EntityDict,
|
||||
Cxt extends AsyncContext<ED>
|
||||
>(params: {
|
||||
entities: (keyof ED)[],
|
||||
}, context: Cxt) {
|
||||
const { entities } = params;
|
||||
const userId = context.getCurrentUserId();
|
||||
if (!userId) {
|
||||
throw new OakUnloggedInException();
|
||||
}
|
||||
const userRelations = await context.select('userRelation', {
|
||||
data: {
|
||||
id: 1,
|
||||
userId: 1,
|
||||
relationId: 1,
|
||||
entity: 1,
|
||||
entityId: 1,
|
||||
relation: {
|
||||
id: 1,
|
||||
entity: 1,
|
||||
entityId: 1,
|
||||
name: 1,
|
||||
display: 1,
|
||||
actionAuth$relation: {
|
||||
$entity: 'actionAuth',
|
||||
data: {
|
||||
id: 1,
|
||||
path: 1,
|
||||
destEntity: 1,
|
||||
deActions: 1,
|
||||
},
|
||||
},
|
||||
relationAuth$sourceRelation: {
|
||||
$entity: 'relationAuth',
|
||||
data: {
|
||||
id: 1,
|
||||
sourceRelationId: 1,
|
||||
destRelationId: 1,
|
||||
destRelation: {
|
||||
id: 1,
|
||||
entity: 1,
|
||||
entityId: 1,
|
||||
name: 1,
|
||||
display: 1,
|
||||
},
|
||||
path: 1,
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
filter: {
|
||||
userId,
|
||||
entity: {
|
||||
$in: entities as string[],
|
||||
},
|
||||
},
|
||||
}, {});
|
||||
const result = userRelations.map(
|
||||
(userRelation) => omit(userRelation, 'relation')
|
||||
);
|
||||
return result as ED['userRelation']['OpSchema'][];
|
||||
}
|
||||
Loading…
Reference in New Issue