summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2017-02-16 18:32:08 +0100
committerJules Laplace <jules@okfoc.us>2017-02-16 18:32:08 +0100
commitd3d195470caef02891de58ed25b92a02c088c37d (patch)
treeaf3531e9efe2fe32407b7bde4fc1828e60564b98 /lib
parentf40e2286faef696c25a81c04635aaf737606a39a (diff)
routes
Diffstat (limited to 'lib')
-rw-r--r--lib/okpush/db.js15
-rw-r--r--lib/okpush/index.js16
2 files changed, 15 insertions, 16 deletions
diff --git a/lib/okpush/db.js b/lib/okpush/db.js
index 844bccae..ad18b7b3 100644
--- a/lib/okpush/db.js
+++ b/lib/okpush/db.js
@@ -10,7 +10,7 @@ function init (config) {
mongoose.connection.on('error', errorHandler)
var pushTokenSchema = new db.Schema({
- type: {
+ platform: {
type: 'String',
required: true,
lowercase: true,
@@ -62,13 +62,8 @@ function errorHandler (error) {
/* devices / tokens */
-function addToken (deviceType, token, channel) {
- var pushItem = new PushToken({
- type: deviceType,
- token: token,
- channel: channel
- })
- pushItem.save()
+function addToken (data) {
+ return new PushToken(data).save()
}
function getAllTokens (channel, cb) {
PushToken.find({ channel: channel }, function (err, items) {
@@ -79,8 +74,8 @@ function getAllTokens (channel, cb) {
return cb(null, items)
})
}
-function removeToken (token, channel) {
- PushToken.find({ token: token, channel: channel }).remove().exec()
+function removeToken (data) {
+ PushToken.find(data).remove().exec()
}
function getDeviceCount (channel, cb) {
PushToken.count({ channel: channel }, cb)
diff --git a/lib/okpush/index.js b/lib/okpush/index.js
index a9ba12eb..a509c891 100644
--- a/lib/okpush/index.js
+++ b/lib/okpush/index.js
@@ -69,6 +69,7 @@ function OKPush (options) {
// pass in admin middleware!
router.get('/admin', function (req, res) {
+ // change this to get notification counts for each channel
db.getNotifications(function(err, notes){
db.getDeviceCount(function(err, count){
var data = {
@@ -100,14 +101,17 @@ function OKPush (options) {
// should work without middleware
router.post('/add', function (req, res) {
- // add a key
- db.
- registrationId: localStorage.getItem("yoox.registrationId"),
- channel: channel,
- platform,
+ db.addToken({
+ token: req.body.registrationId,
+ channel: req.body.channel,
+ platform: req.body.platform,
+ })
})
router.post('/remove', function (req, res) {
- // remove a key
+ db.removeToken({
+ token: req.body.registrationId,
+ channel: req.body.channel,
+ })
})
this._router = router