cascadeUpsert中的几个小问题
This commit is contained in:
parent
3839aa82a8
commit
f9b664460d
|
|
@ -100,20 +100,27 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
}
|
||||
});
|
||||
};
|
||||
var entityIds = (0, lodash_1.uniq)(result.filter(function (ele) { return ele.entity === attr; }).map(function (ele) { return ele.entityId; }));
|
||||
var subRows = cascadeSelectFn.call(_this, attr, {
|
||||
data: projection2[attr],
|
||||
filter: {
|
||||
id: {
|
||||
$in: entityIds
|
||||
var entityIds = (0, lodash_1.uniq)(result.filter(function (ele) { return ele.entity === attr; }).map(function (ele) {
|
||||
(0, assert_1.default)(ele.entityId !== null);
|
||||
return ele.entityId;
|
||||
}));
|
||||
if (entityIds.length > 0) {
|
||||
var subRows = cascadeSelectFn.call(_this, attr, {
|
||||
data: projection2[attr],
|
||||
filter: {
|
||||
id: {
|
||||
$in: entityIds
|
||||
},
|
||||
},
|
||||
},
|
||||
}, context, option);
|
||||
if (subRows instanceof Promise) {
|
||||
return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
|
||||
}, context, option);
|
||||
if (subRows instanceof Promise) {
|
||||
return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
|
||||
}
|
||||
else {
|
||||
dealWithSubRows(subRows);
|
||||
}
|
||||
}
|
||||
else {
|
||||
dealWithSubRows(subRows);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -191,18 +198,20 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
});
|
||||
};
|
||||
var ids = (0, lodash_1.uniq)(result.filter(function (ele) { return !!(ele["".concat(attr, "Id")]); }).map(function (ele) { return ele["".concat(attr, "Id")]; }));
|
||||
var subRows = cascadeSelectFn.call(_this, relation, {
|
||||
data: projection2[attr],
|
||||
filter: {
|
||||
id: {
|
||||
$in: ids
|
||||
if (ids.length > 0) {
|
||||
var subRows = cascadeSelectFn.call(_this, relation, {
|
||||
data: projection2[attr],
|
||||
filter: {
|
||||
id: {
|
||||
$in: ids
|
||||
},
|
||||
},
|
||||
},
|
||||
}, context, option);
|
||||
if (subRows instanceof Promise) {
|
||||
return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
|
||||
}, context, option);
|
||||
if (subRows instanceof Promise) {
|
||||
return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
|
||||
}
|
||||
dealWithSubRows(subRows);
|
||||
}
|
||||
dealWithSubRows(subRows);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -261,21 +270,23 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
_a));
|
||||
});
|
||||
};
|
||||
var subRows = cascadeSelectFn.call(_this, entity2_1, {
|
||||
data: subProjection_1,
|
||||
filter: (0, filter_1.combineFilters)([(_a = {},
|
||||
_a[foreignKey_1] = {
|
||||
$in: ids,
|
||||
},
|
||||
_a), subFilter_1]),
|
||||
sorter: subSorter_1,
|
||||
indexFrom: indexFrom_1,
|
||||
count: count_1
|
||||
}, context, option);
|
||||
if (subRows instanceof Promise) {
|
||||
return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
|
||||
if (ids.length > 0) {
|
||||
var subRows = cascadeSelectFn.call(_this, entity2_1, {
|
||||
data: subProjection_1,
|
||||
filter: (0, filter_1.combineFilters)([(_a = {},
|
||||
_a[foreignKey_1] = {
|
||||
$in: ids,
|
||||
},
|
||||
_a), subFilter_1]),
|
||||
sorter: subSorter_1,
|
||||
indexFrom: indexFrom_1,
|
||||
count: count_1
|
||||
}, context, option);
|
||||
if (subRows instanceof Promise) {
|
||||
return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
|
||||
}
|
||||
dealWithSubRows(subRows);
|
||||
}
|
||||
dealWithSubRows(subRows);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -329,22 +340,24 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
_a));
|
||||
});
|
||||
};
|
||||
var subRows = cascadeSelectFn.call(_this, entity2_1, {
|
||||
data: subProjection_1,
|
||||
filter: (0, filter_1.combineFilters)([{
|
||||
entity: entity,
|
||||
entityId: {
|
||||
$in: ids,
|
||||
}
|
||||
}, subFilter_1]),
|
||||
sorter: subSorter_1,
|
||||
indexFrom: indexFrom_1,
|
||||
count: count_1
|
||||
}, context, option);
|
||||
if (subRows instanceof Promise) {
|
||||
return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
|
||||
if (ids.length > 0) {
|
||||
var subRows = cascadeSelectFn.call(_this, entity2_1, {
|
||||
data: subProjection_1,
|
||||
filter: (0, filter_1.combineFilters)([{
|
||||
entity: entity,
|
||||
entityId: {
|
||||
$in: ids,
|
||||
}
|
||||
}, subFilter_1]),
|
||||
sorter: subSorter_1,
|
||||
indexFrom: indexFrom_1,
|
||||
count: count_1
|
||||
}, context, option);
|
||||
if (subRows instanceof Promise) {
|
||||
return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
|
||||
}
|
||||
dealWithSubRows(subRows);
|
||||
}
|
||||
dealWithSubRows(subRows);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -708,11 +721,11 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
*/
|
||||
CascadeStore.prototype.doUpdateSingleRowAsync = function (entity, operation, context, option) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var data, action, operId, filter, now, _a, modiCreate, result_1, createInner, multipleCreate, data_1, data_1_1, d, createSingleOper, e_2_1, operatorId, createOper, _b, ids_1, selection, rows, modiUpsert, upsertModis, _c, originData, originId, createOper, updateAttrCount, result;
|
||||
var e_2, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
||||
var data, action, operId, filter, now, _a, modiCreate, result_1, createInner, multipleCreate, data_1, data_1_1, d, createSingleOper, e_2_1, operatorId, createOper, _b, ids_1, selection, rows, modiUpsert, upsertModis, _c, originData, originId, _d, createOper, updateAttrCount, result;
|
||||
var e_2, _e, _f, _g, _h, _j, _k, _l;
|
||||
var _this = this;
|
||||
return tslib_1.__generator(this, function (_o) {
|
||||
switch (_o.label) {
|
||||
return tslib_1.__generator(this, function (_m) {
|
||||
switch (_m.label) {
|
||||
case 0:
|
||||
data = operation.data, action = operation.action, operId = operation.id, filter = operation.filter;
|
||||
now = Date.now();
|
||||
|
|
@ -746,7 +759,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
};
|
||||
return [4 /*yield*/, this.cascadeUpdateAsync('modi', modiCreate, context, option)];
|
||||
case 2:
|
||||
_o.sent();
|
||||
_m.sent();
|
||||
return [2 /*return*/, 1];
|
||||
case 3:
|
||||
result_1 = 0;
|
||||
|
|
@ -836,12 +849,12 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
if (!multipleCreate) return [3 /*break*/, 5];
|
||||
return [4 /*yield*/, createInner(operation)];
|
||||
case 4:
|
||||
_o.sent();
|
||||
_m.sent();
|
||||
return [3 /*break*/, 12];
|
||||
case 5:
|
||||
_o.trys.push([5, 10, 11, 12]);
|
||||
_m.trys.push([5, 10, 11, 12]);
|
||||
data_1 = tslib_1.__values(data), data_1_1 = data_1.next();
|
||||
_o.label = 6;
|
||||
_m.label = 6;
|
||||
case 6:
|
||||
if (!!data_1_1.done) return [3 /*break*/, 9];
|
||||
d = data_1_1.value;
|
||||
|
|
@ -852,27 +865,27 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
};
|
||||
return [4 /*yield*/, createInner(createSingleOper)];
|
||||
case 7:
|
||||
_o.sent();
|
||||
_o.label = 8;
|
||||
_m.sent();
|
||||
_m.label = 8;
|
||||
case 8:
|
||||
data_1_1 = data_1.next();
|
||||
return [3 /*break*/, 6];
|
||||
case 9: return [3 /*break*/, 12];
|
||||
case 10:
|
||||
e_2_1 = _o.sent();
|
||||
e_2_1 = _m.sent();
|
||||
e_2 = { error: e_2_1 };
|
||||
return [3 /*break*/, 12];
|
||||
case 11:
|
||||
try {
|
||||
if (data_1_1 && !data_1_1.done && (_d = data_1.return)) _d.call(data_1);
|
||||
if (data_1_1 && !data_1_1.done && (_e = data_1.return)) _e.call(data_1);
|
||||
}
|
||||
finally { if (e_2) throw e_2.error; }
|
||||
return [7 /*endfinally*/];
|
||||
case 12: return [3 /*break*/, 15];
|
||||
case 13: return [4 /*yield*/, createInner(operation)];
|
||||
case 14:
|
||||
_o.sent();
|
||||
_o.label = 15;
|
||||
_m.sent();
|
||||
_m.label = 15;
|
||||
case 15:
|
||||
if (!option.dontCollect) {
|
||||
context.opRecords.push({
|
||||
|
|
@ -886,20 +899,20 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
(0, assert_1.default)(operId);
|
||||
return [4 /*yield*/, context.getCurrentUserId(true)];
|
||||
case 16:
|
||||
operatorId = _o.sent();
|
||||
operatorId = _m.sent();
|
||||
if (!operatorId) return [3 /*break*/, 22];
|
||||
_e = {
|
||||
_f = {
|
||||
id: 'dummy',
|
||||
action: 'create'
|
||||
};
|
||||
_f = {
|
||||
_g = {
|
||||
id: operId,
|
||||
action: action,
|
||||
data: data,
|
||||
operatorId: operatorId
|
||||
};
|
||||
if (!(data instanceof Array)) return [3 /*break*/, 18];
|
||||
_g = {
|
||||
_h = {
|
||||
id: 'dummy',
|
||||
action: 'create'
|
||||
};
|
||||
|
|
@ -918,34 +931,34 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
});
|
||||
}); }))];
|
||||
case 17:
|
||||
_b = (_g.data = _o.sent(),
|
||||
_g);
|
||||
_b = (_h.data = _m.sent(),
|
||||
_h);
|
||||
return [3 /*break*/, 20];
|
||||
case 18:
|
||||
_h = {
|
||||
_j = {
|
||||
id: 'dummy',
|
||||
action: 'create'
|
||||
};
|
||||
_j = {};
|
||||
_k = {};
|
||||
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
||||
case 19:
|
||||
_b = [(_h.data = (_j.id = _o.sent(),
|
||||
_j.entity = entity,
|
||||
_j.entityId = data.id,
|
||||
_j),
|
||||
_h)];
|
||||
_o.label = 20;
|
||||
_b = [(_j.data = (_k.id = _m.sent(),
|
||||
_k.entity = entity,
|
||||
_k.entityId = data.id,
|
||||
_k),
|
||||
_j)];
|
||||
_m.label = 20;
|
||||
case 20:
|
||||
createOper = (_e.data = (_f.operEntity$oper = _b,
|
||||
_f),
|
||||
_e);
|
||||
createOper = (_f.data = (_g.operEntity$oper = _b,
|
||||
_g),
|
||||
_f);
|
||||
return [4 /*yield*/, this.cascadeUpdateAsync('oper', createOper, context, {
|
||||
dontCollect: true,
|
||||
dontCreateOper: true,
|
||||
})];
|
||||
case 21:
|
||||
_o.sent();
|
||||
_o.label = 22;
|
||||
_m.sent();
|
||||
_m.label = 22;
|
||||
case 22: return [2 /*return*/, result_1];
|
||||
case 23:
|
||||
ids_1 = (0, filter_2.getRelevantIds)(filter);
|
||||
|
|
@ -962,9 +975,9 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
dontCollect: true,
|
||||
})];
|
||||
case 24:
|
||||
rows = _o.sent();
|
||||
rows = _m.sent();
|
||||
ids_1.push.apply(ids_1, tslib_1.__spreadArray([], tslib_1.__read((rows.map(function (ele) { return ele.id; }))), false));
|
||||
_o.label = 25;
|
||||
_m.label = 25;
|
||||
case 25:
|
||||
if (data) {
|
||||
this.preProcessDataUpdated(data);
|
||||
|
|
@ -1003,7 +1016,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
count: 1,
|
||||
}, context, option)];
|
||||
case 26:
|
||||
upsertModis = _o.sent();
|
||||
upsertModis = _m.sent();
|
||||
if (upsertModis.length > 0) {
|
||||
_c = upsertModis[0], originData = _c.data, originId = _c.id;
|
||||
modiUpsert = {
|
||||
|
|
@ -1017,24 +1030,26 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
}
|
||||
};
|
||||
}
|
||||
_o.label = 27;
|
||||
_m.label = 27;
|
||||
case 27:
|
||||
if (!!modiUpsert) return [3 /*break*/, 29];
|
||||
_k = {
|
||||
modiUpsert = {
|
||||
id: 'dummy',
|
||||
action: 'create'
|
||||
action: 'create',
|
||||
data: {
|
||||
id: operId,
|
||||
targetEntity: entity,
|
||||
entity: option.modiParentEntity,
|
||||
entityId: option.modiParentId,
|
||||
action: action,
|
||||
data: data,
|
||||
iState: 'active',
|
||||
filter: filter,
|
||||
},
|
||||
};
|
||||
if (!(ids_1.length > 0)) return [3 /*break*/, 29];
|
||||
_d = modiUpsert.data;
|
||||
_l = {
|
||||
id: operId,
|
||||
targetEntity: entity,
|
||||
entity: option.modiParentEntity,
|
||||
entityId: option.modiParentId,
|
||||
action: action,
|
||||
data: data,
|
||||
iState: 'active',
|
||||
filter: filter
|
||||
};
|
||||
_m = {
|
||||
id: 'dummy',
|
||||
action: 'create'
|
||||
};
|
||||
|
|
@ -1053,14 +1068,12 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
});
|
||||
}); }))];
|
||||
case 28:
|
||||
modiUpsert = (_k.data = (_l.modiEntity$modi = (_m.data = _o.sent(),
|
||||
_m),
|
||||
_l),
|
||||
_k);
|
||||
_o.label = 29;
|
||||
_d.modiEntity$modi = (_l.data = _m.sent(),
|
||||
_l);
|
||||
_m.label = 29;
|
||||
case 29: return [4 /*yield*/, this.cascadeUpdateAsync('modi', modiUpsert, context, option)];
|
||||
case 30:
|
||||
_o.sent();
|
||||
_m.sent();
|
||||
return [2 /*return*/, 1];
|
||||
case 31:
|
||||
createOper = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
||||
|
|
@ -1155,15 +1168,15 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
return [4 /*yield*/, createOper()];
|
||||
case 34:
|
||||
// 如果不是update动作而是用户自定义的动作,这里还是要记录oper
|
||||
_o.sent();
|
||||
_m.sent();
|
||||
return [2 /*return*/, 0];
|
||||
case 35: return [2 /*return*/, 0];
|
||||
case 36: return [4 /*yield*/, this.updateAbjointRowAsync(entity, operation, context, option)];
|
||||
case 37:
|
||||
result = _o.sent();
|
||||
result = _m.sent();
|
||||
return [4 /*yield*/, createOper()];
|
||||
case 38:
|
||||
_o.sent();
|
||||
_m.sent();
|
||||
return [2 /*return*/, result];
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -169,24 +169,32 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
const entityIds = uniq(result.filter(
|
||||
ele => ele.entity === attr
|
||||
).map(
|
||||
ele => ele.entityId
|
||||
ele => {
|
||||
assert(ele.entityId !== null);
|
||||
return ele.entityId;
|
||||
}
|
||||
) as string[]);
|
||||
|
||||
const subRows = cascadeSelectFn.call(this, attr as any, {
|
||||
data: projection2[attr],
|
||||
filter: {
|
||||
id: {
|
||||
$in: entityIds
|
||||
},
|
||||
} as any,
|
||||
}, context, option);
|
||||
if (subRows instanceof Promise) {
|
||||
return subRows.then(
|
||||
(subRowss) => dealWithSubRows(subRowss)
|
||||
)
|
||||
if (entityIds.length > 0) {
|
||||
const subRows = cascadeSelectFn.call(this, attr as any, {
|
||||
data: projection2[attr],
|
||||
filter: {
|
||||
id: {
|
||||
$in: entityIds
|
||||
},
|
||||
} as any,
|
||||
}, context, option);
|
||||
if (subRows instanceof Promise) {
|
||||
return subRows.then(
|
||||
(subRowss) => dealWithSubRows(subRowss)
|
||||
)
|
||||
}
|
||||
else {
|
||||
dealWithSubRows(subRows as any);
|
||||
}
|
||||
}
|
||||
else {
|
||||
dealWithSubRows(subRows as any);
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
@ -286,20 +294,22 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
ele => ele[`${attr}Id`]
|
||||
) as string[]);
|
||||
|
||||
const subRows = cascadeSelectFn.call(this, relation, {
|
||||
data: projection2[attr],
|
||||
filter: {
|
||||
id: {
|
||||
$in: ids
|
||||
},
|
||||
} as any,
|
||||
}, context, option);
|
||||
if (subRows instanceof Promise) {
|
||||
return subRows.then(
|
||||
(subRowss) => dealWithSubRows(subRowss)
|
||||
);
|
||||
if (ids.length > 0) {
|
||||
const subRows = cascadeSelectFn.call(this, relation, {
|
||||
data: projection2[attr],
|
||||
filter: {
|
||||
id: {
|
||||
$in: ids
|
||||
},
|
||||
} as any,
|
||||
}, context, option);
|
||||
if (subRows instanceof Promise) {
|
||||
return subRows.then(
|
||||
(subRowss) => dealWithSubRows(subRowss)
|
||||
);
|
||||
}
|
||||
dealWithSubRows(subRows as any);
|
||||
}
|
||||
dealWithSubRows(subRows as any);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -370,23 +380,25 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
);
|
||||
};
|
||||
|
||||
const subRows = cascadeSelectFn.call(this, entity2, {
|
||||
data: subProjection,
|
||||
filter: combineFilters([{
|
||||
[foreignKey]: {
|
||||
$in: ids,
|
||||
}
|
||||
}, subFilter]),
|
||||
sorter: subSorter,
|
||||
indexFrom,
|
||||
count
|
||||
}, context, option);
|
||||
if (subRows instanceof Promise) {
|
||||
return subRows.then(
|
||||
(subRowss) => dealWithSubRows(subRowss)
|
||||
);
|
||||
if (ids.length > 0) {
|
||||
const subRows = cascadeSelectFn.call(this, entity2, {
|
||||
data: subProjection,
|
||||
filter: combineFilters([{
|
||||
[foreignKey]: {
|
||||
$in: ids,
|
||||
}
|
||||
}, subFilter]),
|
||||
sorter: subSorter,
|
||||
indexFrom,
|
||||
count
|
||||
}, context, option);
|
||||
if (subRows instanceof Promise) {
|
||||
return subRows.then(
|
||||
(subRowss) => dealWithSubRows(subRowss)
|
||||
);
|
||||
}
|
||||
dealWithSubRows(subRows as any);
|
||||
}
|
||||
dealWithSubRows(subRows as any);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -452,24 +464,26 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
);
|
||||
};
|
||||
|
||||
const subRows = cascadeSelectFn.call(this, entity2, {
|
||||
data: subProjection,
|
||||
filter: combineFilters([{
|
||||
entity,
|
||||
entityId: {
|
||||
$in: ids,
|
||||
}
|
||||
}, subFilter]),
|
||||
sorter: subSorter,
|
||||
indexFrom,
|
||||
count
|
||||
}, context, option);
|
||||
if (subRows instanceof Promise) {
|
||||
return subRows.then(
|
||||
(subRowss) => dealWithSubRows(subRowss)
|
||||
);
|
||||
if (ids.length > 0) {
|
||||
const subRows = cascadeSelectFn.call(this, entity2, {
|
||||
data: subProjection,
|
||||
filter: combineFilters([{
|
||||
entity,
|
||||
entityId: {
|
||||
$in: ids,
|
||||
}
|
||||
}, subFilter]),
|
||||
sorter: subSorter,
|
||||
indexFrom,
|
||||
count
|
||||
}, context, option);
|
||||
if (subRows instanceof Promise) {
|
||||
return subRows.then(
|
||||
(subRowss) => dealWithSubRows(subRowss)
|
||||
);
|
||||
}
|
||||
dealWithSubRows(subRows as any);
|
||||
}
|
||||
dealWithSubRows(subRows as any);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -1116,22 +1130,24 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
action,
|
||||
data,
|
||||
iState: 'active',
|
||||
filter,
|
||||
modiEntity$modi: {
|
||||
id: 'dummy',
|
||||
action: 'create',
|
||||
data: await Promise.all(
|
||||
ids.map(
|
||||
async (id) => ({
|
||||
id: await generateNewIdAsync(),
|
||||
entity: entity as string,
|
||||
entityId: id,
|
||||
})
|
||||
)
|
||||
),
|
||||
},
|
||||
filter,
|
||||
},
|
||||
};
|
||||
if (ids.length > 0){
|
||||
modiUpsert.data.modiEntity$modi = {
|
||||
id: 'dummy',
|
||||
action: 'create',
|
||||
data: await Promise.all(
|
||||
ids.map(
|
||||
async (id) => ({
|
||||
id: await generateNewIdAsync(),
|
||||
entity: entity as string,
|
||||
entityId: id,
|
||||
})
|
||||
)
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
await this.cascadeUpdateAsync('modi', modiUpsert!, context, option);
|
||||
return 1;
|
||||
|
|
|
|||
Loading…
Reference in New Issue