Skip to content

Commit

Permalink
move getMDNLinks func to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Berkeley Martinez authored and Berkeley Martinez committed Jun 19, 2015
1 parent adbbbf3 commit 9385684
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
20 changes: 3 additions & 17 deletions server/boot/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,13 @@

var R = require('ramda'),
utils = require('../utils'),
userMigration = require('../utils/middleware').userMigration,
MDNlinks = require('../../seed/bonfireMDNlinks');
userMigration = require('../utils/middleware').userMigration;

var challengeMapWithNames = utils.getChallengeMapWithNames();
var challengeMapWithIds = utils.getChallengeMapWithIds();
var challengeMapWithDashedNames = utils.getChallengeMapWithDashedNames();


function getMDNlinks(links) {
// takes in an array of links, which are strings
var populatedLinks = [];

// for each key value, push the corresponding link
// from the MDNlinks object into a new array
if (links) {
links.forEach(function (value) {
populatedLinks.push(MDNlinks[value]);
});
}
return populatedLinks;
}
var getMDNLinks = utils.getMDNLinks;

module.exports = function(app) {
var router = app.loopback.Router();
Expand Down Expand Up @@ -295,7 +281,7 @@ module.exports = function(app) {
bonfires: challenge,
challengeId: challenge.id,
MDNkeys: challenge.MDNlinks,
MDNlinks: getMDNlinks(challenge.MDNlinks),
MDNlinks: getMDNLinks(challenge.MDNlinks),
challengeType: challenge.challengeType
});
}
Expand Down
16 changes: 15 additions & 1 deletion server/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var path = require('path'),
fs = require('fs'),


MDNlinks = require('../../seed/bonfireMDNlinks'),
resources = require('./resources.json'),
nonprofits = require('../../seed/nonprofits.json'),
fieldGuides = require('../../seed/field-guides.json');
Expand All @@ -16,7 +17,7 @@ var path = require('path'),
*/
var allFieldGuideIds, allFieldGuideNames, allNonprofitNames,
challengeMap, challengeMapForDisplay, challengeMapWithIds,
challengeMapWithNames, allChallengeIds, allChallenges,
challengeMapWithNames, allChallengeIds,
challengeMapWithDashedNames;

/**
Expand Down Expand Up @@ -216,5 +217,18 @@ module.exports = {
}
});
})();
},

getMDNLinks: function(links) {
if (!links) {
return [];
}
// takes in an array of links, which are strings

// for each key value, push the corresponding link
// from the MDNlinks object into a new array
return links.map(function(value) {
return MDNlinks[value];
});
}
};

0 comments on commit 9385684

Please sign in to comment.