summaryrefslogtreecommitdiff
path: root/examples/lib/okpush/db.js
diff options
context:
space:
mode:
Diffstat (limited to 'examples/lib/okpush/db.js')
-rw-r--r--examples/lib/okpush/db.js14
1 files changed, 10 insertions, 4 deletions
diff --git a/examples/lib/okpush/db.js b/examples/lib/okpush/db.js
index 75beb65..83a6ebc 100644
--- a/examples/lib/okpush/db.js
+++ b/examples/lib/okpush/db.js
@@ -3,6 +3,8 @@ var findOrCreate = require('mongoose-findorcreate')
var _ = require('lodash')
var db, PushToken
+mongoose.Promise = require('bluebird')
+
function init (config) {
db = mongoose.connect(config.mongodbUrl)
mongoose.connection.on('error', errorHandler)
@@ -52,20 +54,23 @@ function getAllDevices (cb) {
}
function removeDevice () {
PushToken.remove({token: token}, function (err) {
- if (err) console.log(err)
+ if (err) console.log(err)
})
}
function removeDevices (tokens) {
- PushAssociation.remove({token: {$in: tokens}}, function (err) {
+ PushToken.remove({token: {$in: tokens}}, function (err) {
if (err) console.log(err)
})
}
+function getDeviceCount (cb) {
+ PushToken.count({}, cb);
+}
/* notifications */
function updateNotification (key, cb) {
var now = new Date
- Notification.findOrCreate({key: key}, {last_push: now}, function(err, note, created){
+ Notification.findOrCreate({key: key}, {last_push: now}, function(err, note, created) {
if (err) {
console.error("Error finding/creating notification", err)
cb(err, false)
@@ -74,8 +79,8 @@ function updateNotification (key, cb) {
else if (! created) {
note.last_push = now
note.save()
- cb(null, note)
}
+ console.log(note, created)
cb(null, note)
})
}
@@ -113,6 +118,7 @@ module.exports = {
getAllDevices: getAllDevices,
removeDevice: removeDevice,
removeDevices: removeDevices,
+ getDeviceCount: getDeviceCount,
updateNotification: updateNotification,
getNotifications: getNotifications,
} \ No newline at end of file