chore: preparing for the move

This commit is contained in:
Mrugesh Mohapatra
2018-09-27 12:36:41 +05:30
parent 5272862733
commit 67929d80ff
402 changed files with 0 additions and 0 deletions

24
curriculum/mongoIds.js Normal file
View File

@ -0,0 +1,24 @@
import _ from 'lodash';
import { isMongoId } from 'validator';
class MongoIds {
constructor() {
this.knownIds = [];
}
check(id, title) {
if (!isMongoId(id)) {
throw new Error(`Expected a valid ObjectId for ${title}, but got ${id}`);
}
const idIndex = _.findIndex(this.knownIds, existing => id === existing);
if (idIndex !== -1) {
throw new Error(`
All challenges must have a unique id.
The id for ${title} is already assigned
`);
}
this.knownIds = [ ...this.knownIds, id ];
}
}
export default MongoIds;