- Also did some refactoring for cleaner code Co-authored-by: Patrick Müller <patrick@mueller-patrick.tech> Reviewed-on: #2 Co-authored-by: Patrick Müller <patrick@plutodev.de> Co-committed-by: Patrick Müller <patrick@plutodev.de>
This commit was merged in pull request #2.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Required External Modules and Interfaces
|
||||
*/
|
||||
import express, {Request, Response} from 'express';
|
||||
import * as AddHighlightService from "./addHighlights.service";
|
||||
|
||||
/**
|
||||
* Router Definition
|
||||
*/
|
||||
export const addHighlightRouter = express.Router();
|
||||
|
||||
addHighlightRouter.get('/', (req: Request, res: Response) => {
|
||||
try {
|
||||
res.status(200).send(`GET endpoint not defined.`);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
})
|
||||
|
||||
addHighlightRouter.post('/', (req: Request, res: Response) => {
|
||||
try {
|
||||
// Check input params
|
||||
const body = req.body;
|
||||
|
||||
if(body.access_key !== process.env.TWITCH_HIGHLIGHTS_ACCESS_KEY){
|
||||
// Unauthorized, return error
|
||||
res.type('application/json');
|
||||
res.status(403).send('{"status": "error", "description": "Unauthorized."}');
|
||||
} else if(!body.streamer || !body.stream_id || !body.stream_game || !body.timestamp || !body.description || !body.username){
|
||||
// Missing params, return error
|
||||
res.type('application/json');
|
||||
res.status(400).send('{"status": "error", "description": "Missing parameters."}');
|
||||
} else {
|
||||
// Everything fine, return success
|
||||
AddHighlightService.createHighlightEntry(body);
|
||||
|
||||
res.type('application/json');
|
||||
res.status(200).send('{"status": "success", "description": ""}');
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user