diff --git a/src/api/authentication.js b/src/api/authentication.js new file mode 100644 index 0000000..481a5e7 --- /dev/null +++ b/src/api/authentication.js @@ -0,0 +1,35 @@ +import { config } from "../config"; +import { getAuthHeader } from "../utils/auth"; +import { httpClient } from "./httpClient"; + +export const login = (email, password) => { + const header = new Headers({ + "Content-Type": "application/json" + }); + + const body = { + email, + password + }; + + const options = { + method: "POST", + headers: header, + body: JSON.stringify(body) + }; + + return httpClient(`${config.baseURL}users/login`, options); +}; + +export const validate = () => { + const header = new Headers({ + authorization: getAuthHeader() + }); + + const options = { + method: "GET", + headers: header + }; + + return httpClient(`${config.baseURL}users/validate`, options); +}; diff --git a/src/api/categories.js b/src/api/categories.js new file mode 100644 index 0000000..dc4500f --- /dev/null +++ b/src/api/categories.js @@ -0,0 +1,16 @@ +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 + }; + + return httpClient(`${config.baseURL}categories?type=TicketStatus`, options) +} \ No newline at end of file diff --git a/src/api/httpClient.js b/src/api/httpClient.js new file mode 100644 index 0000000..c69db69 --- /dev/null +++ b/src/api/httpClient.js @@ -0,0 +1,14 @@ + +export const httpClient = (url, options) => { + return fetch(url, options) + .then(response => { + if (!response.ok) { + throw new Error(response.status); + } + + return response.json(); + }).catch(err => { + throw new Error(err); + }); + +} \ No newline at end of file diff --git a/src/api/tickets.js b/src/api/tickets.js new file mode 100644 index 0000000..17198a2 --- /dev/null +++ b/src/api/tickets.js @@ -0,0 +1,31 @@ +import { config } from '../config'; +import { getAuthHeader } from '../utils/auth'; +import { httpClient } from './httpClient'; + +export const getTickets = (page = 1, status='') => { + const header = new Headers({ + 'Content-Type': 'application/json', + 'authorization': getAuthHeader() + }); + + const options = { + method: 'GET', + headers: header + }; + + return httpClient(`${config.baseURL}tickets?page=${page}&status=${status}`, options); +} + +export const findTicket = (ticketId) => { + const header = new Headers({ + 'Content-Type': 'application/json', + 'authorization': getAuthHeader() + }); + + const options = { + method: 'GET', + headers: header + }; + + return httpClient(`${config.baseURL}tickets?id=${ticketId}`, options); +}