mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
* WIP: report a bug api/ui * fix lint * add USER_USERNAME * extend sendTxn tests / checks + fix bug report email * fix lint * add more checks to sendTxn - fix bug-report variables * fix lint / ci * fix test: reset email config url * fix test stub * fix tests * refactor the variables checks * lint. * move bug-report page as a modal * send user_email to the email * show true/false instead 1/0 * fix issues * fix footer report bug email if not logged in * fix styles/margins * prefill user's email * show facebook email if local email not existing * bugReportSuccessModal.vue * add BROWSER_UA to mail properties * extract bugReportLogic to its own lib file for unit test * test api validators * fix lint
54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
import { authWithHeaders } from '../../middlewares/auth';
|
|
import { bugReportLogic } from '../../libs/bug-report';
|
|
|
|
const api = {};
|
|
|
|
/**
|
|
* @api {post} /api/v4/bug-report Report an issue
|
|
* @apiName BugReport
|
|
* @apiGroup BugReport
|
|
* @apiDescription This POST method is used to send bug reports from the Website.
|
|
* Since it needs the Users Data, it requires authentication.
|
|
*
|
|
* @apiParam (Body) {String} message Bug Report Message to sent
|
|
* @apiParam (Body) {String} email User Email
|
|
*
|
|
* @apiSuccess {Object} data Result of this bug report
|
|
* @apiSuccess {Boolean} data.ok Status of this report
|
|
* @apiSuccess {String} data.message Status of this report
|
|
*
|
|
* @apiError (400) {BadRequest} emptyReportBugMessage The report message is missing.
|
|
* @apiUse UserNotFound
|
|
*/
|
|
api.bugReport = {
|
|
method: 'POST',
|
|
url: '/bug-report',
|
|
middlewares: [authWithHeaders()],
|
|
async handler (req, res) {
|
|
req.checkBody('message', res.t('emptyReportBugMessage')).notEmpty();
|
|
req.checkBody('email', res.t('missingEmail')).notEmpty();
|
|
req.checkBody('email', res.t('notAnEmail')).isEmail();
|
|
|
|
const validationErrors = req.validationErrors();
|
|
if (validationErrors) throw validationErrors;
|
|
|
|
const { message, email } = req.body;
|
|
const { user } = res.locals;
|
|
const BROWSER_UA = req.get('User-Agent');
|
|
|
|
const {
|
|
emailData, sendMailResult,
|
|
} = bugReportLogic(
|
|
user, email, message, BROWSER_UA,
|
|
);
|
|
|
|
res.status(200).send({
|
|
ok: true,
|
|
emailData,
|
|
sendMailResult,
|
|
});
|
|
},
|
|
};
|
|
|
|
export default api;
|