Skip to content

Commit

Permalink
Update preprocessor
Browse files Browse the repository at this point in the history
Handle errors while creating caserevisions
update curator data
  • Loading branch information
stanislaw-zakrzewski committed Apr 3, 2024
1 parent 764dc98 commit 8f442de
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions data-serving/data-service/src/controllers/preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,22 @@ export const setBatchUpsertFields = async (
);
}
}
const curator = request.body.curator.email;
const curator = request.body.curator;
if (curator) {
c.curator = curator;
c.revisionMetadata = {
revisionNumber: 0,
creationMetadata: {
curator,
curator: curator.email,
date: currentDate,
},
updateMetadata: {
curator,
curator: curator.email,
date: currentDate,
notes: 'Creation',
},
};
}
console.log('Case:', c.revisionMetadata);
});
// Clean up the additional metadata that falls outside the `case` entity.
delete request.body.curator;
Expand Down Expand Up @@ -243,14 +243,19 @@ export const createBatchDeleteCaseRevisions = async (
});
}

await CaseRevision.insertMany(casesToDelete, {
ordered: false,
rawResult: true,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Mongoose types don't include the `lean` option from its
// documentation: https://mongoosejs.com/docs/api.html#model_Model.insertMany
lean: true,
});
try {
await CaseRevision.insertMany(casesToDelete, {
ordered: false,
rawResult: true,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Mongoose types don't include the `lean` option from its
// documentation: https://mongoosejs.com/docs/api.html#model_Model.insertMany
lean: true,
});
} catch (err) {
console.log('Failed to insert some case revisions');
console.log(err);
}

next();
};
Expand Down

0 comments on commit 8f442de

Please sign in to comment.