Migrate invalid Challenge IDs

This commit is contained in:
Rex Schrader
2016-02-10 15:18:48 -08:00
parent 0542845b10
commit 858546e3ec
3 changed files with 46 additions and 18 deletions

View File

@ -1462,7 +1462,7 @@
] ]
}, },
{ {
"id": "bg9997c9c79feddfaeb9bdef", "id": "56bbb991ad1ed5201cd392ca",
"title": "Access Array Data with Indexes", "title": "Access Array Data with Indexes",
"description": [ "description": [
"We can access the data inside arrays using <code>indexes</code>.", "We can access the data inside arrays using <code>indexes</code>.",
@ -1581,7 +1581,7 @@
"challengeType": 1 "challengeType": 1
}, },
{ {
"id": "bg9995c9c69feddfaeb9bdef", "id": "56bbb991ad1ed5201cd392cb",
"title": "Manipulate Arrays With push()", "title": "Manipulate Arrays With push()",
"description": [ "description": [
"An easy way to append data to the end of an array is via the <code>push()</code> function.", "An easy way to append data to the end of an array is via the <code>push()</code> function.",
@ -1621,7 +1621,7 @@
] ]
}, },
{ {
"id": "bg9994c9c69feddfaeb9bdef", "id": "56bbb991ad1ed5201cd392cc",
"title": "Manipulate Arrays With pop()", "title": "Manipulate Arrays With pop()",
"description": [ "description": [
"Another way to change the data in an array is with the <code>.pop()</code> function.", "Another way to change the data in an array is with the <code>.pop()</code> function.",
@ -1666,7 +1666,7 @@
] ]
}, },
{ {
"id": "bg9996c9c69feddfaeb9bdef", "id": "56bbb991ad1ed5201cd392cd",
"title": "Manipulate Arrays With shift()", "title": "Manipulate Arrays With shift()",
"description": [ "description": [
"<code>pop()</code> always removes the last element of an array. What if you want to remove the first?", "<code>pop()</code> always removes the last element of an array. What if you want to remove the first?",
@ -1708,7 +1708,7 @@
] ]
}, },
{ {
"id": "bg9997c9c69feddfaeb9bdef", "id": "56bbb991ad1ed5201cd392ce",
"title": "Manipulate Arrays With unshift()", "title": "Manipulate Arrays With unshift()",
"description": [ "description": [
"Not only can you <code>shift</code> elements off of the beginning of an array, you can also <code>unshift</code> elements to the beginning of an array i.e. add elements in front of the array.", "Not only can you <code>shift</code> elements off of the beginning of an array, you can also <code>unshift</code> elements to the beginning of an array i.e. add elements in front of the array.",
@ -1805,7 +1805,7 @@
"challengeType": 1 "challengeType": 1
}, },
{ {
"id": "bg9997c9c89feddfaeb9bdef", "id": "56bbb991ad1ed5201cd392cf",
"title": "Write Reusable JavaScript with Functions", "title": "Write Reusable JavaScript with Functions",
"description": [ "description": [
"In JavaScript, we can divide up our code into reusable parts called <dfn>functions</dfn>.", "In JavaScript, we can divide up our code into reusable parts called <dfn>functions</dfn>.",
@ -3314,7 +3314,7 @@
"challengeType": 1 "challengeType": 1
}, },
{ {
"id": "bg9998c9c99feddfaeb9bdef", "id": "56bbb991ad1ed5201cd392d0",
"title": "Build JavaScript Objects", "title": "Build JavaScript Objects",
"description": [ "description": [
"You may have heard the term <code>object</code> before.", "You may have heard the term <code>object</code> before.",
@ -3500,7 +3500,7 @@
"challengeType": 1 "challengeType": 1
}, },
{ {
"id": "bg9999c9c99feddfaeb9bdef", "id": "56bbb991ad1ed5201cd392d1",
"title": "Updating Object Properties", "title": "Updating Object Properties",
"description": [ "description": [
"After you've created a JavaScript object, you can update its properties at any time just like you would update any other variable. You can use either dot or bracket notation to update.", "After you've created a JavaScript object, you can update its properties at any time just like you would update any other variable. You can use either dot or bracket notation to update.",
@ -3565,7 +3565,7 @@
] ]
}, },
{ {
"id": "bg9999c9c99feedfaeb9bdef", "id": "56bbb991ad1ed5201cd392d2",
"title": "Add New Properties to a JavaScript Object", "title": "Add New Properties to a JavaScript Object",
"description": [ "description": [
"You can add new properties to existing JavaScript objects the same way you would modify them.", "You can add new properties to existing JavaScript objects the same way you would modify them.",
@ -3621,7 +3621,7 @@
] ]
}, },
{ {
"id": "bg9999c9c99fdddfaeb9bdef", "id": "56bbb991ad1ed5201cd392d3",
"title": "Delete Properties from a JavaScript Object", "title": "Delete Properties from a JavaScript Object",
"description": [ "description": [
"We can also delete properties from objects like this:", "We can also delete properties from objects like this:",

View File

@ -5,7 +5,7 @@
"helpRoom": "Help", "helpRoom": "Help",
"challenges": [ "challenges": [
{ {
"id": "bb000000000000000000001", "id": "56bbb991ad1ed5201cd392d4",
"title": "Trigger Click Events with jQuery", "title": "Trigger Click Events with jQuery",
"description": [ "description": [
"In this section, we'll learn how to get data from APIs. APIs - or Application Programming Interfaces - are tools that computers use to communicate with one another.", "In this section, we'll learn how to get data from APIs. APIs - or Application Programming Interfaces - are tools that computers use to communicate with one another.",
@ -63,13 +63,13 @@
"Nesta sessão, vamos aprender como obter dados de uma API. As APIS - Interface de Programação de Aplicativos - são ferramentas usadas pelos computadores para se comunicarem entre si.", "Nesta sessão, vamos aprender como obter dados de uma API. As APIS - Interface de Programação de Aplicativos - são ferramentas usadas pelos computadores para se comunicarem entre si.",
"Também aprenderemos como utilizar o HTML com os dados obtidos de uma API usando uma tecnologia chamada Ajax", "Também aprenderemos como utilizar o HTML com os dados obtidos de uma API usando uma tecnologia chamada Ajax",
"Em primeiro lugar, vamos revir o que faz a função <code>$(document).ready()</code>. Esta função faz com que todo o codigo que esteja dentro de seu escopo execute somente quando a nossa página tenha sido carregada.", "Em primeiro lugar, vamos revir o que faz a função <code>$(document).ready()</code>. Esta função faz com que todo o codigo que esteja dentro de seu escopo execute somente quando a nossa página tenha sido carregada.",
"Vamos fazer nosso butão \"Get message\" mudar o texto do elemento com a classe <code>message</code>.", "Vamos fazer nosso butão \"Get message\" mudar o texto do elemento com a classe <code>message</code>.",
"Antes de poder fazer isso, temos que implementar um <code>evento de clique</code> dentro da nossa função <code>$(document).ready()</code>, adicionando este código:", "Antes de poder fazer isso, temos que implementar um <code>evento de clique</code> dentro da nossa função <code>$(document).ready()</code>, adicionando este código:",
"<blockquote>$(\"#getMessage\").on(\"click\", function(){</br></br>});</blockquote>" "<blockquote>$(\"#getMessage\").on(\"click\", function(){</br></br>});</blockquote>"
] ]
}, },
{ {
"id": "bc000000000000000000001", "id": "56bbb991ad1ed5201cd392d5",
"title": "Change Text with Click Events", "title": "Change Text with Click Events",
"description": [ "description": [
"When our click event happens, we can use Ajax to update an HTML element.", "When our click event happens, we can use Ajax to update an HTML element.",
@ -128,7 +128,7 @@
] ]
}, },
{ {
"id": "bb000000000000000000002", "id": "56bbb991ad1ed5201cd392d6",
"title": "Get JSON with the jQuery getJSON Method", "title": "Get JSON with the jQuery getJSON Method",
"description": [ "description": [
"You can also request data from an external source. This is where APIs come into play.", "You can also request data from an external source. This is where APIs come into play.",
@ -209,7 +209,7 @@
] ]
}, },
{ {
"id": "bb000000000000000000003", "id": "56bbb991ad1ed5201cd392d7",
"title": "Convert JSON Data to HTML", "title": "Convert JSON Data to HTML",
"description": [ "description": [
"Now that we're getting data from a JSON API, let's display it in our HTML.", "Now that we're getting data from a JSON API, let's display it in our HTML.",
@ -283,7 +283,7 @@
] ]
}, },
{ {
"id": "bb000000000000000000004", "id": "56bbb991ad1ed5201cd392d8",
"title": "Render Images from Data Sources", "title": "Render Images from Data Sources",
"description": [ "description": [
"We've seen from the last two lessons that each object in our JSON array contains an <code>imageLink</code> key with a value that is the url of a cat's image.", "We've seen from the last two lessons that each object in our JSON array contains an <code>imageLink</code> key with a value that is the url of a cat's image.",
@ -361,7 +361,7 @@
] ]
}, },
{ {
"id": "bb000000000000000000005", "id": "56bbb991ad1ed5201cd392d9",
"title": "Prefilter JSON", "title": "Prefilter JSON",
"description": [ "description": [
"If we don't want to render every cat photo we get from our Free Code Camp's Cat Photo JSON API, we can pre-filter the json before we loop through it.", "If we don't want to render every cat photo we get from our Free Code Camp's Cat Photo JSON API, we can pre-filter the json before we loop through it.",
@ -440,7 +440,7 @@
] ]
}, },
{ {
"id": "bb000000000000000000006", "id": "56bbb991ad1ed5201cd392da",
"title": "Get Geo-location Data", "title": "Get Geo-location Data",
"description": [ "description": [
"Another cool thing we can do is access our user's current location. Every browser has a built in navigator that can give us this information.", "Another cool thing we can do is access our user's current location. Every browser has a built in navigator that can give us this information.",

View File

@ -15,6 +15,26 @@ const challengeTypes = {
waypoint: 0 waypoint: 0
}; };
const idMap = {
"bg9997c9c79feddfaeb9bdef": "56bbb991ad1ed5201cd392ca",
"bg9995c9c69feddfaeb9bdef": "56bbb991ad1ed5201cd392cb",
"bg9994c9c69feddfaeb9bdef": "56bbb991ad1ed5201cd392cc",
"bg9996c9c69feddfaeb9bdef": "56bbb991ad1ed5201cd392cd",
"bg9997c9c69feddfaeb9bdef": "56bbb991ad1ed5201cd392ce",
"bg9997c9c89feddfaeb9bdef": "56bbb991ad1ed5201cd392cf",
"bg9998c9c99feddfaeb9bdef": "56bbb991ad1ed5201cd392d0",
"bg9999c9c99feddfaeb9bdef": "56bbb991ad1ed5201cd392d1",
"bg9999c9c99feedfaeb9bdef": "56bbb991ad1ed5201cd392d2",
"bg9999c9c99fdddfaeb9bdef": "56bbb991ad1ed5201cd392d3",
"bb000000000000000000001": "56bbb991ad1ed5201cd392d4",
"bc000000000000000000001": "56bbb991ad1ed5201cd392d5",
"bb000000000000000000002": "56bbb991ad1ed5201cd392d6",
"bb000000000000000000003": "56bbb991ad1ed5201cd392d7",
"bb000000000000000000004": "56bbb991ad1ed5201cd392d8",
"bb000000000000000000005": "56bbb991ad1ed5201cd392d9",
"bb000000000000000000006": "56bbb991ad1ed5201cd392da"
};
const challengeTypeReg = /^(waypoint|hike|zipline|basejump)/i; const challengeTypeReg = /^(waypoint|hike|zipline|basejump)/i;
const challengeTypeRegWithColon = const challengeTypeRegWithColon =
/^(bonfire|checkpoint|waypoint|hike|zipline|basejump):\s+/i; /^(bonfire|checkpoint|waypoint|hike|zipline|basejump):\s+/i;
@ -51,6 +71,13 @@ function updateName(challenge) {
return challenge; return challenge;
} }
function updateId(challenge) {
if(idMap.hasOwnProperty(challenge.id)) {
challenge.id = idMap[challenge.id];
}
return challenge;
}
// buildChallengeMap( // buildChallengeMap(
// userId: String, // userId: String,
// completedChallenges: Object[], // completedChallenges: Object[],
@ -64,6 +91,7 @@ function buildChallengeMap(userId, completedChallenges = [], User) {
Scheduler.default Scheduler.default
) )
.filter(({ id, _id }) => ObjectID.isValid(id || _id)) .filter(({ id, _id }) => ObjectID.isValid(id || _id))
.map(updateId)
.map(updateName) .map(updateName)
.reduce((challengeMap, challenge) => { .reduce((challengeMap, challenge) => {
const id = challenge.id || challenge._id; const id = challenge.id || challenge._id;