overleaf/services/web/app/src/Features/Announcements/AnnouncementsController.js
Alasdair Smith 0ca81de78c Merge pull request #1717 from overleaf/as-decaffeinate-backend
Decaffeinate backend

GitOrigin-RevId: 4ca9f94fc809cab6f47cec8254cacaf1bb3806fa
2019-05-29 09:32:21 +00:00

59 lines
1.6 KiB
JavaScript

/* eslint-disable
max-len,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const AnnouncementsHandler = require('./AnnouncementsHandler')
const AuthenticationController = require('../Authentication/AuthenticationController')
const logger = require('logger-sharelatex')
const settings = require('settings-sharelatex')
module.exports = {
getUndreadAnnouncements(req, res, next) {
if (
__guard__(
__guard__(
settings != null ? settings.apis : undefined,
x1 => x1.analytics
),
x => x.url
) == null ||
settings.apis.blog.url == null
) {
return res.json([])
}
const user = AuthenticationController.getSessionUser(req)
logger.log(
{ user_id: user != null ? user._id : undefined },
'getting unread announcements'
)
return AnnouncementsHandler.getUnreadAnnouncements(user, function(
err,
announcements
) {
if (err != null) {
logger.err(
{ err, user_id: user._id },
'unable to get unread announcements'
)
return next(err)
} else {
return res.json(announcements)
}
})
}
}
function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null
? transform(value)
: undefined
}