Mongoose 4.x (#9928)

* update mongoose to ^4.x

* another fix
This commit is contained in:
Matteo Pagliazzi
2018-02-02 16:37:36 +01:00
committed by GitHub
parent 389d6f18b4
commit 1fbdb7dbd0
8 changed files with 531 additions and 340 deletions

View File

@@ -54,6 +54,23 @@ export let TaskSchema = new Schema({
return !validator.isUUID(val);
},
msg: 'Task short names cannot be uuids.',
}, {
validator (alias) {
return new Promise((resolve, reject) => {
Task.findOne({ // eslint-disable-line no-use-before-define
_id: { $ne: this._id },
userId: this.userId,
alias,
}).exec().then((task) => {
let aliasAvailable = !task;
return aliasAvailable ? resolve() : reject();
}).catch(() => {
reject();
});
});
},
msg: 'Task alias already used on another task.',
}],
},
tags: [{
@@ -193,20 +210,6 @@ TaskSchema.methods.scoreChallengeTask = async function scoreChallengeTask (delta
export let Task = mongoose.model('Task', TaskSchema);
Task.schema.path('alias').validate(function valiateAliasNotTaken (alias, respond) {
Task.findOne({
_id: { $ne: this._id },
userId: this.userId,
alias,
}).exec().then((task) => {
let aliasAvailable = !task;
respond(aliasAvailable);
}).catch(() => {
respond(false);
});
}, 'Task alias already used on another task.');
// habits and dailies shared fields
let habitDailySchema = () => {
return {history: Array}; // [{date:Date, value:Number}], // this causes major performance problems