89 lines
1.9 KiB
JavaScript
89 lines
1.9 KiB
JavaScript
const sql = require('./mysql')
|
|
|
|
function getUserAccounts(user) {
|
|
let data = sql.query(`SELECT
|
|
userAccounts.username,
|
|
userAccounts.stream,
|
|
userAccounts.streamURL,
|
|
userAccounts.expiaryDate,
|
|
userAccounts.password
|
|
FROM users
|
|
INNER JOIN userAccounts
|
|
ON users.id = userAccounts.userID
|
|
WHERE users.id = '${user}'`)
|
|
// console.log(data)
|
|
if (data.length == 0) {
|
|
return 'User Not Found'
|
|
} else {
|
|
return data
|
|
}
|
|
}
|
|
|
|
function getUserAccountsCheck(user) {
|
|
let data = sql.query(`SELECT
|
|
userAccounts.username,
|
|
userAccounts.stream,
|
|
userAccounts.streamURL,
|
|
userAccounts.expiaryDate,
|
|
userAccounts.password
|
|
FROM users
|
|
INNER JOIN userAccounts
|
|
ON users.id = userAccounts.userID
|
|
WHERE users.id = '${user}'`)
|
|
// console.log(data)
|
|
if (data.length == 0) {
|
|
return 'User Not Found'
|
|
} else {
|
|
return data
|
|
}
|
|
}
|
|
|
|
function getAllUserAccounts() {
|
|
let data = sql.query(`SELECT
|
|
userAccounts.username,
|
|
userAccounts.password,
|
|
userAccounts.expiaryDate,
|
|
userAccounts.stream
|
|
FROM userAccounts
|
|
WHERE userAccounts.expiaryDate != '0'
|
|
ORDER BY userAccounts.id DESC
|
|
`)
|
|
// console.log(data)
|
|
if (data.length == 0) {
|
|
return 'User Not Found'
|
|
} else {
|
|
return data
|
|
}
|
|
}
|
|
|
|
function getAllUniqueAccounts() {
|
|
let data = sql.query(`SELECT DISTINCT(userAccounts.stream), userAccounts.username, userAccounts.password, userAccounts.stream FROM userAccounts
|
|
WHERE userAccounts.expiaryDate != '0'
|
|
GROUP BY userAccounts.stream;`)
|
|
if (data.length == 0) {
|
|
return 'User Not Found'
|
|
} else {
|
|
return data
|
|
}
|
|
}
|
|
|
|
function getUserId(user) {
|
|
let data = sql.query(`SELECT id FROM users WHERE userName = '${user}'`)
|
|
// console.log(data)
|
|
if (data.length == 0) {
|
|
return 'User Not Found'
|
|
} else {
|
|
return data[0].id
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = {
|
|
getUserAccounts,
|
|
getAllUserAccounts,
|
|
getUserId,
|
|
getUserAccountsCheck,
|
|
getAllUniqueAccounts
|
|
}
|
|
|