Skip to content

Commit

Permalink
feat(analytic-payment-opt): add meta and branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Jessica Kellogg committed Jul 16, 2019
1 parent 909d48e commit e6a5095
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/errors/analytics.ts
Expand Up @@ -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) {
Expand Down
28 changes: 27 additions & 1 deletion src/v0/analytics/reports/payment_options.ts
Expand Up @@ -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
Expand Down Expand Up @@ -52,4 +52,30 @@ export class PaymentOptions {
}
})
}

meta(query?: PaymentOptionsQuery): Promise<PaymentOptionsResponse> {
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())
}
})
}
}

0 comments on commit e6a5095

Please sign in to comment.