fix for Report API CORS

pull/29/head
Matthew 2020-10-19 19:24:49 -04:00
parent f1a28fa171
commit 65ec451e4e
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
1 changed files with 3 additions and 0 deletions

View File

@ -13,6 +13,7 @@ export default class Report extends Route {
public bind() { public bind() {
this.router.post('/hard', async (req, res) => { this.router.post('/hard', async (req, res) => {
try { try {
res.setHeader('Access-Control-Allow-Origin', '*');
if (!req.headers.authorization) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED }); if (!req.headers.authorization) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
if (!req.body.pin || !req.body.userID || !req.body.reason) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR, message: this.constants.messages.CLIENT_ERROR }); if (!req.body.pin || !req.body.userID || !req.body.reason) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR, message: this.constants.messages.CLIENT_ERROR });
if (req.body.reason?.length < 1) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR, message: this.constants.codes.CLIENT_ERROR }); if (req.body.reason?.length < 1) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR, message: this.constants.codes.CLIENT_ERROR });
@ -115,6 +116,7 @@ export default class Report extends Route {
this.router.post('/v2/soft', async (req, res) => { this.router.post('/v2/soft', async (req, res) => {
try { try {
res.setHeader('Access-Control-Allow-Origin', '*');
if (!req.headers.authorization) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED }); if (!req.headers.authorization) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
if (!req.body.userID) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR, message: this.constants.messages.CLIENT_ERROR }); if (!req.body.userID) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR, message: this.constants.messages.CLIENT_ERROR });
@ -196,6 +198,7 @@ export default class Report extends Route {
this.router.post('/soft', async (req, res) => { this.router.post('/soft', async (req, res) => {
try { try {
res.setHeader('Access-Control-Allow-Origin', '*');
if (!req.headers.authorization) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED }); if (!req.headers.authorization) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
if (!req.body.pin || !req.body.userID) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR, message: this.constants.messages.CLIENT_ERROR }); if (!req.body.pin || !req.body.userID) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR, message: this.constants.messages.CLIENT_ERROR });