diff options
| author | Jules Laplace <jules@okfoc.us> | 2016-10-06 17:08:38 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2016-10-06 17:08:38 -0400 |
| commit | d2299d24a23c9d0d835631b72e4f1d1974958f94 (patch) | |
| tree | 2133ec4d5701767d9fd8d51051eaea768e07629f /examples/lib/okpush/db.js | |
| parent | c8c0b465d9796b526d268ea0e641fd7ba00e44bb (diff) | |
js component
Diffstat (limited to 'examples/lib/okpush/db.js')
| -rw-r--r-- | examples/lib/okpush/db.js | 14 |
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 |
