- PUSH Notification
This commit is contained in:
@@ -1,20 +1,93 @@
|
||||
var mongoose = require('mongoose');
|
||||
|
||||
var Todo = mongoose.model('Todo', {
|
||||
text: {
|
||||
const _ = require('lodash');
|
||||
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
mongoose.set('debug', process.env.DEBUG);
|
||||
|
||||
var TodoSchema = new mongoose.Schema({
|
||||
userId: {
|
||||
type: String,
|
||||
required: true,
|
||||
minlength: 1,
|
||||
trim: true
|
||||
},
|
||||
pos: {
|
||||
type: Number,
|
||||
},
|
||||
category: {
|
||||
type: String,
|
||||
},
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
priority: {
|
||||
type: Number,
|
||||
},
|
||||
completed: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
completedAt: {
|
||||
created_at: {
|
||||
type: Date
|
||||
},
|
||||
modify_at: {
|
||||
type: Date
|
||||
},
|
||||
completed_at: {
|
||||
type: Date
|
||||
},
|
||||
expiring_at: {
|
||||
type: Date
|
||||
},
|
||||
enableExpiring: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
id_prev: {
|
||||
type: String,
|
||||
},
|
||||
id_next: {
|
||||
type: String,
|
||||
},
|
||||
progress: {
|
||||
type: Number,
|
||||
default: null
|
||||
}
|
||||
},
|
||||
modified: {
|
||||
type: Boolean,
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = {Todo};
|
||||
TodoSchema.methods.toJSON = function () {
|
||||
var todo = this;
|
||||
var todoObject = todo.toObject();
|
||||
|
||||
console.log(todoObject);
|
||||
|
||||
return _.pick(todoObject, ['_id', 'userId', 'pos', 'category', 'descr', 'priority', 'completed', 'created_at', 'modify_at',
|
||||
'completed_at', 'expiring_at', 'enableExpiring', 'id_prev', 'id_next', 'progress', 'modified']);
|
||||
};
|
||||
|
||||
|
||||
TodoSchema.statics.findAllByUserId = function (userId) {
|
||||
var Todo = this;
|
||||
|
||||
return Todo.find({
|
||||
'userId': userId,
|
||||
});
|
||||
};
|
||||
|
||||
TodoSchema.pre('save', function (next) {
|
||||
next();
|
||||
});
|
||||
|
||||
|
||||
var Todo = mongoose.model('Todos', TodoSchema);
|
||||
|
||||
module.exports = { Todo };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user