From 938568454e94f7ed14c9bab369904cec73493237 Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Fri, 19 Jun 2015 14:32:17 -0700 Subject: [PATCH] move getMDNLinks func to utils --- server/boot/challenge.js | 20 +++----------------- server/utils/index.js | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/server/boot/challenge.js b/server/boot/challenge.js index dfa2f98ef2..77346d15fa 100644 --- a/server/boot/challenge.js +++ b/server/boot/challenge.js @@ -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(); @@ -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 }); } diff --git a/server/utils/index.js b/server/utils/index.js index 6b7b342e56..bff016241c 100644 --- a/server/utils/index.js +++ b/server/utils/index.js @@ -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'); @@ -16,7 +17,7 @@ var path = require('path'), */ var allFieldGuideIds, allFieldGuideNames, allNonprofitNames, challengeMap, challengeMapForDisplay, challengeMapWithIds, - challengeMapWithNames, allChallengeIds, allChallenges, + challengeMapWithNames, allChallengeIds, challengeMapWithDashedNames; /** @@ -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]; + }); } };