add ability to update tasks, can pass additional fields to Model.sanitize at runtime

This commit is contained in:
Matteo Pagliazzi
2015-11-29 19:05:24 +01:00
parent 5291753841
commit 3002db3d75
5 changed files with 63 additions and 8 deletions

View File

@@ -42,9 +42,13 @@ TaskSchema.plugin(baseModel, {
timestamps: true,
});
export let TaskModel = mongoose.model('Task', TaskSchema);
// A list of additional fields that cannot be updated (but can be set on creation)
let noUpdate = ['_id', 'type'];
TaskSchema.statics.sanitizeUpdate = function sanitizeUpdate (updateObj) {
return TaskModel.sanitize(updateObj, noUpdate); // eslint-disable-line no-use-before-define
};
// TODO discriminators: it's very important to check that the options and plugins of the parent schema are used in the sub-schemas too
export let TaskModel = mongoose.model('Task', TaskSchema);
// habits and dailies shared fields
let habitDailySchema = () => {