UNPKG

626 BJavaScriptView Raw
1"use strict";
2
3/**
4 * Return success status and payload as response.
5 *
6 * @param {Response} res use as res.success(...)
7 * @param {string|object} [message='Success'] success message to return
8 * @param {string} [audit=false] audit event type
9 * @param {string} [extra=undefined] extra audit payload which may help debug event
10 */
11function success(res, message = 'Success', audit = false, extra = undefined)
12{
13 if (audit)
14 {
15 res.audit(audit, message, extra);
16 }
17 if (typeof message === 'string')
18 {
19 message = {
20 success: message
21 };
22 }
23 res.status(200)
24 .json(message);
25}
26
27module.exports = success;