From d2299d24a23c9d0d835631b72e4f1d1974958f94 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 6 Oct 2016 17:08:38 -0400 Subject: js component --- examples/lib/okpush/db.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'examples/lib/okpush/db.js') 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 -- cgit v1.2.3-70-g09d2