修正了一下对更新无属性情况的处理

This commit is contained in:
Xu Chang 2024-12-25 13:26:38 +08:00
parent 31fd80d9a0
commit f4af94a98a
2 changed files with 142 additions and 140 deletions

View File

@ -1405,16 +1405,24 @@ class CascadeStore extends RowStore_1.RowStore {
},
};
};
if (option.modiParentEntity && !['modi', 'modiEntity'].includes(entity)) {
// 延时更新变成对modi的操作
if (action === 'update' && Object.keys(data).length === 0) {
return {};
const saveRecordAndCreateOper = async () => {
if (action === 'remove') {
if (!option.dontCollect) {
context.saveOpRecord(entity, {
id: operId,
action,
data: data,
filter: {
id: {
$in: ids,
}
},
});
}
}
return createModi();
}
else {
const saveRecordAndCreateOper = async () => {
if (action === 'remove') {
else {
const updateAttrCount = Object.keys(data).length;
if (updateAttrCount > 0) {
if (!option.dontCollect) {
context.saveOpRecord(entity, {
id: operId,
@ -1428,68 +1436,61 @@ class CascadeStore extends RowStore_1.RowStore {
});
}
}
else {
const updateAttrCount = Object.keys(data).length;
if (updateAttrCount > 0) {
if (!option.dontCollect) {
context.saveOpRecord(entity, {
id: operId,
action,
data: data,
filter: {
id: {
$in: ids,
}
},
});
}
}
else {
return {};
}
}
if (!option.dontCreateOper && !['oper', 'operEntity', 'modiEntity', 'modi', 'log'].includes(entity) && ids.length > 0) {
// 按照框架要求生成Oper和OperEntity这两个内置的对象
(0, assert_1.default)(operId);
const operatorId = context.getCurrentUserId(true);
const createOper = {
id: 'dummy',
action: 'create',
data: {
id: operId,
action,
data,
targetEntity: entity,
bornAt,
operatorId,
operEntity$oper: {
id: 'dummy',
action: 'create',
data: await Promise.all(ids.map(async (ele) => ({
id: await (0, uuid_1.generateNewIdAsync)(),
entityId: ele,
entity: entity,
})))
},
filter: {
id: { $in: ids },
},
logId: entity === 'log' ? undefined : option.logId,
undoData,
}
if (!option.dontCreateOper && !['oper', 'operEntity', 'modiEntity', 'modi', 'log'].includes(entity) && ids.length > 0) {
// 按照框架要求生成Oper和OperEntity这两个内置的对象
(0, assert_1.default)(operId);
const operatorId = context.getCurrentUserId(true);
const createOper = {
id: 'dummy',
action: 'create',
data: {
id: operId,
action,
data,
targetEntity: entity,
bornAt,
operatorId,
operEntity$oper: {
id: 'dummy',
action: 'create',
data: await Promise.all(ids.map(async (ele) => ({
id: await (0, uuid_1.generateNewIdAsync)(),
entityId: ele,
entity: entity,
})))
},
};
const closeRootMode = context.openRootMode();
await this.cascadeUpdateAsync('oper', createOper, context, {
dontCollect: !option.logId, // 如果是在创建log则把oper收集回去
});
closeRootMode();
}
return {
[entity]: {
[action]: ids.length,
}
filter: {
id: { $in: ids },
},
logId: entity === 'log' ? undefined : option.logId,
undoData,
},
};
const closeRootMode = context.openRootMode();
await this.cascadeUpdateAsync('oper', createOper, context, {
dontCollect: !option.logId, // 如果是在创建log则把oper收集回去
});
closeRootMode();
}
return {
[entity]: {
[action]: ids.length,
}
};
};
if (action !== 'remove' && Object.keys(data).length === 0) {
if (action !== 'update') {
// 如果不是update这里还是记一条oper
return saveRecordAndCreateOper();
}
return {};
}
if (option.modiParentEntity && !['modi', 'modiEntity'].includes(entity)) {
// 延时更新变成对modi的操作
return createModi();
}
else {
const count = await this.updateAbjointRowAsync(entity, operation, context, option);
if (count === ids.length) {
return await saveRecordAndCreateOper();

View File

@ -1699,16 +1699,24 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
} as OperationResult<ED>;
};
if (option.modiParentEntity && !['modi', 'modiEntity'].includes(entity as string)) {
// 延时更新变成对modi的操作
if (action === 'update' && Object.keys(data).length === 0) {
return {};
const saveRecordAndCreateOper = async () => {
if (action === 'remove') {
if (!option.dontCollect) {
context.saveOpRecord(entity, {
id: operId,
action,
data: data as ED[T]['Update']['data'],
filter: {
id: {
$in: ids,
}
},
});
}
}
return createModi();
}
else {
const saveRecordAndCreateOper = async () => {
if (action === 'remove') {
else {
const updateAttrCount = Object.keys(data).length;
if (updateAttrCount > 0) {
if (!option.dontCollect) {
context.saveOpRecord(entity, {
id: operId,
@ -1722,73 +1730,66 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
});
}
}
else {
const updateAttrCount = Object.keys(data).length;
if (updateAttrCount > 0) {
if (!option.dontCollect) {
context.saveOpRecord(entity, {
id: operId,
action,
data: data as ED[T]['Update']['data'],
filter: {
id: {
$in: ids,
}
},
});
}
}
else {
return {};
}
}
if (!option.dontCreateOper && !['oper', 'operEntity', 'modiEntity', 'modi', 'log'].includes(entity as string) && ids.length > 0) {
// 按照框架要求生成Oper和OperEntity这两个内置的对象
assert(operId);
const operatorId = context.getCurrentUserId(true);
const createOper: CreateSingleOperOperation = {
id: 'dummy',
action: 'create',
data: {
id: operId,
action,
data,
targetEntity: entity as string,
bornAt,
operatorId,
operEntity$oper: {
id: 'dummy',
action: 'create',
data: await Promise.all(
ids.map(
async (ele) => ({
id: await generateNewIdAsync(),
entityId: ele,
entity: entity as string,
})
)
}
if (!option.dontCreateOper && !['oper', 'operEntity', 'modiEntity', 'modi', 'log'].includes(entity as string) && ids.length > 0) {
// 按照框架要求生成Oper和OperEntity这两个内置的对象
assert(operId);
const operatorId = context.getCurrentUserId(true);
const createOper: CreateSingleOperOperation = {
id: 'dummy',
action: 'create',
data: {
id: operId,
action,
data,
targetEntity: entity as string,
bornAt,
operatorId,
operEntity$oper: {
id: 'dummy',
action: 'create',
data: await Promise.all(
ids.map(
async (ele) => ({
id: await generateNewIdAsync(),
entityId: ele,
entity: entity as string,
})
)
},
filter: {
id: { $in: ids },
},
logId: entity === 'log' ? undefined : option.logId,
undoData,
)
},
}
const closeRootMode = context.openRootMode();
await this.cascadeUpdateAsync('oper', createOper, context, {
dontCollect: !option.logId, // 如果是在创建log则把oper收集回去
});
closeRootMode();
filter: {
id: { $in: ids },
},
logId: entity === 'log' ? undefined : option.logId,
undoData,
},
}
const closeRootMode = context.openRootMode();
await this.cascadeUpdateAsync('oper', createOper, context, {
dontCollect: !option.logId, // 如果是在创建log则把oper收集回去
});
closeRootMode();
}
return {
[entity]: {
[action as ED[T]['Action']]: ids.length,
}
} as OperationResult<ED>;
};
return {
[entity]: {
[action as ED[T]['Action']]: ids.length,
}
} as OperationResult<ED>;
};
if (action !== 'remove' && Object.keys(data).length === 0) {
if (action !== 'update') {
// 如果不是update这里还是记一条oper
return saveRecordAndCreateOper();
}
return {};
}
if (option.modiParentEntity && !['modi', 'modiEntity'].includes(entity as string)) {
// 延时更新变成对modi的操作
return createModi();
}
else {
const count = await this.updateAbjointRowAsync(entity, operation, context, option);
if (count === ids.length) {