Skip to content

Commit dfdc64b

Browse files
committed
fix: clean notification body for retro-compatibility with notify
1 parent 267b8de commit dfdc64b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

api/src/notifications/router.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ router.post('', async (req, res, next) => {
7070
res.status(201).json(body)
7171
} else {
7272
debug('pushing a notification with a recipient', req.body)
73+
74+
// small cleanup of deprecated stuff for retro-compatibility with notify
75+
// TODO should we manage more properly i18n of notification object ?
76+
// the problem is that locale is defined on a subscription and we don't have one here.. user level setting ?
77+
if (typeof req.body.title === 'object') req.body.title = req.body.title[config.i18n.defaultLocale]
78+
if (typeof req.body.body === 'object') req.body.body = req.body.body[config.i18n.defaultLocale]
79+
if (typeof req.body.htmlBody === 'object') req.body.htmlBody = req.body.htmlBody[config.i18n.defaultLocale]
80+
if (req.body.visibility) delete req.body.visibility
81+
7382
const { body } = notificationsPostReq.returnValid(req, { name: 'req' })
7483
const notification: Notification = {
7584
...body,

0 commit comments

Comments
 (0)