generated from lucien/api-template
add: improved frontend and added descriptions to users
This commit is contained in:
parent
6342377aa0
commit
eca9efc170
14 changed files with 266 additions and 29 deletions
|
@ -47,7 +47,7 @@ function deleteUser(connection, id) {
|
|||
function getUsers(connection) {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(
|
||||
`SELECT id, username, admin FROM users`,
|
||||
`SELECT id, username, admin, description FROM users`,
|
||||
(error, result) => {
|
||||
if (error) {
|
||||
reject(new Error(error));
|
||||
|
@ -148,6 +148,21 @@ function setUserPassword(connection, id, password) {
|
|||
});
|
||||
}
|
||||
|
||||
function setUserDescription(connection, id, description) {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(
|
||||
`UPDATE users SET description = ? WHERE id = ?`,
|
||||
[description, id],
|
||||
(error, result) => {
|
||||
if (error) {
|
||||
reject(new Error(error));
|
||||
}
|
||||
resolve(result);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// +---------------------------+
|
||||
// | Channels |
|
||||
// +---------------------------+
|
||||
|
@ -185,7 +200,9 @@ function deleteChannel(connection, channel_id) {
|
|||
function getChannels(connection) {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(
|
||||
`SELECT * FROM channels`,
|
||||
`SELECT channels.id, name, channels.description, owner_id, username AS owner_username
|
||||
FROM channels
|
||||
JOIN users ON channels.owner_id = users.id`,
|
||||
(error, result) => {
|
||||
if (error) {
|
||||
reject(new Error(error));
|
||||
|
@ -199,7 +216,7 @@ function getChannels(connection) {
|
|||
function getChannel(connection, name) {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(
|
||||
`SELECT channels.id, name, description, owner_id, username AS owner_username
|
||||
`SELECT channels.id, name, channels.description, owner_id, username AS owner_username
|
||||
FROM channels
|
||||
JOIN users ON channels.owner_id = users.id
|
||||
WHERE name = ?`,
|
||||
|
@ -217,7 +234,7 @@ function getChannel(connection, name) {
|
|||
function getActiveChannels(connection) {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(
|
||||
`SELECT channels.id, name, description, owner_id, username AS owner_username, count(*) AS message_count
|
||||
`SELECT channels.id, name, channels.description, owner_id, username AS owner_username, count(*) AS message_count
|
||||
FROM messages
|
||||
JOIN channels ON messages.channel_id = channels.id
|
||||
JOIN users ON messages.user_id = users.id
|
||||
|
@ -238,7 +255,7 @@ function getActiveChannels(connection) {
|
|||
function getNewChannels(connection) {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(
|
||||
`SELECT channels.id, name, description, owner_id, username AS owner_username
|
||||
`SELECT channels.id, name, channels.description, owner_id, username AS owner_username
|
||||
FROM channels
|
||||
JOIN users ON channels.owner_id = users.id
|
||||
ORDER BY channels.id DESC LIMIT 5`,
|
||||
|
@ -255,7 +272,7 @@ function getNewChannels(connection) {
|
|||
function searchChannels(connection, search) {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(
|
||||
`SELECT channels.id, name, description, owner_id, username AS owner_username
|
||||
`SELECT channels.id, name, channels.description, owner_id, username AS owner_username
|
||||
FROM channels
|
||||
JOIN users ON channels.owner_id = users.id
|
||||
WHERE name LIKE ?
|
||||
|
@ -673,6 +690,7 @@ module.exports = {
|
|||
setUserPfp,
|
||||
setUserUsername,
|
||||
setUserPassword,
|
||||
setUserDescription,
|
||||
|
||||
addChannel,
|
||||
deleteChannel,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue