Skip to content

Instantly share code, notes, and snippets.

@TobyEalden
Last active March 3, 2017 09:28
Show Gist options
  • Save TobyEalden/5f850664ef6683c1f4e9a97ac124d91c to your computer and use it in GitHub Desktop.
Save TobyEalden/5f850664ef6683c1f4e9a97ac124d91c to your computer and use it in GitHub Desktop.
import {dataLoader, optionsWithError} from "../../../configs/app-data-loader";
import Home from "../components/home";
import {Meteor} from "meteor/meteor";
function dataMapper({
connectionManager,
setRegionId,
setUserName,
setGeoCentre,
setProjectionListId,
setLsoas,
setPopulationListId,
}, onData) {
if (connectionManager.isAuthenticated()) {
connectionManager.tdxApi.getDatasets({"schemaDefinition.basedOn": "Nquirerusers"}, null, null, (err, response) => {
if (err) onData(err);
else {
if (response.length === 0) onData(new Error("Failed to find valid login"));
else {
connectionManager.tdxApi.getDatasetData(response[0].id, null, null, null, (err, response) => {
if (err) onData(err);
else {
const userInfo = response.data[0];
setRegionId(userInfo.regionId);
setUserName(userInfo.userName);
setGeoCentre(userInfo.geoCentre);
setProjectionListId(userInfo.projectionListId);
setPopulationListId(userInfo.populationListId);
const pipeline = [
{
$match: {
parentId: userInfo.regionId,
childType: "LSOA11CD",
mappingType: "ons-mapping",
},
},
{
$group: {
_id: null,
id_array: {
$push: "$childId",
},
},
},
];
connectionManager.tdxApi.getAggregateData(Meteor.settings.public.mappingId, JSON.stringify(pipeline), {
limit: 5000,
}, (err, response) => {
if (err) onData(err);
else {
setLsoas(response.data[0].id_array);
onData(null, {userName: userInfo.userName});
}
});
}
});
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment