Skip to content

Commit

Permalink
feat(analytics): adds simple cartitem tx
Browse files Browse the repository at this point in the history
  • Loading branch information
eljefedelrodeodeljefe committed Jan 16, 2019
1 parent fc62c9c commit da3234f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/errors.ts
Expand Up @@ -907,6 +907,13 @@ export class PaymentsReportFetchFailed extends BaseError {
}
}

export class SimpleSalesCartItemsReportFetchFailed extends BaseError {
public name = 'SimpleSalesCartItemsReportFetchFailed'
constructor(public message: string = 'Could not fetch the sales cart items report', properties?: any) {
super(message, properties)
}
}

export class AuditActionsFetchAllFailed extends BaseError {
public name = 'AuditActionsFetchAllFailed'
constructor(public message: string = 'Could not fetch audit actions', properties?: any) {
Expand Down
45 changes: 41 additions & 4 deletions src/v0/analytics.ts
Expand Up @@ -66,6 +66,14 @@ export interface VoucherOptions {
type?: 'update:update' | 'update:decrement' | 'update:increment' | 'create'
}

export interface SimpleSalesCartItemsOptions {
[key: string]: any
start?: string
end?: string,
embed?: string | string[]
include?: string | string[]
}

export class Analytics {
endpoint: string
http: Client
Expand Down Expand Up @@ -193,7 +201,7 @@ export class Analytics {
try {
const uri = `${this.options.base}${this.endpoint}/${
this.options.user
}/reports/staff/overview`
}/reports/staff/overview`

const response = await this.http.getClient().get(uri)
response.status !== 200 && reject(new errors.StaffOverviewFetchFailed())
Expand All @@ -213,7 +221,7 @@ export class Analytics {
try {
const uri = `${this.options.base}${this.endpoint}/${
this.options.user
}/reports/staff/product_groups/${staff || ''}`
}/reports/staff/product_groups/${staff || ''}`

const response = await this.http.getClient().get(uri)
response.status !== 200 && reject(new errors.ProductGroupsReportFetchFailed())
Expand All @@ -233,7 +241,7 @@ export class Analytics {
try {
const uri = `${this.options.base}${this.endpoint}/${
this.options.user
}/reports/staff/refunds/${staff || ''}`
}/reports/staff/refunds/${staff || ''}`

const response = await this.http.getClient().get(uri)
response.status !== 200 && reject(new errors.RefundsReportFetchFailed())
Expand Down Expand Up @@ -277,7 +285,7 @@ export class Analytics {
try {
const uri = `${this.options.base}${this.endpoint}/${
this.options.user
}/reports/staff/products/${staff || ''}`
}/reports/staff/products/${staff || ''}`

const response = await this.http.getClient().get(uri)
response.status !== 200 && reject(new errors.ProductsReportFetchFailed())
Expand Down Expand Up @@ -311,4 +319,33 @@ export class Analytics {
}
})
}

getSimpleSalesCartItems(query?: SimpleSalesCartItemsOptions | undefined): Promise<AnalyticsResponse> {
return new Promise(async (resolve, reject) => {
try {
let uri = `${this.options.base}${this.endpoint}/${
this.options.user
}/reports/transactions/simple`

const queryString = qs.stringify(query)

if (queryString) {
uri = `${uri}?${queryString}`
}

const response = await this.http.getClient().get(uri)
response.status !== 200 && reject(new errors.SimpleSalesCartItemsReportFetchFailed())

return resolve({
data: response.data.results[0].results,
metadata: {
count: response.data.results[0].count,
metric: response.data.results[0].metric
}
} as AnalyticsResponse)
} catch (err) {
return reject(new errors.SimpleSalesCartItemsReportFetchFailed())
}
})
}
}

0 comments on commit da3234f

Please sign in to comment.