|
| 1 | +import { IHttpClient } from "../../http"; |
| 2 | +import { PSCDiscrepancyReport } from "./types" |
| 3 | +import Util from "./util" |
| 4 | +import { Result } from "services/result"; |
| 5 | +import { ApiResponse, ApiErrorResponse } from "services/resource"; |
| 6 | + |
| 7 | +const PSC_DISCREPANCY_API_URL = "/psc-discrepancy-reports"; |
| 8 | + |
| 9 | +type PromisedReportResult= Promise<Result<ApiResponse<PSCDiscrepancyReport>, ApiErrorResponse>>; |
| 10 | + |
| 11 | +export default class { |
| 12 | + utility: Util; |
| 13 | + constructor (private readonly client: IHttpClient) { this.utility = new Util() } |
| 14 | + |
| 15 | + public async getReport (reportId: string): PromisedReportResult { |
| 16 | + return this.getReportBySelfLink(this.buildSelfLink(reportId)); |
| 17 | + } |
| 18 | + |
| 19 | + public async getReportBySelfLink (selfLink: string): PromisedReportResult { |
| 20 | + const resp = await this.client.httpGet(`${selfLink}`); |
| 21 | + return this.utility.processResponse(resp); |
| 22 | + } |
| 23 | + |
| 24 | + public async createNewReport (obligedEntityType: String): PromisedReportResult { |
| 25 | + const resp = await this.client.httpPost( |
| 26 | + PSC_DISCREPANCY_API_URL, |
| 27 | + { |
| 28 | + obligedEntityType: obligedEntityType, |
| 29 | + status: "INCOMPLETE" |
| 30 | + }); |
| 31 | + return this.utility.processResponse(resp); |
| 32 | + } |
| 33 | + |
| 34 | + public async updateReport (reportId: string, report: PSCDiscrepancyReport): PromisedReportResult { |
| 35 | + return this.updateReportBySelfLink(this.buildSelfLink(reportId), report); |
| 36 | + } |
| 37 | + |
| 38 | + public async updateReportBySelfLink (selfLink: string, report: PSCDiscrepancyReport): PromisedReportResult { |
| 39 | + const resp = await this.client.httpPut(selfLink, report); |
| 40 | + return this.utility.processResponse(resp); |
| 41 | + } |
| 42 | + |
| 43 | + private buildSelfLink (reportId: string): string { |
| 44 | + return `${PSC_DISCREPANCY_API_URL}/${reportId}`; |
| 45 | + } |
| 46 | +} |
0 commit comments