diff --git a/src/errors/analytics.ts b/src/errors/analytics.ts index 3627dbec486..aa302c9b527 100644 --- a/src/errors/analytics.ts +++ b/src/errors/analytics.ts @@ -31,6 +31,16 @@ export class ReportsPaymentOptionsFetchAllFailed extends BaseError { } } +export class ReportsPaymentOptionsMetaFailed extends BaseError { + public name = 'ReportsPaymentOptionsMetaFailed' + constructor( + public message: string = 'Could not fetch meta the payment options', + properties?: any + ) { + super(message, properties) + } +} + export class ReportsPaymentsFetchAllFailed extends BaseError { public name = 'ReportsPaymentsFetchAllFailed' constructor(public message: string = 'Could not fetch all the payments', properties?: any) { diff --git a/src/v0/analytics/reports/payment_options.ts b/src/v0/analytics/reports/payment_options.ts index bc8d5d02cd0..4c938b1c56a 100644 --- a/src/v0/analytics/reports/payment_options.ts +++ b/src/v0/analytics/reports/payment_options.ts @@ -15,7 +15,7 @@ export interface PaymentOptionsResponse { export interface PaymentOptionsQuery { start?: string end?: string - branch_id?: string + branch_number?: string register_id?: string payment_method?: string uri?: string @@ -52,4 +52,30 @@ export class PaymentOptions { } }) } + + meta(query?: PaymentOptionsQuery): Promise { + return new Promise(async (resolve, reject) => { + try { + const base = this.uriHelper.generateBaseUri('/reports/payment_options/meta') + const uri = this.uriHelper.generateUriWithQuery(base, query) + const response = await this.http.getClient().get(uri) + + if (response.status !== 200) return reject(new errors.ReportsPaymentOptionsMetaFailed(undefined, { status: response.status })) + + if (!response.data.results[0]) { + return reject( + new errors.ReportsPaymentOptionsMetaFailed('Could not get balances metadata unexpectedly') + ) + } + + return resolve({ + data: response.data.results[0], + metadata: { count: response.data.count } + } as PaymentOptionsResponse) + + } catch (err) { + return reject(new errors.ReportsPaymentOptionsMetaFailed()) + } + }) + } }