summaryrefslogtreecommitdiff
path: root/examples/lib/okpush/db.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-10-06 17:08:38 -0400
committerJules Laplace <jules@okfoc.us>2016-10-06 17:08:38 -0400
commitd2299d24a23c9d0d835631b72e4f1d1974958f94 (patch)
tree2133ec4d5701767d9fd8d51051eaea768e07629f /examples/lib/okpush/db.js
parentc8c0b465d9796b526d268ea0e641fd7ba00e44bb (diff)
js component
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