mirror of https://github.com/franjsco/tick3t
improvement: add api modules
This commit is contained in:
parent
d8a990af71
commit
053b47e72d
|
@ -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);
|
||||
};
|
|
@ -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)
|
||||
}
|
|
@ -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);
|
||||
});
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue