Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const BASEURL = "https://eublack-api-proxy-dev.herokuapp.com"
  2.  
  3. const login = async (user, password) => {
  4.     try {
  5.         const response = await fetch(`${BASEURL}/assinaturas/assinantes/login`, {
  6.             method: "POST",
  7.             headers: {
  8.                 "Content-Type": "application/json",
  9.             },
  10.             body: JSON.stringify({
  11.                 email: user,
  12.                 senha: password,
  13.             }),
  14.         })
  15.         return await response.json()
  16.     } catch (error) {
  17.         return error
  18.     }
  19. }
  20.  
  21. const reautenticar = async token => {
  22.     try {
  23.         const response = await fetch(`${BASEURL}/assinaturas/assinantes/reautenticar`, {
  24.             method: "POST",
  25.             headers: {
  26.                 "Content-Type": "application/json",
  27.                 Authorization: `Bearer ${token}`,
  28.             },
  29.         })
  30.         return await response.json()
  31.     } catch (error) {
  32.         return error
  33.     }
  34. }
  35.  
  36. const getUserById = async (token, id) => {
  37.     try {
  38.         const response = await fetch(`${BASEURL}/assinaturas/assinantes/${id}`, {
  39.             method: "GET",
  40.             headers: {
  41.                 "Content-Type": "application/json",
  42.                 Authorization: `Bearer ${token}`,
  43.             },
  44.         })
  45.         return await response.json()
  46.     } catch (e) {
  47.         return error
  48.     }
  49. }
  50.  
  51. const upload = async (token, file) => {
  52.     try {
  53.         const response = await fetch(`${BASEURL}/conteudos/files/upload/base64`, {
  54.             method: "POST",
  55.             headers: {
  56.                 "Content-Type": "application/json",
  57.                 Authorization: `Bearer ${token}`,
  58.             },
  59.             body: JSON.stringify({ base64Image: file }),
  60.         })
  61.         return await response.json()
  62.     } catch (e) {
  63.         return e
  64.     }
  65. }
  66.  
  67. const updateUser = async (token, id, data) => {
  68.     try {
  69.         const response = await fetch(`${BASEURL}/assinaturas/assinantes/${id}`, {
  70.             method: "PUT",
  71.             headers: {
  72.                 "Content-Type": "application/json",
  73.                 Authorization: `Bearer ${token}`,
  74.             },
  75.             body: JSON.stringify({
  76.                 id,
  77.                 ...data,
  78.             }),
  79.         })
  80.         return await response.json()
  81.     } catch (e) {
  82.         return error
  83.     }
  84. }
  85.  
  86. const updateDeviceToken = async (token, deviceToken) => {
  87.     try {
  88.         const response = await fetch(`${BASEURL}/assinaturas/assinantes/set/deviceToken`, {
  89.             method: "PUT",
  90.             headers: {
  91.                 "Content-Type": "application/json",
  92.                 Authorization: `Bearer ${token}`,
  93.             },
  94.             body: JSON.stringify({ deviceToken }),
  95.         })
  96.         return await response.json()
  97.     } catch (error) {
  98.         return null
  99.     }
  100. }
  101.  
  102. const getTrails = async () => {
  103.     try {
  104.         const response = await fetch(`${BASEURL}/gamefication/trails`, {
  105.             method: "GET",
  106.             headers: { "Content-Type": "application/json" },
  107.         })
  108.         return await response.json()
  109.     } catch (error) {
  110.         return error
  111.     }
  112. }
  113.  
  114. const getTrailById = async (token, id) => {
  115.     try {
  116.         const response = await fetch(`${BASEURL}/gamefication/trails/${id}`, {
  117.             method: "GET",
  118.             headers: {
  119.                 "Content-Type": "application/json",
  120.                 Authorization: `Bearer ${token}`,
  121.             },
  122.         })
  123.         return await response.json()
  124.     } catch (error) {
  125.         return error
  126.     }
  127. }
  128.  
  129. const getQuizById = async (token, id) => {
  130.     try {
  131.         const response = await fetch(`${BASEURL}/gamefication/quizzes/${id}`, {
  132.             method: "GET",
  133.             headers: {
  134.                 "Content-Type": "application/json",
  135.                 Authorization: `Bearer ${token}`,
  136.             },
  137.         })
  138.         return await response.json()
  139.     } catch (error) {
  140.         return error
  141.     }
  142. }
  143.  
  144. const recoverPassword = async email => {
  145.     try {
  146.         const response = await fetch(`${BASEURL}/assinaturas/assinantes/senha/recoveryPin`, {
  147.             method: "POST",
  148.             headers: { "Content-Type": "application/json" },
  149.             body: JSON.stringify({ email }),
  150.         })
  151.         return await response.json()
  152.     } catch (error) {
  153.         return error
  154.     }
  155. }
  156.  
  157. const recoverPasswordConfirm = async (pin, email, senha) => {
  158.     try {
  159.         const response = await fetch(`${BASEURL}/assinaturas/assinantes/senha/recoveryPinConfirm`, {
  160.             method: "POST",
  161.             headers: { "Content-Type": "application/json" },
  162.             body: JSON.stringify({ pin, email, senha }),
  163.         })
  164.         return await response.json()
  165.     } catch (error) {
  166.         return error
  167.     }
  168. }
  169.  
  170. const getEventsFromSchedule = async ({ searchText, pageNumber, perPage, initDate, endDate, place, eventType, placeType, city }) => {
  171.     try {
  172.         const response = await fetch(
  173.             `${BASEURL}/agendas` +
  174.                 `?searchText=${searchText}` +
  175.                 `&pageNumber=${pageNumber}` +
  176.                 `&perPage=${perPage}` +
  177.                 `&initDate=${initDate}` +
  178.                 `&endDate=${endDate}` +
  179.                 `&place=${place}` +
  180.                 `&eventType=${eventType}` +
  181.                 `&placeType=${placeType}` +
  182.                 `&city=${city}`,
  183.             {
  184.                 method: "GET",
  185.                 headers: { "Content-Type": "application/json" },
  186.             }
  187.         )
  188.         return await response.json()
  189.     } catch (error) {
  190.         return error
  191.     }
  192. }
  193.  
  194. const onEditRecruiterURL = async token => {
  195.     try {
  196.         const response = await fetch(`${BASEURL}/assinaturas/assinantes/hook/onEditRecruiterURL`,
  197.             {
  198.                 method: "POST",
  199.                 headers:
  200.                     { "Content-Type": "application/json"
  201.                     ,"Authorization": `Bearer ${token}`
  202.                     }
  203.             }
  204.         )
  205.         return await response.json()
  206.     }
  207.     catch (e) {
  208.         return error
  209.     }
  210. }
  211.  
  212.  
  213. export default
  214.     { upload
  215.     , login
  216.     , reautenticar
  217.     , getUserById
  218.     , getTrails
  219.     , getTrailById
  220.     , getQuizById
  221.     , updateUser
  222.     , updateDeviceToken
  223.     , recoverPassword
  224.     , recoverPasswordConfirm
  225.     , onEditRecruiterURL
  226.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement