Last active
April 9, 2020 03:52
-
-
Save peerasak-u/dd29c66c2b1445117a28b1125e90bd79 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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