Proof of concept of a kanban style application.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
624 B
Raw

const mongoose=require("mongoose");
const validatorId=require('mongoose-id-validator');
var taskSchema=new mongoose.Schema({
name:{ type: String, required: true },
description:{ type: String, default:"" },
parent:{ type: mongoose.Schema.Types.ObjectId, ref: 'Task' }
});
taskSchema.plugin(validatorId);
taskSchema.pre("findOneAndUpdate",function(next){
if(
this._update
&& this._update.hasOwnProperty("parent")
&& this._update.parent.toString()===this._conditions._id.toString()
){
next(new Error("parent must be different of _id."));
}else{
next();
}
});
module.exports=mongoose.model("Task",taskSchema);