From ccc4369f1abce6b4173323519d7d8d453992f64a Mon Sep 17 00:00:00 2001 From: EJ Mercado Date: Mon, 8 Jun 2020 17:52:55 +0800 Subject: [PATCH] feat: get report request count --- src/sections/reports.ts | 43 +++++++++++++++++++- test/unit/__snapshots__/reports.test.ts.snap | 15 +++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/sections/reports.ts b/src/sections/reports.ts index b4260698..38673c1d 100644 --- a/src/sections/reports.ts +++ b/src/sections/reports.ts @@ -1,4 +1,4 @@ -import { boolean, Codec, GetInterface, optional, string } from 'purify-ts' +import { boolean, Codec, GetInterface, number, optional, string } from 'purify-ts' import { ParsingError } from '../error' import { HttpClient, RequestMeta, Resource } from '../http' @@ -86,9 +86,50 @@ interface GetReportRequestListByNextTokenParameters { NextToken: NextToken<'GetReportRequestList'> } +interface GetReportRequestCountParameters { + ReportTypeList?: ReportType[] + ReportProcessingStatusList?: ReportProcessing[] + RequestedFromDate?: Date + RequestedToDate?: Date +} + +const GetReportRequestCount = Codec.interface({ + Count: number, +}) + +const GetReportRequestCountResponse = Codec.interface({ + GetReportRequestCountResponse: Codec.interface({ + GetReportRequestCountResult: GetReportRequestCount, + }), +}) + +type GetReportRequestCount = GetInterface export class Reports { constructor(private httpClient: HttpClient) {} + async getReportRequestCount( + parameters: GetReportRequestCountParameters, + ): Promise<[GetReportRequestCount, RequestMeta]> { + const [response, meta] = await this.httpClient.request('POST', { + resource: Resource.Report, + version: REPORTS_API_VERSION, + action: 'GetReportRequestCount', + parameters: { + 'ReportTypeList.Type': parameters.ReportTypeList, + 'ReportProcessingStatusList.Status': parameters.ReportProcessingStatusList, + RequestedFromDate: parameters.RequestedFromDate?.toISOString(), + RequestedToDate: parameters.RequestedToDate?.toISOString(), + }, + }) + + return GetReportRequestCountResponse.decode(response).caseOf({ + Right: (x) => [x.GetReportRequestCountResponse.GetReportRequestCountResult, meta], + Left: (error) => { + throw new ParsingError(error) + }, + }) + } + async getReportRequestListByNextToken( parameters: GetReportRequestListByNextTokenParameters, ): Promise<[GetReportRequestListResult, RequestMeta]> { diff --git a/test/unit/__snapshots__/reports.test.ts.snap b/test/unit/__snapshots__/reports.test.ts.snap index 6528205e..4aeabc14 100644 --- a/test/unit/__snapshots__/reports.test.ts.snap +++ b/test/unit/__snapshots__/reports.test.ts.snap @@ -1,5 +1,20 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`reports getReportRequestCount returns report request count if succesful 1`] = ` +Array [ + Object { + "Count": 1276, + }, + Object { + "quotaMax": 1000, + "quotaRemaining": 999, + "quotaResetOn": 2020-04-06T10:22:23.582Z, + "requestId": "0", + "timestamp": 2020-05-06T09:22:23.582Z, + }, +] +`; + exports[`reports getReportRequestList returns report request info if succesful 1`] = ` Array [ Object {