32 lines
972 B
TypeScript
32 lines
972 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 = await 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;
|
|
} finally {
|
|
// Return connection
|
|
await conn.end();
|
|
}
|
|
};
|