This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
715 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { | ||
AccessBulkDataJobRequest, | ||
Authorization, | ||
BulkDataAccess, | ||
GetExportStatusResponse, | ||
InitiateExportRequest, | ||
} from 'fhir-works-on-aws-interface'; | ||
import createError from 'http-errors'; | ||
|
||
export default class ExportHandler { | ||
private bulkDataAccess: BulkDataAccess; | ||
|
||
private authService: Authorization; | ||
|
||
constructor(bulkDataAccess: BulkDataAccess, authService: Authorization) { | ||
this.bulkDataAccess = bulkDataAccess; | ||
this.authService = authService; | ||
} | ||
|
||
async initiateExport(initiateExportRequest: InitiateExportRequest): Promise<string> { | ||
return this.bulkDataAccess.initiateExport(initiateExportRequest); | ||
} | ||
|
||
async getExportJobStatus(jobId: string, requesterUserId: string): Promise<GetExportStatusResponse> { | ||
const jobDetails = await this.bulkDataAccess.getExportStatus(jobId); | ||
await this.checkIfRequesterHasAccessToJob(jobDetails, requesterUserId); | ||
return jobDetails; | ||
} | ||
|
||
async cancelExport(jobId: string, requesterUserId: string): Promise<void> { | ||
const jobDetails = await this.bulkDataAccess.getExportStatus(jobId); | ||
await this.checkIfRequesterHasAccessToJob(jobDetails, requesterUserId); | ||
if (['completed', 'failed'].includes(jobDetails.jobStatus)) { | ||
throw new createError.BadRequest( | ||
`Job cannot be canceled because job is already in ${jobDetails.jobStatus} state`, | ||
); | ||
} | ||
|
||
await this.bulkDataAccess.cancelExport(jobId); | ||
} | ||
|
||
private async checkIfRequesterHasAccessToJob(jobDetails: GetExportStatusResponse, requesterUserId: string) { | ||
const { jobOwnerId } = jobDetails; | ||
const accessBulkDataJobRequest: AccessBulkDataJobRequest = { requesterUserId, jobOwnerId }; | ||
await this.authService.isAccessBulkDataJobAllowed(accessBulkDataJobRequest); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.