mirror of
				https://github.com/franjsco/tick3t
				synced 2025-06-05 22:19:18 +02:00 
			
		
		
		
	feat(api): add new methods ticket
This commit is contained in:
		| @@ -1,11 +1,10 @@ | ||||
| import { config } from '../config'; | ||||
| import { getAuthHeader } from '../utils/auth'; | ||||
| import { httpClient } from './httpClient'; | ||||
| import { authHeader } from '../_helpers'; | ||||
|  | ||||
| export const getTickets = (page = 1, status = '') => { | ||||
|   const header = new Headers({ | ||||
|     'Content-Type': 'application/json', | ||||
|     'authorization': getAuthHeader() | ||||
|     'authorization': authHeader() | ||||
|   }); | ||||
|  | ||||
|   const options = { | ||||
| @@ -13,13 +12,42 @@ export const getTickets = (page = 1, status='') => { | ||||
|     headers: header | ||||
|   }; | ||||
|  | ||||
|   return httpClient(`${config.baseURL}tickets?page=${page}&status=${status}`, options); | ||||
|   return fetch(`${config.baseURL}tickets?page=${page}&status=${status}`, options) | ||||
|     .then(res => { | ||||
|       if (res.ok) { | ||||
|         return res.json(); | ||||
|       } else { | ||||
|         throw new Error('Ops,problem') | ||||
|       } | ||||
|     });; | ||||
| } | ||||
|  | ||||
| export const viewTicket = (ticketId) => { | ||||
|   const header = new Headers({ | ||||
|     'Content-Type': 'application/json' | ||||
|   }); | ||||
|  | ||||
|   const options = { | ||||
|     method: 'GET', | ||||
|     headers: header | ||||
|   }; | ||||
|  | ||||
|   return fetch(`${config.baseURL}tickets/${ticketId}`, options) | ||||
|     .then(res => { | ||||
|       if (res.ok) { | ||||
|         return res.json(); | ||||
|       } else if (res.status === 404) { | ||||
|         throw new Error('Ticket not found.'); | ||||
|       } else { | ||||
|         throw new Error('Ops,problem'); | ||||
|       } | ||||
|     }); | ||||
| } | ||||
|  | ||||
| export const findTicket = (ticketId) => { | ||||
|   const header = new Headers({ | ||||
|     'Content-Type': 'application/json', | ||||
|     'authorization': getAuthHeader() | ||||
|     'authorization': authHeader() | ||||
|   }); | ||||
|  | ||||
|   const options = { | ||||
| @@ -27,5 +55,60 @@ export const findTicket = (ticketId) => { | ||||
|     headers: header | ||||
|   }; | ||||
|  | ||||
|   return httpClient(`${config.baseURL}tickets?id=${ticketId}`, options); | ||||
|   return fetch(`${config.baseURL}tickets?id=${ticketId}`, options) | ||||
|     .then(res => { | ||||
|       if (res.ok) { | ||||
|         return res.json(); | ||||
|       } else { | ||||
|         throw new Error('Ops,problem'); | ||||
|       } | ||||
|     }); | ||||
| } | ||||
|  | ||||
| export const updateTicket = (ticket) => { | ||||
|   const header = new Headers({ | ||||
|     'Content-Type': 'application/json', | ||||
|     'authorization': authHeader() | ||||
|   }); | ||||
|  | ||||
|   const options = { | ||||
|     method: 'PUT', | ||||
|     headers: header, | ||||
|     body: JSON.stringify({ | ||||
|       status: ticket.status, | ||||
|       note: ticket.note | ||||
|     }) | ||||
|   }; | ||||
|  | ||||
|   return fetch(`${config.baseURL}tickets/${ticket.ticketId}`, options) | ||||
|     .then(res => { | ||||
|       console.log(res.status) | ||||
|       if (res.ok) { | ||||
|         return res.json(); | ||||
|       } else { | ||||
|         throw new Error('Ops,problem'); | ||||
|       } | ||||
|     }); | ||||
| } | ||||
|  | ||||
|  | ||||
| export const createTicket = (ticket) => { | ||||
|   const header = new Headers({ | ||||
|     'Content-Type': 'application/json', | ||||
|   }); | ||||
|  | ||||
|   const options = { | ||||
|     method: 'POST', | ||||
|     headers: header, | ||||
|     body: JSON.stringify(ticket) | ||||
|   }; | ||||
|  | ||||
|   return fetch(`${config.baseURL}tickets`, options) | ||||
|     .then(res => { | ||||
|       if (res.ok) { | ||||
|         return res.json(); | ||||
|       } else { | ||||
|         throw new Error('Ops, prolem'); | ||||
|       } | ||||
|     }); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user