Skip to content

Instantly share code, notes, and snippets.

@peerasak-u
Last active April 9, 2020 03:52
Show Gist options
  • Save peerasak-u/dd29c66c2b1445117a28b1125e90bd79 to your computer and use it in GitHub Desktop.
Save peerasak-u/dd29c66c2b1445117a28b1125e90bd79 to your computer and use it in GitHub Desktop.
const axios = require('axios');
const fetchState = async (projectId) => {
let result = await axios(
`http://167.99.72.166:3800/projects/${projectId}/state`,
);
return result.data;
};
const fetchSummary = async (projectId, status) => {
let result = await axios(
`http://167.99.72.166:3800/projects/${projectId}/${status}/summary`,
);
let pods = result.data.pod.filter((pod) => pod.state);
return pods;
};
const run = async () => {
const states = await fetchState(2);
const statuses = ['REWORK', 'COMPLETE'];
const fetchPromise = statuses.map((status) => fetchSummary(2, status));
try {
let promiseResult = await Promise.all(fetchPromise);
let pods = promiseResult.flat();
let summary = states.map((state) => {
return {
stateTitle: state,
completeActual: pods.filter(
(pod) => pod.state === state && pod.status === 'complete',
).length,
reworkActual: pods.filter(
(pod) => pod.state === state && pod.status === 'rework',
).length,
};
});
console.log(summary);
} catch (error) {
console.error(error);
}
};
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment