init for chats and api

This commit is contained in:
Nikolai Petukhov
2024-10-04 00:06:44 +03:00
parent 1301c145e8
commit 073c61977f
6 changed files with 441 additions and 13 deletions
+16 -1
View File
@@ -1,5 +1,6 @@
// Read already defined users (pseudo-DB)
const users = require('./auth/users.json');
const chats = require('./chat/chats.json');
const getUserFromDB = (userID) => {
if (!userID) {return false;}
@@ -14,4 +15,18 @@ const getUserFromDB = (userID) => {
}
}
module.exports = {users, getUserFromDB}
const getChatFromDB = (firstID, secondID) => {
if (!firstID || !secondID) {return false;}
// Accessing 'DB'
const chat = chats.find((item) =>
(item.id1 === firstID && item.id2 === secondID) || (item.id1 === secondID && item.id2 === firstID));
if (chat) {
return chat;
} else {
return false;
}
}
module.exports = {users, chats, getUserFromDB, getChatFromDB}