modi中的两个update的修正
This commit is contained in:
parent
f0a524a80f
commit
43d5590228
|
|
@ -21,19 +21,40 @@ function createOperationsFromModies(modies) {
|
||||||
exports.createOperationsFromModies = createOperationsFromModies;
|
exports.createOperationsFromModies = createOperationsFromModies;
|
||||||
function applyModis(filter, context, option) {
|
function applyModis(filter, context, option) {
|
||||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||||
var _a, _b, _c;
|
var modis, _a, _b, _c;
|
||||||
var _d;
|
var _d;
|
||||||
return tslib_1.__generator(this, function (_e) {
|
return tslib_1.__generator(this, function (_e) {
|
||||||
switch (_e.label) {
|
switch (_e.label) {
|
||||||
case 0:
|
case 0: return [4 /*yield*/, context.rowStore.select('modi', {
|
||||||
|
data: {
|
||||||
|
id: 1,
|
||||||
|
},
|
||||||
|
filter: filter,
|
||||||
|
sorter: [
|
||||||
|
{
|
||||||
|
$attr: {
|
||||||
|
$$createAt$$: 1,
|
||||||
|
},
|
||||||
|
$direction: 'asc',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, context, Object.assign({}, option, {
|
||||||
|
blockTrigger: false,
|
||||||
|
}))];
|
||||||
|
case 1:
|
||||||
|
modis = (_e.sent()).result;
|
||||||
_b = (_a = context.rowStore).operate;
|
_b = (_a = context.rowStore).operate;
|
||||||
_c = ['modi'];
|
_c = ['modi'];
|
||||||
_d = {};
|
_d = {};
|
||||||
return [4 /*yield*/, generateNewId()];
|
return [4 /*yield*/, generateNewId()];
|
||||||
case 1: return [2 /*return*/, _b.apply(_a, _c.concat([(_d.id = _e.sent(),
|
case 2: return [2 /*return*/, _b.apply(_a, _c.concat([(_d.id = _e.sent(),
|
||||||
_d.action = 'apply',
|
_d.action = 'apply',
|
||||||
_d.data = {},
|
_d.data = {},
|
||||||
_d.filter = filter,
|
_d.filter = {
|
||||||
|
id: {
|
||||||
|
$in: modis.map(function (ele) { return ele.id; }),
|
||||||
|
}
|
||||||
|
},
|
||||||
_d.sorter = [
|
_d.sorter = [
|
||||||
{
|
{
|
||||||
$attr: {
|
$attr: {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ var triggers = [
|
||||||
fn: function (_a, context, option) {
|
fn: function (_a, context, option) {
|
||||||
var operation = _a.operation;
|
var operation = _a.operation;
|
||||||
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
||||||
var filter, modies, modies_1, modies_1_1, modi, targetEntity, id, action, data, filter_1, e_1_1;
|
var filter, modies, modies_1, modies_1_1, modi, targetEntity, id, action, data, filter_1, targets, e_1_1;
|
||||||
var e_1, _b;
|
var e_1, _b;
|
||||||
return tslib_1.__generator(this, function (_c) {
|
return tslib_1.__generator(this, function (_c) {
|
||||||
switch (_c.label) {
|
switch (_c.label) {
|
||||||
|
|
@ -30,39 +30,49 @@ var triggers = [
|
||||||
modies = (_c.sent()).result;
|
modies = (_c.sent()).result;
|
||||||
_c.label = 2;
|
_c.label = 2;
|
||||||
case 2:
|
case 2:
|
||||||
_c.trys.push([2, 7, 8, 9]);
|
_c.trys.push([2, 8, 9, 10]);
|
||||||
modies_1 = tslib_1.__values(modies), modies_1_1 = modies_1.next();
|
modies_1 = tslib_1.__values(modies), modies_1_1 = modies_1.next();
|
||||||
_c.label = 3;
|
_c.label = 3;
|
||||||
case 3:
|
case 3:
|
||||||
if (!!modies_1_1.done) return [3 /*break*/, 6];
|
if (!!modies_1_1.done) return [3 /*break*/, 7];
|
||||||
modi = modies_1_1.value;
|
modi = modies_1_1.value;
|
||||||
targetEntity = modi.targetEntity, id = modi.id, action = modi.action, data = modi.data, filter_1 = modi.filter;
|
targetEntity = modi.targetEntity, id = modi.id, action = modi.action, data = modi.data, filter_1 = modi.filter;
|
||||||
return [4 /*yield*/, context.rowStore.operate(targetEntity, {
|
return [4 /*yield*/, context.rowStore.select(targetEntity, {
|
||||||
id: id,
|
data: {
|
||||||
action: action,
|
id: 1,
|
||||||
data: data,
|
},
|
||||||
filter: filter_1,
|
filter: filter_1,
|
||||||
}, context, Object.assign({}, option, {
|
}, context, Object.assign({}, option, {
|
||||||
blockTrigger: true,
|
blockTrigger: true,
|
||||||
}))];
|
}))];
|
||||||
case 4:
|
case 4:
|
||||||
_c.sent();
|
targets = _c.sent();
|
||||||
_c.label = 5;
|
return [4 /*yield*/, context.rowStore.operate(targetEntity, {
|
||||||
|
id: id,
|
||||||
|
action: action,
|
||||||
|
data: data,
|
||||||
|
filter: targets.result.map(function (ele) { return ele.id; }),
|
||||||
|
}, context, Object.assign({}, option, {
|
||||||
|
blockTrigger: true,
|
||||||
|
}))];
|
||||||
case 5:
|
case 5:
|
||||||
|
_c.sent();
|
||||||
|
_c.label = 6;
|
||||||
|
case 6:
|
||||||
modies_1_1 = modies_1.next();
|
modies_1_1 = modies_1.next();
|
||||||
return [3 /*break*/, 3];
|
return [3 /*break*/, 3];
|
||||||
case 6: return [3 /*break*/, 9];
|
case 7: return [3 /*break*/, 10];
|
||||||
case 7:
|
case 8:
|
||||||
e_1_1 = _c.sent();
|
e_1_1 = _c.sent();
|
||||||
e_1 = { error: e_1_1 };
|
e_1 = { error: e_1_1 };
|
||||||
return [3 /*break*/, 9];
|
return [3 /*break*/, 10];
|
||||||
case 8:
|
case 9:
|
||||||
try {
|
try {
|
||||||
if (modies_1_1 && !modies_1_1.done && (_b = modies_1.return)) _b.call(modies_1);
|
if (modies_1_1 && !modies_1_1.done && (_b = modies_1.return)) _b.call(modies_1);
|
||||||
}
|
}
|
||||||
finally { if (e_1) throw e_1.error; }
|
finally { if (e_1) throw e_1.error; }
|
||||||
return [7 /*endfinally*/];
|
return [7 /*endfinally*/];
|
||||||
case 9: return [2 /*return*/, modies.length];
|
case 10: return [2 /*return*/, modies.length];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,32 @@ export function createOperationsFromModies(modies: Modi[]): Array<{
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function applyModis<ED extends EntityDict & BaseEntityDict, Cxt extends UniversalContext<ED>, Op extends OperateOption>(filter: ED['modi']['Selection']['filter'], context: Cxt, option: Op) {
|
export async function applyModis<ED extends EntityDict & BaseEntityDict, Cxt extends UniversalContext<ED>, Op extends OperateOption>(filter: ED['modi']['Selection']['filter'], context: Cxt, option: Op) {
|
||||||
|
const { result: modis } = await context.rowStore.select('modi', {
|
||||||
|
data: {
|
||||||
|
id: 1,
|
||||||
|
},
|
||||||
|
filter,
|
||||||
|
sorter: [
|
||||||
|
{
|
||||||
|
$attr: {
|
||||||
|
$$createAt$$: 1,
|
||||||
|
},
|
||||||
|
$direction: 'asc',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, context, Object.assign({}, option, {
|
||||||
|
blockTrigger: false,
|
||||||
|
}));
|
||||||
|
|
||||||
return context.rowStore.operate('modi', {
|
return context.rowStore.operate('modi', {
|
||||||
id: await generateNewId(),
|
id: await generateNewId(),
|
||||||
action: 'apply',
|
action: 'apply',
|
||||||
data: {},
|
data: {},
|
||||||
filter,
|
filter: {
|
||||||
|
id: {
|
||||||
|
$in: modis.map(ele => ele.id),
|
||||||
|
}
|
||||||
|
},
|
||||||
sorter: [
|
sorter: [
|
||||||
{
|
{
|
||||||
$attr: {
|
$attr: {
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,19 @@ const triggers: Trigger<EntityDict, 'modi', UniversalContext<EntityDict>>[] = [
|
||||||
|
|
||||||
for (const modi of modies) {
|
for (const modi of modies) {
|
||||||
const { targetEntity, id, action, data, filter} = modi;
|
const { targetEntity, id, action, data, filter} = modi;
|
||||||
|
const targets = await context.rowStore.select(targetEntity as keyof EntityDict, {
|
||||||
|
data: {
|
||||||
|
id: 1,
|
||||||
|
},
|
||||||
|
filter: filter as any,
|
||||||
|
}, context, Object.assign({}, option, {
|
||||||
|
blockTrigger: true,
|
||||||
|
}));
|
||||||
await context.rowStore.operate(targetEntity as keyof EntityDict, {
|
await context.rowStore.operate(targetEntity as keyof EntityDict, {
|
||||||
id,
|
id,
|
||||||
action,
|
action,
|
||||||
data,
|
data,
|
||||||
filter: filter as any,
|
filter: targets.result.map(ele => ele.id),
|
||||||
}, context, Object.assign({}, option, {
|
}, context, Object.assign({}, option, {
|
||||||
blockTrigger: true,
|
blockTrigger: true,
|
||||||
}));
|
}));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue