generated from lucien/api-template
add: improved the frontend and the backend by adding websockets
This commit is contained in:
parent
ecf7b61aca
commit
fbf7821320
18 changed files with 255 additions and 65 deletions
|
@ -110,7 +110,7 @@ function getActiveChannels(connection) {
|
|||
FROM messages
|
||||
JOIN channels ON messages.channel_id = channels.id
|
||||
JOIN users ON messages.user_id = users.id
|
||||
WHERE date > (SELECT max(date) FROM messages) - 7 * 24 * 60 * 60
|
||||
WHERE date > (SELECT max(date) FROM messages) - 3 * 24 * 60 * 60
|
||||
GROUP BY channel_id
|
||||
ORDER BY count(*) DESC
|
||||
LIMIT 5;`,
|
||||
|
@ -124,6 +124,23 @@ function getActiveChannels(connection) {
|
|||
});
|
||||
}
|
||||
|
||||
function getNewChannels(connection) {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(
|
||||
`SELECT channels.id, name, description, owner_id, username AS owner_username
|
||||
FROM channels
|
||||
JOIN users ON channels.owner_id = users.id
|
||||
ORDER BY channels.id DESC LIMIT 5`,
|
||||
(error, result) => {
|
||||
if (error) {
|
||||
reject(new Error(error));
|
||||
}
|
||||
resolve(result);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function searchChannels(connection, search) {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(
|
||||
|
@ -319,6 +336,7 @@ module.exports = {
|
|||
getUserLastMessages,
|
||||
getChannels,
|
||||
getActiveChannels,
|
||||
getNewChannels,
|
||||
searchChannels,
|
||||
getChannel,
|
||||
addChannel,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue