Skip to content

Commit

Permalink
feat: fixes put; fixes options
Browse files Browse the repository at this point in the history
  • Loading branch information
eljefedelrodeodeljefe committed Sep 24, 2018
1 parent fe7864e commit 10214ac
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 42 deletions.
54 changes: 20 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -90,6 +90,7 @@
"@storybook/addon-actions": "^3.4.10",
"@storybook/react": "^4.0.0-alpha.21",
"@types/jest": "^23.3.2",
"@types/qs": "^6.5.1",
"axios-mock-adapter": "^1.15.0",
"babel-core": "^6.26.3",
"babel-loader": "^8.0.2",
Expand Down Expand Up @@ -142,7 +143,8 @@
"webpack-cli": "^3.1.0"
},
"dependencies": {
"axios": "^0.18.0"
"axios": "^0.18.0",
"qs": "^6.5.2"
},
"release": {
"verifyConditions": [
Expand Down
18 changes: 11 additions & 7 deletions src/v1/templates.ts
@@ -1,9 +1,11 @@
import qs from 'qs'
import { Client } from '../client'
import * as errors from '../errors'

export interface TemplatesQuery {
export interface TemplatesOptions {
limit?: number
uri?: string
query?: any
}

type TemplateTypes = 'delivery_note_v1' | 'invoice_v1' | 'full_receipt_v1'
Expand Down Expand Up @@ -74,9 +76,9 @@ export class Templates {
})
}

put(template: Template): Promise<TemplatesResponse> {
put(templateId: string, template: Template): Promise<TemplatesResponse> {
return new Promise(async (resolve, reject) => {
const uri = `${this.options.base}${this.endpoint}/${this.options.user}`
const uri = `${this.options.base}${this.endpoint}/${this.options.user}/${templateId}`
try {
const response = await this.http.getClient().put(uri, template)

Expand All @@ -90,14 +92,16 @@ export class Templates {
})
}

getAll(query?: TemplatesQuery | undefined): Promise<TemplatesResponse> {
getAll(options?: TemplatesOptions | undefined): Promise<TemplatesResponse> {
return new Promise(async (resolve, reject) => {
try {
let uri
if (query && query.uri) {
uri = query.uri
if (options && options.uri) {
uri = options.uri
} else {
uri = `${this.options.base}${this.endpoint}/${this.options.user}`
uri = `${this.options.base}${this.endpoint}/${this.options.user}${
options && options.query ? qs.stringify(options.query) : ''
}`
}

const response = await this.http.getClient().get(uri)
Expand Down

0 comments on commit 10214ac

Please sign in to comment.