-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetConfigByKey.js
65 lines (63 loc) · 1.53 KB
/
getConfigByKey.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const { query } = require("./dbClient");
const fetchConfigByKey = async (key) => {
try {
const res = await query(
`select * from la79y.public."GlobalConfigs" where key='${key}'`,
[]
);
console.log(res.rows);
return res.rows;
} catch (err) {
console.error("Error executing query", err.stack);
throw err;
}
};
const updateSessionToUsed = async (sessionId, username, resource) => {
try {
const res = await query(
`
update "Sessions"
set used = true
where id = '${sessionId}'
and username = '${username}'
and resource = '${resource}'
and is_streamer = false
and used = false;`,
[]
);
console.log(res.rows);
return res.rows;
} catch (err) {
console.error("Error executing query", err.stack);
throw err;
}
};
const fetchSessionIdByResourceAndUser = async (
sessionId,
username,
resource,
used
) => {
try {
const res = await query(
`
select * from "Sessions"
where id = '${sessionId}'
and username = '${username}'
and resource = '${resource}'
and is_streamer = false
and used = ${used}`,
[]
);
console.log(res.rows);
return res.rows;
} catch (err) {
console.error("Error executing query", err.stack);
throw err;
}
};
module.exports = {
fetchConfigByKey,
fetchSessionIdByResourceAndUser,
updateSessionToUsed,
}; // Export the function for use in other files