diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/okpush/db.js | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/okpush/db.js b/lib/okpush/db.js index 35a4c86e..4e6c2ee1 100644 --- a/lib/okpush/db.js +++ b/lib/okpush/db.js @@ -19,6 +19,7 @@ function init (config) { token: { type: 'String', required: true, + unique: true, }, channel: { type: 'String', @@ -51,9 +52,9 @@ function init (config) { } }) - PushToken = db.model('PushToken', pushTokenSchema) - Notification = db.model('Notification', notificationSchema) - Channel = db.model('Channel', channelSchema) + module.exports.PushToken = PushToken = db.model('PushToken', pushTokenSchema) + module.exports.Notification = Notification = db.model('Notification', notificationSchema) + module.exports.Channel = Channel = db.model('Channel', channelSchema) } function errorHandler (error) { @@ -74,6 +75,15 @@ function getAllIOSTokens (channel, cb) { return cb(null, items) }) } +function getAllAndroidTokens (channel, cb) { + PushToken.find({ channel: channel, platform: 'android' }, function (err, items) { + if (err) return cb(err, null) + var items = _.map(items, function (item) { + return item.token + }) + return cb(null, items) + }) +} function getAllTokens (channel, cb) { PushToken.find({ channel: channel }, function (err, items) { if (err) return cb(err, null) @@ -139,12 +149,13 @@ function getNotifications (cb) { /* wrap functions for some reason */ -module.exports = { +var exports = module.exports = { init: init, addToken: addToken, removeToken: removeToken, getAllTokens: getAllTokens, getAllIOSTokens: getAllIOSTokens, + getAllAndroidTokens: getAllAndroidTokens, getDeviceCount: getDeviceCount, addNotification: addNotification, getNotifications: getNotifications, |
