Files
habitica/website/server/controllers/api-v4/bug-report.js
Phillip Thelen f8d315ff6e Upgrade to mongoose 7 (#14971)
* remove some unused dependencies

* update mongoose version

* make common tests pass

* Make unit tests pass

* make api v3 integration tests pass

* fix lint issues

* fix issue with package-lock

* fix(lint): we don't need no .js

* fix(lint): update to latest config-habitrpg

* chore(npm): update package locks

* fix(test): replace deprecated fn

* chore(package): update eslint-habitrpg again

* fix(lint): server linting

* fix(lint): client linting

* fix(client): correct mangled common imports

* chore(npm): update package-locks

* fix(lint): punctuation, module

---------

Co-authored-by: SabreCat <sabrecat@gmail.com>
Co-authored-by: SabreCat <sabe@habitica.com>
2024-01-16 15:18:47 -06:00

52 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, question } = req.body;
const { user } = res.locals;
const BROWSER_UA = req.get('User-Agent');
const {
emailData, sendMailResult,
} = bugReportLogic(user, email, message, BROWSER_UA, question);
res.status(200).send({
ok: true,
emailData,
sendMailResult,
});
},
};
export default api;