Files
freeplanet_serverside/server/models/todo.js
Paolo Arena db2a460594 - add: createPushSubscription :
'Subscribed to FreePlanet.app!',
  'You can now receive Notification and Messages.'
2019-02-05 18:17:44 +01:00

94 lines
1.5 KiB
JavaScript

var mongoose = require('mongoose');
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,
},
pos: {
type: Number,
},
category: {
type: String,
},
descr: {
type: String,
},
priority: {
type: Number,
},
completed: {
type: Boolean,
default: false
},
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,
},
modified: {
type: Boolean,
},
});
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 };