- PUSH Notification
This commit is contained in:
22
server/models/subscribers.js
Normal file
22
server/models/subscribers.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
|
||||
const SubscriberSchema = new Schema({
|
||||
endpoint: String,
|
||||
keys: Schema.Types.Mixed,
|
||||
createDate: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
}
|
||||
});
|
||||
|
||||
mongoose.model('subscribers', SubscriberSchema);
|
||||
@@ -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 };
|
||||
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
var bcrypt = require('bcrypt');
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
const validator = require('validator');
|
||||
const jwt = require('jsonwebtoken');
|
||||
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 UserSchema = new mongoose.Schema({
|
||||
userId: {
|
||||
type: String,
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
required: true,
|
||||
@@ -72,7 +78,7 @@ UserSchema.methods.toJSON = function () {
|
||||
var user = this;
|
||||
var userObject = user.toObject();
|
||||
|
||||
return _.pick(userObject, ['_id', 'email', 'verified_email', 'username']);
|
||||
return _.pick(userObject, ['_id', 'email', 'verified_email', 'username', 'userId']);
|
||||
};
|
||||
|
||||
UserSchema.methods.generateAuthToken = function () {
|
||||
|
||||
Reference in New Issue
Block a user