Browse Source

fix: api calls

master
Pierre-Louis Guhur 1 year ago
parent
commit
9226f699ae
  1. 16
      pages/result/[pid]/[[...tid]].jsx
  2. 5
      services/api.js

16
pages/result/[pid]/[[...tid]].jsx

@ -26,17 +26,15 @@ export async function getServerSideProps({ query, locale }) {
const [res, details, translations] = await Promise.all([
getResults(
pid,
(res) => {
ok: true, res;
},
(err) => ({ ok: false, err })
(res) => ({ ok: true, res }),
(err) => {
return { ok: false, err: "Unknown error" };
}
),
getDetails(
pid,
(res) => {
ok: true, res;
},
(err) => ({ ok: false, err })
(res) => ({ ok: true, ...res }),
(err) => ({ ok: false, err: "Unknown error" })
),
serverSideTranslations(locale, [], config),
]);
@ -52,7 +50,7 @@ export async function getServerSideProps({ query, locale }) {
props: {
title: details.title,
numGrades: details.num_grades,
candidates: res,
candidates: res.res,
pid: pid,
...translations,
},

5
services/api.js

@ -127,8 +127,7 @@ const getResults = (pid, successCallback, failureCallback) => {
return response.json();
})
.then(successCallback || ((res) => res))
.catch((err) => err)
.then(failureCallback || console.log);
.catch(failureCallback || ((err) => err));
};
const getDetails = (pid, successCallback, failureCallback) => {
@ -148,7 +147,7 @@ const getDetails = (pid, successCallback, failureCallback) => {
return response.json();
})
.then(successCallback || ((res) => res))
.catch(failureCallback || console.log);
.catch(failureCallback || ((err) => err));
};
const castBallot = (judgments, pid, token, callbackSuccess, callbackError) => {

Loading…
Cancel
Save