fix(cert-settings): Uncouple Cert-Settings from dashedName's

This commit is contained in:
Stuart Taylor
2018-03-05 14:15:30 +00:00
parent 15473616c9
commit 6301411673
6 changed files with 148 additions and 192 deletions

View File

@ -9,7 +9,6 @@ import loopback from 'loopback';
import _ from 'lodash';
import { themes } from '../utils/themes';
import { dasherize } from '../../server/utils';
import { saveUser, observeMethod } from '../../server/utils/rx.js';
import { blacklistedUsernames } from '../../server/utils/constants.js';
import { wrapHandledError } from '../../server/utils/create-handled-error.js';
@ -43,28 +42,25 @@ function destroyAll(id, Model) {
}
function buildChallengeMapUpdate(challengeMap, project) {
const key = Object.keys(project)[0];
const solutions = project[key];
console.log(solutions);
const currentChallengeMap = { ...challengeMap };
const { nameToIdMap } = _.values(project)[0];
const incomingUpdate = _.pickBy(
_.omit(_.values(project)[0], [ 'id', 'nameToIdMap' ]),
Boolean
const currentCompletedProjects = _.pick(
currentChallengeMap,
Object.keys(solutions)
);
const currentCompletedProjects = _.pick(challengeMap, _.values(nameToIdMap));
const now = Date.now();
const update = Object.keys(incomingUpdate).reduce((update, current) => {
const dashedName = dasherize(current)
.replace('java-script', 'javascript')
.replace('metric-imperial', 'metricimperial');
const currentId = nameToIdMap[dashedName];
const update = Object.keys(solutions).reduce((update, currentId) => {
if (
currentId in currentCompletedProjects &&
currentCompletedProjects[currentId].solution !== incomingUpdate[current]
currentCompletedProjects[currentId].solution !== solutions[currentId]
) {
return {
...update,
[currentId]: {
...currentCompletedProjects[currentId],
solution: incomingUpdate[current],
solution: solutions[currentId],
numOfAttempts: currentCompletedProjects[currentId].numOfAttempts + 1
}
};
@ -74,7 +70,7 @@ function buildChallengeMapUpdate(challengeMap, project) {
...update,
[currentId]: {
id: currentId,
solution: incomingUpdate[current],
solution: solutions[currentId],
challengeType: 3,
completedDate: now,
numOfAttempts: 1