Skip to content

Instantly share code, notes, and snippets.

@aaronmcadam
Last active July 1, 2016 13:33
Show Gist options
  • Save aaronmcadam/97bb74bfd68ca6a56b82ce3ccdd320d1 to your computer and use it in GitHub Desktop.
Save aaronmcadam/97bb74bfd68ca6a56b82ce3ccdd320d1 to your computer and use it in GitHub Desktop.
import express from 'express';
import fetchAttributes from '../services/attributes';
/* eslint new-cap: "off" */
const router = express.Router();
router.route('/tasks/:taskId/attributes')
.get((req, res) => {
fetchAttributes(req.params.taskId).then(responses => res.json(responses));
});
export default router;
import R from 'ramda';
import callBizApi from './callBizApi';
import extractAttributes from '../util/extractAttributes';
import sumAttributes from '../util/sumAttributes';
import averageAttributes from '../util/averageAttributes';
const fetchAttributes = taskId => (
new Promise(resolve => (
callBizApi([`/tasks/${taskId}/responses`, `/tasks/${taskId}/questions`])
.then(mapAttributes)
.then(resolve)
))
);
export const mapAttributes = R.compose(
averageAttributes,
sumAttributes,
extractAttributes
);
export default fetchAttributes;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment