在寻找查询条件的锚点时,所有可能的锚点都不能过滤

This commit is contained in:
Xu Chang 2023-07-17 16:44:27 +08:00
parent 70dbf3b136
commit fed8244396
2 changed files with 16 additions and 64 deletions

View File

@ -36,7 +36,6 @@ var RelationAuth = /** @class */ (function () {
var findHighestAnchors = function (entity, filter, path, excludePaths) { var findHighestAnchors = function (entity, filter, path, excludePaths) {
var _a; var _a;
var anchors = []; var anchors = [];
var anchorsOnMe = [];
var _loop_1 = function (attr) { var _loop_1 = function (attr) {
if (attr === '$and') { if (attr === '$and') {
filter[attr].forEach(function (ele) { return anchors.push.apply(anchors, tslib_1.__spreadArray([], tslib_1.__read(findHighestAnchors(entity, ele, path, excludePaths)), false)); }); filter[attr].forEach(function (ele) { return anchors.push.apply(anchors, tslib_1.__spreadArray([], tslib_1.__read(findHighestAnchors(entity, ele, path, excludePaths)), false)); });
@ -68,24 +67,13 @@ var RelationAuth = /** @class */ (function () {
if (attr === 'entity' && (pathGroup[filter.entity] || filter.entity === 'user')) { if (attr === 'entity' && (pathGroup[filter.entity] || filter.entity === 'user')) {
var nextPath = path ? "".concat(path, ".").concat(filter.entity) : filter.entity; var nextPath = path ? "".concat(path, ".").concat(filter.entity) : filter.entity;
if (filter.entityId) { if (filter.entityId) {
if (filter.entity === 'user') { anchors.push({
anchors.push({ entity: filter.entity,
entity: filter.entity, filter: {
filter: { id: filter.entityId,
id: filter.entityId, },
}, relativePath: nextPath,
relativePath: nextPath, });
});
}
else {
anchorsOnMe.push({
entity: filter.entity,
filter: {
id: filter.entityId,
},
relativePath: nextPath,
});
}
} }
var attributes = _this.schema[entity].attributes; var attributes = _this.schema[entity].attributes;
var ref = attributes.entity.ref; var ref = attributes.entity.ref;
@ -100,16 +88,7 @@ var RelationAuth = /** @class */ (function () {
else if (((_a = _this.schema[entity].attributes[attr]) === null || _a === void 0 ? void 0 : _a.type) === 'ref') { else if (((_a = _this.schema[entity].attributes[attr]) === null || _a === void 0 ? void 0 : _a.type) === 'ref') {
var ref = _this.schema[entity].attributes[attr].ref; var ref = _this.schema[entity].attributes[attr].ref;
(0, assert_1.default)(typeof ref === 'string'); (0, assert_1.default)(typeof ref === 'string');
if (pathGroup[ref]) { if (pathGroup[ref] || ref === 'user') {
anchorsOnMe.push({
entity: ref,
filter: {
id: filter[attr],
},
relativePath: path ? "".concat(path, ".").concat(attr.slice(0, attr.length - 2)) : attr.slice(0, attr.length - 2)
});
}
else if (ref === 'user') {
anchors.push({ anchors.push({
entity: ref, entity: ref,
filter: { filter: {
@ -127,9 +106,6 @@ var RelationAuth = /** @class */ (function () {
if (anchors.length > 0) { if (anchors.length > 0) {
return anchors; return anchors;
} }
if (anchorsOnMe.length > 0) {
return anchorsOnMe;
}
if (filter.id) { if (filter.id) {
// 直接以id作为查询目标 // 直接以id作为查询目标
return [{ return [{

View File

@ -72,7 +72,6 @@ export class RelationAuth<ED extends EntityDict & BaseEntityDict>{
const findHighestAnchors = (entity: keyof ED, filter: NonNullable<ED[keyof ED]['Selection']['filter']>, path: string, excludePaths: string[]): Anchor[] => { const findHighestAnchors = (entity: keyof ED, filter: NonNullable<ED[keyof ED]['Selection']['filter']>, path: string, excludePaths: string[]): Anchor[] => {
const anchors = [] as Anchor[]; const anchors = [] as Anchor[];
const anchorsOnMe = [] as Anchor[];
for (const attr in filter) { for (const attr in filter) {
if (attr === '$and') { if (attr === '$and') {
filter[attr].forEach( filter[attr].forEach(
@ -110,24 +109,13 @@ export class RelationAuth<ED extends EntityDict & BaseEntityDict>{
if (attr === 'entity' && (pathGroup[filter.entity] || filter.entity === 'user')) { if (attr === 'entity' && (pathGroup[filter.entity] || filter.entity === 'user')) {
const nextPath = path ? `${path}.${filter.entity as string}` : filter.entity; const nextPath = path ? `${path}.${filter.entity as string}` : filter.entity;
if (filter.entityId) { if (filter.entityId) {
if (filter.entity === 'user') { anchors.push({
anchors.push({ entity: filter.entity,
entity: filter.entity, filter: {
filter: { id: filter.entityId,
id: filter.entityId, },
}, relativePath: nextPath,
relativePath: nextPath, });
});
}
else {
anchorsOnMe.push({
entity: filter.entity,
filter: {
id: filter.entityId,
},
relativePath: nextPath,
});
}
} }
const { attributes } = this.schema[entity]; const { attributes } = this.schema[entity];
const { ref } = attributes.entity; const { ref } = attributes.entity;
@ -144,16 +132,7 @@ export class RelationAuth<ED extends EntityDict & BaseEntityDict>{
else if (this.schema[entity].attributes[attr as any]?.type === 'ref') { else if (this.schema[entity].attributes[attr as any]?.type === 'ref') {
const { ref } = this.schema[entity].attributes[attr as any]; const { ref } = this.schema[entity].attributes[attr as any];
assert(typeof ref === 'string'); assert(typeof ref === 'string');
if (pathGroup[ref]) { if (pathGroup[ref] || ref === 'user') {
anchorsOnMe.push({
entity: ref,
filter: {
id: filter[attr],
},
relativePath: path ? `${path}.${attr.slice(0, attr.length - 2)}` : attr.slice(0, attr.length - 2)
});
}
else if (ref === 'user') {
anchors.push({ anchors.push({
entity: ref, entity: ref,
filter: { filter: {
@ -168,9 +147,6 @@ export class RelationAuth<ED extends EntityDict & BaseEntityDict>{
if (anchors.length > 0) { if (anchors.length > 0) {
return anchors; return anchors;
} }
if (anchorsOnMe.length > 0) {
return anchorsOnMe;
}
if (filter.id) { if (filter.id) {
// 直接以id作为查询目标 // 直接以id作为查询目标
return [{ return [{