diff options
| author | Jules Laplace <jules@okfoc.us> | 2017-03-02 22:19:11 +0100 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2017-03-02 22:19:11 +0100 |
| commit | 9dba1c0ed884af905d208fb30fc84c33f5e80e6a (patch) | |
| tree | 97a0b8c36734dfdbf5ec5ec39f75651c0fa05b62 /lib | |
| parent | 65604d724e48856f8301390426a2bd81c5d62aba (diff) | |
db
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, |
