非update的更新动作即使不实际更新数据也要记oper日志
This commit is contained in:
parent
af2139e78b
commit
6a8e0d26dd
|
|
@ -1081,11 +1081,11 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
*/
|
||||
CascadeStore.prototype.doUpdateSingleRow = function (entity, operation, context, option) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var data, action, operId, filter, now, _a, modiCreate, addTimestamp_1, result_1, e_5, congruentRow_1, rest, result2, row, updateData, result3, _b, _c, updateData, result2, _d, _e, createOper, _f, ids, selection, rows, modiUpsert, upsertModis, _g, originData, originId, result_2, createOper;
|
||||
var _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
||||
var data, action, operId, filter, now, _a, modiCreate, addTimestamp_1, result_1, e_5, congruentRow_1, rest, result2, row, updateData, result3, _b, _c, updateData, result2, _d, _e, createOper, _f, ids_1, selection, rows, modiUpsert, upsertModis, _g, originData, originId, createOper, updateAttrCount, result_2;
|
||||
var _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
||||
var _this = this;
|
||||
return tslib_1.__generator(this, function (_w) {
|
||||
switch (_w.label) {
|
||||
return tslib_1.__generator(this, function (_t) {
|
||||
switch (_t.label) {
|
||||
case 0:
|
||||
data = operation.data, action = operation.action, operId = operation.id, filter = operation.filter;
|
||||
now = Date.now();
|
||||
|
|
@ -1116,7 +1116,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
};
|
||||
return [4 /*yield*/, this.cascadeUpdate('modi', modiCreate, context, option)];
|
||||
case 2:
|
||||
_w.sent();
|
||||
_t.sent();
|
||||
return [2 /*return*/, 1];
|
||||
case 3:
|
||||
addTimestamp_1 = function (data2) {
|
||||
|
|
@ -1131,15 +1131,15 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
else {
|
||||
addTimestamp_1(data);
|
||||
}
|
||||
_w.label = 4;
|
||||
_t.label = 4;
|
||||
case 4:
|
||||
_w.trys.push([4, 6, , 15]);
|
||||
_t.trys.push([4, 6, , 15]);
|
||||
return [4 /*yield*/, this.updateAbjointRow(entity, operation, context, option)];
|
||||
case 5:
|
||||
result_1 = _w.sent();
|
||||
result_1 = _t.sent();
|
||||
return [3 /*break*/, 15];
|
||||
case 6:
|
||||
e_5 = _w.sent();
|
||||
e_5 = _t.sent();
|
||||
if (!(e_5 instanceof types_1.OakCongruentRowExists)) return [3 /*break*/, 14];
|
||||
if (!option.allowExists) return [3 /*break*/, 13];
|
||||
congruentRow_1 = e_5.getData();
|
||||
|
|
@ -1152,14 +1152,14 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
data: rest,
|
||||
}), context, option)];
|
||||
case 7:
|
||||
result2 = _w.sent();
|
||||
result2 = _t.sent();
|
||||
row = data.find(function (ele) { return ele.id === congruentRow_1.id; });
|
||||
updateData = (0, lodash_1.omit)(row, ['id', '$$createAt$$']);
|
||||
_b = this.updateAbjointRow;
|
||||
_c = [entity];
|
||||
_h = {};
|
||||
return [4 /*yield*/, generateNewId()];
|
||||
case 8: return [4 /*yield*/, _b.apply(this, _c.concat([(_h.id = _w.sent(),
|
||||
case 8: return [4 /*yield*/, _b.apply(this, _c.concat([(_h.id = _t.sent(),
|
||||
_h.action = 'update',
|
||||
_h.data = updateData,
|
||||
_h.filter = {
|
||||
|
|
@ -1168,7 +1168,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
_h), context,
|
||||
option]))];
|
||||
case 9:
|
||||
result3 = _w.sent();
|
||||
result3 = _t.sent();
|
||||
return [2 /*return*/, result2 + result3];
|
||||
case 10:
|
||||
if (data.id !== congruentRow_1.id) {
|
||||
|
|
@ -1179,7 +1179,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
_e = [entity];
|
||||
_j = {};
|
||||
return [4 /*yield*/, generateNewId()];
|
||||
case 11: return [4 /*yield*/, _d.apply(this, _e.concat([(_j.id = _w.sent(),
|
||||
case 11: return [4 /*yield*/, _d.apply(this, _e.concat([(_j.id = _t.sent(),
|
||||
_j.action = 'update',
|
||||
_j.data = updateData,
|
||||
_j.filter = {
|
||||
|
|
@ -1188,7 +1188,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
_j), context,
|
||||
option]))];
|
||||
case 12:
|
||||
result2 = _w.sent();
|
||||
result2 = _t.sent();
|
||||
return [2 /*return*/, result2];
|
||||
case 13: throw e_5;
|
||||
case 14: return [3 /*break*/, 15];
|
||||
|
|
@ -1214,7 +1214,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
};
|
||||
return [4 /*yield*/, context.getCurrentUserId()];
|
||||
case 16:
|
||||
_l.operatorId = _w.sent();
|
||||
_l.operatorId = _t.sent();
|
||||
if (!(data instanceof Array)) return [3 /*break*/, 18];
|
||||
_m = {
|
||||
id: 'dummy',
|
||||
|
|
@ -1235,7 +1235,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
});
|
||||
}); }))];
|
||||
case 17:
|
||||
_f = (_m.data = _w.sent(),
|
||||
_f = (_m.data = _t.sent(),
|
||||
_m);
|
||||
return [3 /*break*/, 20];
|
||||
case 18:
|
||||
|
|
@ -1246,12 +1246,12 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
_p = {};
|
||||
return [4 /*yield*/, generateNewId()];
|
||||
case 19:
|
||||
_f = [(_o.data = (_p.id = _w.sent(),
|
||||
_f = [(_o.data = (_p.id = _t.sent(),
|
||||
_p.entity = entity,
|
||||
_p.entityId = data.id,
|
||||
_p),
|
||||
_o)];
|
||||
_w.label = 20;
|
||||
_t.label = 20;
|
||||
case 20:
|
||||
createOper = (_k.data = (_l.operEntity$oper = _f,
|
||||
_l),
|
||||
|
|
@ -1261,12 +1261,12 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
dontCreateOper: true,
|
||||
})];
|
||||
case 21:
|
||||
_w.sent();
|
||||
_w.label = 22;
|
||||
_t.sent();
|
||||
_t.label = 22;
|
||||
case 22: return [2 /*return*/, result_1];
|
||||
case 23:
|
||||
ids = (0, filter_1.getRelevantIds)(filter);
|
||||
if (!(ids.length === 0)) return [3 /*break*/, 25];
|
||||
ids_1 = (0, filter_1.getRelevantIds)(filter);
|
||||
if (!(ids_1.length === 0)) return [3 /*break*/, 25];
|
||||
selection = {
|
||||
data: {
|
||||
id: 1,
|
||||
|
|
@ -1279,9 +1279,9 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
dontCollect: true,
|
||||
})];
|
||||
case 24:
|
||||
rows = _w.sent();
|
||||
ids.push.apply(ids, tslib_1.__spreadArray([], tslib_1.__read((rows.map(function (ele) { return ele.id; }))), false));
|
||||
_w.label = 25;
|
||||
rows = _t.sent();
|
||||
ids_1.push.apply(ids_1, tslib_1.__spreadArray([], tslib_1.__read((rows.map(function (ele) { return ele.id; }))), false));
|
||||
_t.label = 25;
|
||||
case 25:
|
||||
if (!(option.modiParentEntity && !['modi', 'modiEntity'].includes(entity))) return [3 /*break*/, 31];
|
||||
modiUpsert = void 0;
|
||||
|
|
@ -1299,7 +1299,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
iState: 'active',
|
||||
filter: {
|
||||
id: {
|
||||
$in: ids,
|
||||
$in: ids_1,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -1315,7 +1315,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
count: 1,
|
||||
}, context, option)];
|
||||
case 26:
|
||||
upsertModis = _w.sent();
|
||||
upsertModis = _t.sent();
|
||||
if (upsertModis.length > 0) {
|
||||
_g = upsertModis[0], originData = _g.data, originId = _g.id;
|
||||
modiUpsert = {
|
||||
|
|
@ -1329,7 +1329,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
}
|
||||
};
|
||||
}
|
||||
_w.label = 27;
|
||||
_t.label = 27;
|
||||
case 27:
|
||||
if (!!modiUpsert) return [3 /*break*/, 29];
|
||||
_q = {
|
||||
|
|
@ -1346,7 +1346,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
iState: 'active',
|
||||
filter: {
|
||||
id: {
|
||||
$in: ids,
|
||||
$in: ids_1,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
|
@ -1354,7 +1354,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
id: 'dummy',
|
||||
action: 'create'
|
||||
};
|
||||
return [4 /*yield*/, Promise.all(ids.map(function (id) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
||||
return [4 /*yield*/, Promise.all(ids_1.map(function (id) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
||||
var _a;
|
||||
return tslib_1.__generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
|
|
@ -1369,96 +1369,118 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
});
|
||||
}); }))];
|
||||
case 28:
|
||||
modiUpsert = (_q.data = (_r.modiEntity$modi = (_s.data = _w.sent(),
|
||||
modiUpsert = (_q.data = (_r.modiEntity$modi = (_s.data = _t.sent(),
|
||||
_s),
|
||||
_r),
|
||||
_q);
|
||||
_w.label = 29;
|
||||
_t.label = 29;
|
||||
case 29: return [4 /*yield*/, this.cascadeUpdate('modi', modiUpsert, context, option)];
|
||||
case 30:
|
||||
_w.sent();
|
||||
_t.sent();
|
||||
return [2 /*return*/, 1];
|
||||
case 31:
|
||||
if (action === 'remove') {
|
||||
if (!option.dontCollect) {
|
||||
context.opRecords.push({
|
||||
a: 'r',
|
||||
e: entity,
|
||||
f: {
|
||||
id: {
|
||||
$in: ids,
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (Object.keys(data).length === 0) {
|
||||
// 优化一下,如果不更新任何属性,则不实际执行
|
||||
return [2 /*return*/, 0];
|
||||
}
|
||||
Object.assign(data, {
|
||||
$$updateAt$$: now,
|
||||
createOper = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
||||
var createOper_1;
|
||||
var _a, _b, _c;
|
||||
var _this = this;
|
||||
return tslib_1.__generator(this, function (_d) {
|
||||
switch (_d.label) {
|
||||
case 0:
|
||||
if (!(!(option === null || option === void 0 ? void 0 : option.dontCreateOper) && !['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity) && ids_1.length > 0)) return [3 /*break*/, 3];
|
||||
// 按照框架要求生成Oper和OperEntity这两个内置的对象
|
||||
(0, assert_1.default)(operId);
|
||||
_a = {
|
||||
id: 'dummy',
|
||||
action: 'create'
|
||||
};
|
||||
_b = {
|
||||
id: operId,
|
||||
action: action,
|
||||
data: data
|
||||
};
|
||||
_c = {
|
||||
id: 'dummy',
|
||||
action: 'create'
|
||||
};
|
||||
return [4 /*yield*/, Promise.all(ids_1.map(function (ele) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
||||
var _a;
|
||||
return tslib_1.__generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
_a = {};
|
||||
return [4 /*yield*/, generateNewId()];
|
||||
case 1: return [2 /*return*/, (_a.id = _b.sent(),
|
||||
_a.entity = entity,
|
||||
_a.entityId = ele,
|
||||
_a)];
|
||||
}
|
||||
});
|
||||
}); }))];
|
||||
case 1:
|
||||
createOper_1 = (_a.data = (_b.operEntity$oper = (_c.data = _d.sent(),
|
||||
_c),
|
||||
_b),
|
||||
_a);
|
||||
return [4 /*yield*/, this.cascadeUpdate('oper', createOper_1, context, {
|
||||
dontCollect: true,
|
||||
dontCreateOper: true,
|
||||
})];
|
||||
case 2:
|
||||
_d.sent();
|
||||
_d.label = 3;
|
||||
case 3: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
if (!option.dontCollect) {
|
||||
context.opRecords.push({
|
||||
a: 'u',
|
||||
e: entity,
|
||||
d: data,
|
||||
f: {
|
||||
id: {
|
||||
$in: ids,
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
return [4 /*yield*/, this.updateAbjointRow(entity, operation, context, option)];
|
||||
case 32:
|
||||
result_2 = _w.sent();
|
||||
if (!(!(option === null || option === void 0 ? void 0 : option.dontCreateOper) && !['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity) && ids.length > 0)) return [3 /*break*/, 35];
|
||||
// 按照框架要求生成Oper和OperEntity这两个内置的对象
|
||||
(0, assert_1.default)(operId);
|
||||
_t = {
|
||||
id: 'dummy',
|
||||
action: 'create'
|
||||
};
|
||||
_u = {
|
||||
id: operId,
|
||||
action: action,
|
||||
data: data
|
||||
};
|
||||
_v = {
|
||||
id: 'dummy',
|
||||
action: 'create'
|
||||
};
|
||||
return [4 /*yield*/, Promise.all(ids.map(function (ele) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
||||
var _a;
|
||||
return tslib_1.__generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
_a = {};
|
||||
return [4 /*yield*/, generateNewId()];
|
||||
case 1: return [2 /*return*/, (_a.id = _b.sent(),
|
||||
_a.entity = entity,
|
||||
_a.entityId = ele,
|
||||
_a)];
|
||||
}); };
|
||||
if (!(action === 'remove')) return [3 /*break*/, 32];
|
||||
if (!option.dontCollect) {
|
||||
context.opRecords.push({
|
||||
a: 'r',
|
||||
e: entity,
|
||||
f: {
|
||||
id: {
|
||||
$in: ids_1,
|
||||
}
|
||||
});
|
||||
}); }))];
|
||||
},
|
||||
});
|
||||
}
|
||||
return [3 /*break*/, 36];
|
||||
case 32:
|
||||
updateAttrCount = Object.keys(data).length;
|
||||
if (!(updateAttrCount > 0)) return [3 /*break*/, 33];
|
||||
// 优化一下,如果不更新任何属性,则不实际执行
|
||||
Object.assign(data, {
|
||||
$$updateAt$$: now,
|
||||
});
|
||||
if (!option.dontCollect) {
|
||||
context.opRecords.push({
|
||||
a: 'u',
|
||||
e: entity,
|
||||
d: data,
|
||||
f: {
|
||||
id: {
|
||||
$in: ids_1,
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
return [3 /*break*/, 36];
|
||||
case 33:
|
||||
createOper = (_t.data = (_u.operEntity$oper = (_v.data = _w.sent(),
|
||||
_v),
|
||||
_u),
|
||||
_t);
|
||||
return [4 /*yield*/, this.cascadeUpdate('oper', createOper, context, {
|
||||
dontCollect: true,
|
||||
dontCreateOper: true,
|
||||
})];
|
||||
if (!(action !== 'update')) return [3 /*break*/, 35];
|
||||
// 如果不是update动作而是用户自定义的动作,这里还是要记录oper
|
||||
return [4 /*yield*/, createOper()];
|
||||
case 34:
|
||||
_w.sent();
|
||||
_w.label = 35;
|
||||
case 35: return [2 /*return*/, result_2];
|
||||
// 如果不是update动作而是用户自定义的动作,这里还是要记录oper
|
||||
_t.sent();
|
||||
return [2 /*return*/, 0];
|
||||
case 35: return [2 /*return*/, 0];
|
||||
case 36: return [4 /*yield*/, this.updateAbjointRow(entity, operation, context, option)];
|
||||
case 37:
|
||||
result_2 = _t.sent();
|
||||
return [4 /*yield*/, createOper()];
|
||||
case 38:
|
||||
_t.sent();
|
||||
return [2 /*return*/, result_2];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1269,6 +1269,38 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict, Cxt e
|
|||
return 1;
|
||||
}
|
||||
else {
|
||||
const createOper = async () => {
|
||||
if (!option?.dontCreateOper && !['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity as string) && ids.length > 0) {
|
||||
// 按照框架要求生成Oper和OperEntity这两个内置的对象
|
||||
assert(operId);
|
||||
const createOper: CreateOperOperation = {
|
||||
id: 'dummy',
|
||||
action: 'create',
|
||||
data: {
|
||||
id: operId,
|
||||
action,
|
||||
data,
|
||||
operEntity$oper: {
|
||||
id: 'dummy',
|
||||
action: 'create',
|
||||
data: await Promise.all(
|
||||
ids.map(
|
||||
async (ele) => ({
|
||||
id: await generateNewId(),
|
||||
entity: entity as string,
|
||||
entityId: ele,
|
||||
})
|
||||
)
|
||||
)
|
||||
},
|
||||
},
|
||||
}
|
||||
await this.cascadeUpdate('oper', createOper, context, {
|
||||
dontCollect: true,
|
||||
dontCreateOper: true,
|
||||
});
|
||||
}
|
||||
};
|
||||
if (action === 'remove') {
|
||||
if (!option.dontCollect) {
|
||||
context.opRecords.push({
|
||||
|
|
@ -1283,58 +1315,37 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict, Cxt e
|
|||
}
|
||||
}
|
||||
else {
|
||||
if (Object.keys(data).length === 0) {
|
||||
const updateAttrCount = Object.keys(data).length;
|
||||
if (updateAttrCount > 0) {
|
||||
// 优化一下,如果不更新任何属性,则不实际执行
|
||||
Object.assign(data, {
|
||||
$$updateAt$$: now,
|
||||
});
|
||||
if (!option.dontCollect) {
|
||||
context.opRecords.push({
|
||||
a: 'u',
|
||||
e: entity,
|
||||
d: data as ED[T]['Update']['data'],
|
||||
f: {
|
||||
id: {
|
||||
$in: ids,
|
||||
}
|
||||
} as DeduceFilter<ED[T]['Schema']>,
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (action !== 'update') {
|
||||
// 如果不是update动作而是用户自定义的动作,这里还是要记录oper
|
||||
await createOper();
|
||||
return 0;
|
||||
}
|
||||
Object.assign(data, {
|
||||
$$updateAt$$: now,
|
||||
});
|
||||
if (!option.dontCollect) {
|
||||
context.opRecords.push({
|
||||
a: 'u',
|
||||
e: entity,
|
||||
d: data as ED[T]['Update']['data'],
|
||||
f: {
|
||||
id: {
|
||||
$in: ids,
|
||||
}
|
||||
} as DeduceFilter<ED[T]['Schema']>,
|
||||
});
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
const result = await this.updateAbjointRow(entity, operation, context, option);
|
||||
if (!option?.dontCreateOper && !['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity as string) && ids.length > 0) {
|
||||
// 按照框架要求生成Oper和OperEntity这两个内置的对象
|
||||
assert(operId);
|
||||
const createOper: CreateOperOperation = {
|
||||
id: 'dummy',
|
||||
action: 'create',
|
||||
data: {
|
||||
id: operId,
|
||||
action,
|
||||
data,
|
||||
operEntity$oper: {
|
||||
id: 'dummy',
|
||||
action: 'create',
|
||||
data: await Promise.all(
|
||||
ids.map(
|
||||
async (ele) => ({
|
||||
id: await generateNewId(),
|
||||
entity: entity as string,
|
||||
entityId: ele,
|
||||
})
|
||||
)
|
||||
)
|
||||
},
|
||||
},
|
||||
}
|
||||
await this.cascadeUpdate('oper', createOper, context, {
|
||||
dontCollect: true,
|
||||
dontCreateOper: true,
|
||||
});
|
||||
}
|
||||
await createOper();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue