From e7793fe063f5679cf8493d4c7f38f86e81c05f8a Mon Sep 17 00:00:00 2001 From: Francesco Esposito <33671357+frsposito@users.noreply.github.com> Date: Wed, 31 Jul 2019 15:57:44 +0200 Subject: [PATCH] feat(api): add new methods categories --- src/api/categories.js | 45 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/src/api/categories.js b/src/api/categories.js index dc4500f..2fc3e5a 100644 --- a/src/api/categories.js +++ b/src/api/categories.js @@ -1,16 +1,47 @@ import { config } from '../config'; -import { httpClient } from './httpClient'; export const getAllTicketStatus = () => { - const header = new Headers({ 'Content-Type': 'application/json' }); - const options = { - method: 'GET', - headers: header - }; + const options = { + method: 'GET', + headers: header + }; - return httpClient(`${config.baseURL}categories?type=TicketStatus`, options) + return fetch(`${config.baseURL}categories?type=TicketStatus`, options) + .then(res => { + if (res.ok) { + return res.json(); + } else if (res.status === 404) { + throw new Error('Categories not found.'); + } else { + throw new Error('Ops,problem'); + }; + }); +} + + +export const getAllTicketType = () => { + const header = new Headers({ + 'Content-Type': 'application/json' + }); + + const options = { + method: 'GET', + headers: header + }; + + + return fetch(`${config.baseURL}categories?type=TicketType`, options) + .then(res => { + if (res.ok) { + return res.json(); + } else if (res.status === 404) { + throw new Error('Categories not found.'); + } else { + throw new Error('Ops,problem'); + }; + }); } \ No newline at end of file