Merge branch 'hotfix/21.56.9' into master
[gitter.git] / server / api / v1 / apn.js
blob652d553a6db0bd0fe486335f3ff3d0337b8deb8d
1 'use strict';
3 var env = require('gitter-web-env');
4 var winston = env.logger;
5 var pushNotificationService = require('gitter-web-push-notifications');
7 module.exports = function(req, res, next) {
8   var deviceId = req.body.deviceId;
9   var deviceName = req.body.deviceName;
10   var deviceType = req.body.deviceType;
11   var deviceToken = new Buffer(req.body.deviceToken, 'base64');
12   var appVersion = req.body.version || null;
13   var appBuild = req.body.build || null;
15   winston.info('APN device registration', {
16     deviceId: deviceId,
17     deviceName: deviceName,
18     deviceType: deviceType
19   });
21   return pushNotificationService
22     .registerDevice(deviceId, deviceType, deviceToken, deviceName, appVersion, appBuild)
23     .then(function() {
24       res.send({ success: true });
25     })
26     .catch(next);