- 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,39 @@
|
||||
import * as dotenv from 'dotenv';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const mariadb = require('mariadb');
|
||||
const pool = mariadb.createPool({
|
||||
host: process.env.DB_HOST,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.TWITCH_HIGHLIGHTS_DATABASE,
|
||||
connectionLimit: 5
|
||||
});
|
||||
|
||||
export const createHighlightEntry = async (req_body: any) => {
|
||||
let conn;
|
||||
let price: any;
|
||||
try {
|
||||
conn = await pool.getConnection();
|
||||
|
||||
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 {
|
||||
if (conn) {
|
||||
conn.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user