Files
plutoapi-v2/src/models/twitch-highlight-marker/addHighlight/addHighlights.service.ts
T
Paddy b4d5bdd0b6
Jenkins Production Deployment
API-36: 🚑 Fixing critical issue with the amount of sql connections (!15)
Co-authored-by: Patrick Mueller <patrick@mueller-patrick.tech>
Reviewed-on: #15
Co-authored-by: Patrick Müller <patrick@plutodev.de>
Co-committed-by: Patrick Müller <patrick@plutodev.de>
2022-01-08 15:42:09 +00:00

29 lines
994 B
TypeScript

import * as dotenv from 'dotenv';
import {HighlightMarkerDB} from '../HighlightMarker.db';
dotenv.config();
/**
* Creates a new highlight entry in SQL
* @param req_body The request body
*/
export const createHighlightEntry = async (req_body: any) => {
let conn = HighlightMarkerDB.getConnection();
try {
const streamers = await conn.query('SELECT streamer_id FROM streamers WHERE username = ?', req_body.streamer);
let streamer_id: number = -1;
for (let row in streamers) {
if (row !== 'meta') {
streamer_id = streamers[row].streamer_id;
}
}
const params = [streamer_id, req_body.stream_id, req_body.description, req_body.timestamp, req_body.username, req_body.stream_game];
const rows = await conn.query('INSERT INTO highlights (streamer_id, stream_id, description, stream_timestamp, issuing_user, game) VALUES (?, ?, ?, ?, ?, ?)', params);
} catch (err) {
throw err;
}
};