Skip to content

Commit

Permalink
findUserByName
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobrunia committed Nov 16, 2023
1 parent f9735d4 commit c63ef84
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions services/user-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,32 @@ import { JwtPayload } from 'jsonwebtoken';
export async function findUserByName(DATA) {
DATA.userName = '%' + DATA.userName + '%';
const usersArray = await find(`users`, `username like ?`, DATA.userName);
const privateChatsArray = await returnAllPrivateChats();
for (const user of usersArray) {
for (const privateChat of privateChatsArray) {
const usersInChat = await returnUsersInChat(privateChat.id);
if (usersInChat[0] && usersInChat[1]) {
if (
(usersInChat[0].userID == DATA.myId ||
usersInChat[1].userID == DATA.myId) &&
(usersInChat[0].userID == user.id || usersInChat[1].userID == user.id)
) {
// if (DATA.myId == user.id) {
// console.log('Это я');
// user.chatId = null;
// break;
// } else {
// console.log('Есть чат');
user.chatId = privateChat.id;
break;
// }
} else {
// console.log('Нет чата');
user.chatId = null;
}
}
}
}
// const privateChatsArray = await returnAllPrivateChats();
// for (const user of usersArray) {
// for (const privateChat of privateChatsArray) {
// const usersInChat = await returnUsersInChat(privateChat.id);
// if (usersInChat[0] && usersInChat[1]) {
// if (
// (usersInChat[0].userID == DATA.myId ||
// usersInChat[1].userID == DATA.myId) &&
// (usersInChat[0].userID == user.id || usersInChat[1].userID == user.id)
// ) {
// // if (DATA.myId == user.id) {
// // console.log('Это я');
// // user.chatId = null;
// // break;
// // } else {
// // console.log('Есть чат');
// user.chatId = privateChat.id;
// break;
// // }
// } else {
// // console.log('Нет чата');
// user.chatId = null;
// }
// }
// }
// }
return usersArray;
}

Expand Down

0 comments on commit c63ef84

Please sign in to comment.