Skip to content

Commit

Permalink
Merge branch 'refactor/lookup-reference' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
7sete7 committed Nov 29, 2024
2 parents ea9dd8d + 336f867 commit 1752cce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 122 deletions.
1 change: 1 addition & 0 deletions src/imports/data/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,7 @@ export async function update({ authTokenId, document, data, contextUser, tracing
});

if (updateResults.some(result => result.success === false)) {
await dbSession.abortTransaction();
return errorReturn(
updateResults
.filter(result => result.success === false)
Expand Down
19 changes: 12 additions & 7 deletions src/imports/konsistent/createHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,38 @@ import pick from "lodash/pick";
import { v4 as uuidV4 } from 'uuid';

export default async function createHistory(metaName, action, id, updatedBy, updatedAt, changed, dbSession) {
// If data is empty or no update data is avaible then abort
if (Object.keys(changed).length === 0 || updatedAt == null || updatedBy == null) {
return;
}

const keysToIgnore = ['_updatedAt', '_createdAt', '_deletedAt', '_updatedBy', '_createdBy', '_deletedBy'];
const changeId = uuidV4();
const meta = MetaObject.Meta[metaName];

const history = MetaObject.Collections[`${metaName}.History`];
if (!history) {
return logger.error(`Can't get History collection from ${metaName}`);
}

const userDetailFields = ["_id"].concat(get(meta, "fields._user.descriptionFields", ["name", "active"]));
const historyData = omitBy(changed, (value, key) => keysToIgnore.includes(key) || meta.fields[key]?.ignoreHistory);
if (Object.keys(historyData).length === 0) {
logger.trace(`No history data for ${metaName}`);
return;
}

const userDescriptionFields = ["_id"].concat(get(meta, "fields._user.descriptionFields", ["name", "active"]));
const historyItem = {
_id: uuidV4(),
dataId: id,
createdAt: updatedAt,
createdBy: pick(updatedBy, userDetailFields),
data: omitBy(changed, (value, key) => keysToIgnore.includes(key) || meta.fields[key]?.ignoreHistory),
createdBy: pick(updatedBy, userDescriptionFields),
data: historyData,
type: action,
};

try {
const historyQuery = { _id: changeId };
await history.updateOne(historyQuery, { $set: historyItem, $setOnInsert: historyQuery }, { upsert: true, session: dbSession });
await history.insertOne(historyItem, { session: dbSession });
} catch (e) {
logger.error(e, 'Error on create history');
await dbSession?.abortTransaction();
}
}
115 changes: 0 additions & 115 deletions src/imports/konsistent/processOplogItem.js

This file was deleted.

0 comments on commit 1752cce

Please sign in to comment.