Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
feat: cancel report requests'
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jun 8, 2020
1 parent c7fe5ea commit d0c546b
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/sections/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,54 @@ const GetReportRequestCountResponse = Codec.interface({
})

type GetReportRequestCount = GetInterface<typeof GetReportRequestCount>

interface CancelReportRequestsParameters {
ReportRequestIdList?: string[]
ReportTypeList?: ReportType[]
ReportProcessingStatusList?: ReportProcessing[]
RequestedFromDate?: Date
RequestedToDate?: Date
}

const CancelReportRequests = Codec.interface({
Count: number,
ReportRequestInfo,
})

const CancelReportRequestsResponse = Codec.interface({
CancelReportRequestsResponse: Codec.interface({
CancelReportRequestsResult: CancelReportRequests,
}),
})

type CancelReportRequests = GetInterface<typeof CancelReportRequests>
export class Reports {
constructor(private httpClient: HttpClient) {}

async cancelReportRequests(
parameters: CancelReportRequestsParameters,
): Promise<[CancelReportRequests, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Report,
version: REPORTS_API_VERSION,
action: 'CancelReportRequests',
parameters: {
'ReportRequestIdList.Id': parameters.ReportRequestIdList,
'ReportTypeList.Type': parameters.ReportRequestIdList,
'ReportProcessingStatusList.Status': parameters.ReportProcessingStatusList,
RequestedFromDate: parameters.RequestedFromDate?.toISOString(),
RequestedToDate: parameters.RequestedToDate?.toISOString(),
},
})

return CancelReportRequestsResponse.decode(response).caseOf({
Right: (x) => [x.CancelReportRequestsResponse.CancelReportRequestsResult, meta],
Left: (error) => {
throw new ParsingError(error)
},
})
}

async getReportRequestCount(
parameters: GetReportRequestCountParameters,
): Promise<[GetReportRequestCount, RequestMeta]> {
Expand Down
27 changes: 27 additions & 0 deletions test/unit/__snapshots__/reports.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`reports cancelReportRequests returns count and detailed info of cancelled requests if succesful 1`] = `
Array [
Object {
"Count": 1,
"ReportRequestInfo": Object {
"CompletedDate": undefined,
"EndDate": 2009-02-13T02:10:39.000Z,
"GeneratedReportId": undefined,
"ReportProcessingStatus": "_CANCELLED_",
"ReportRequestId": "2291326454",
"ReportType": "_GET_MERCHANT_LISTINGS_DATA_",
"Scheduled": false,
"StartDate": 2009-01-21T02:10:39.000Z,
"StartedProcessingDate": undefined,
"SubmittedDate": 2009-02-20T02:10:39.000Z,
},
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;

exports[`reports getReportRequestCount returns report request count if succesful 1`] = `
Array [
Object {
Expand Down

0 comments on commit d0c546b

Please sign in to comment.