From 9dba1c0ed884af905d208fb30fc84c33f5e80e6a Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 2 Mar 2017 22:19:11 +0100 Subject: db --- lib/okpush/db.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'lib') 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, -- cgit v1.2.3-70-g09d2