Skip to content

Commit

Permalink
Make batchUpdate more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
elsaperelli committed Aug 19, 2024
1 parent 65581f1 commit 2e47e38
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions service/src/db/dbOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,9 @@ export async function batchInsert(artifacts: FhirArtifact[], action: string) {

/**
* Updates a parent artifact and all of its children (if applicable) in a batch
* to set the date and approvalDate elements of the approved artifacts as well
* as add an 'Approve' cqfm-artifactComment extension to the artifacts
* transaction
*/
export async function batchUpdate(artifacts: FhirArtifact[]) {
export async function batchUpdate(artifacts: FhirArtifact[], action: string) {
let error = null;
const results: FhirArtifact[] = [];
const updateSession = Connection.connection?.startSession();
Expand All @@ -172,9 +171,9 @@ export async function batchUpdate(artifacts: FhirArtifact[]) {
results.push(artifact);
}
});
console.log(`Batch approve transaction committed.`);
console.log(`Batch ${action} transaction committed.`);
} catch (err) {
console.log('Batch approve transaction failed: ' + err);
console.log(`Batch ${action} transaction failed: ` + err);
error = err;
} finally {
await updateSession?.endSession();
Expand Down
2 changes: 1 addition & 1 deletion service/src/services/LibraryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export class LibraryService implements Service<CRMIShareableLibrary> {
});

// now we want to batch update the approved parent Library and any of its children
const approvedArtifacts = await batchUpdate([library, ...(await Promise.all(children))]);
const approvedArtifacts = await batchUpdate([library, ...(await Promise.all(children))], 'approve');

// we want to return a Bundle containing the updated artifacts
return createBatchResponseBundle(approvedArtifacts);
Expand Down
2 changes: 1 addition & 1 deletion service/src/services/MeasureService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export class MeasureService implements Service<CRMIShareableMeasure> {
});

// now we want to batch update the approved parent Measure and any of its children
const approvedArtifacts = await batchUpdate([measure, ...(await Promise.all(children))]);
const approvedArtifacts = await batchUpdate([measure, ...(await Promise.all(children))], 'approve');

// we want to return a Bundle containing the updated artifacts
return createBatchResponseBundle(approvedArtifacts);
Expand Down

0 comments on commit 2e47e38

Please sign in to comment.