API-19: switching from for...in to for...of #9
|
@ -71,18 +71,16 @@ export const getUserData = async (useDev: boolean, userId: string): Promise<User
|
||||||
|
|
||||||
let user: UserData = {} as UserData;
|
let user: UserData = {} as UserData;
|
||||||
|
|
||||||
for (let row in rows) {
|
for (let row of rows) {
|
||||||
if (row !== 'meta') {
|
user = {
|
||||||
user = {
|
username: row.username,
|
||||||
username: rows[row].username,
|
email: row.email,
|
||||||
email: rows[row].email,
|
firstName: row.first_name,
|
||||||
firstName: rows[row].first_name,
|
lastName: row.last_name,
|
||||||
lastName: rows[row].last_name,
|
lastLogin: row.last_login,
|
||||||
lastLogin: rows[row].last_login,
|
emailIsVerified: row.email_is_verified,
|
||||||
emailIsVerified: rows[row].email_is_verified,
|
isPremiumUser: row.is_premium_user
|
||||||
isPremiumUser: rows[row].is_premium_user
|
};
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
|
@ -114,15 +112,13 @@ export const getSessionData = async (useDev: boolean, userId: string): Promise<S
|
||||||
|
|
||||||
let sessions: SessionData[] = [];
|
let sessions: SessionData[] = [];
|
||||||
|
|
||||||
for (let row in rows) {
|
for (let row of rows) {
|
||||||
if (row !== 'meta') {
|
sessions.push({
|
||||||
sessions.push({
|
sessionId: row.session_id,
|
||||||
sessionId: rows[row].session_id,
|
type: row.type,
|
||||||
type: rows[row].type,
|
lastLogin: row.last_login,
|
||||||
lastLogin: rows[row].last_login,
|
lastIp: row.last_ip
|
||||||
lastIp: rows[row].last_ip
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return sessions;
|
return sessions;
|
||||||
|
@ -154,16 +150,14 @@ export const getFriendshipData = async (useDev: boolean, userId: string): Promis
|
||||||
|
|
||||||
let friends: Friendship[] = [];
|
let friends: Friendship[] = [];
|
||||||
|
|
||||||
for (let row in rows) {
|
for (let row of rows) {
|
||||||
if (row !== 'meta') {
|
friends.push({
|
||||||
friends.push({
|
friendshipId: row.friendship_id,
|
||||||
friendshipId: rows[row].friendship_id,
|
friendId: row.friend_id,
|
||||||
friendId: rows[row].friend_id,
|
friendFirstName: row.friend_first_name,
|
||||||
friendFirstName: rows[row].friend_first_name,
|
friendLastName: row.friend_last_name,
|
||||||
friendLastName: rows[row].friend_last_name,
|
friendUsername: row.friend_username
|
||||||
friendUsername: rows[row].friend_username
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return friends;
|
return friends;
|
||||||
|
|
|
@ -57,11 +57,9 @@ export const getExistingUsernamesAndEmails = async (useDev: boolean): Promise<an
|
||||||
let usernames: string[] = [];
|
let usernames: string[] = [];
|
||||||
let emails: string[] = [];
|
let emails: string[] = [];
|
||||||
|
|
||||||
for (let row in rows) {
|
for (let row of rows) {
|
||||||
if (row !== 'meta') {
|
usernames.push(row.username);
|
||||||
usernames.push(rows[row].username);
|
emails.push(row.email);
|
||||||
emails.push(rows[row].email);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -109,9 +107,9 @@ export const registerUser = async (useDev: boolean, username: string, email: str
|
||||||
|
|
||||||
// Get user id of the created user
|
// Get user id of the created user
|
||||||
let userId: number = -1;
|
let userId: number = -1;
|
||||||
for (const row in userIdRes) {
|
for (const row of userIdRes) {
|
||||||
if (row !== 'meta' && userIdRes[row].user_id != null) {
|
if (row.user_id != null) {
|
||||||
userId = userIdRes[row].user_id;
|
userId = row.user_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,9 +127,9 @@ export const registerUser = async (useDev: boolean, username: string, email: str
|
||||||
|
|
||||||
// Get session id of the created session
|
// Get session id of the created session
|
||||||
let sessionId: number = -1;
|
let sessionId: number = -1;
|
||||||
for (const row in sessionIdRes) {
|
for (const row of sessionIdRes) {
|
||||||
if (row !== 'meta' && sessionIdRes[row].session_id != null) {
|
if (row.session_id != null) {
|
||||||
sessionId = sessionIdRes[row].session_id;
|
sessionId = row.session_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,11 +177,9 @@ export const loginUser = async (useDev: boolean, username: string, email: string
|
||||||
let passwordHash: string = '';
|
let passwordHash: string = '';
|
||||||
let userId: string = '';
|
let userId: string = '';
|
||||||
|
|
||||||
for (let row in query_result) {
|
for (let row of query_result) {
|
||||||
if (row !== 'meta') {
|
passwordHash = row.password_hash;
|
||||||
passwordHash = query_result[row].password_hash;
|
userId = row.user_id;
|
||||||
userId = query_result[row].user_id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrong password
|
// Wrong password
|
||||||
|
@ -212,9 +208,9 @@ export const loginUser = async (useDev: boolean, username: string, email: string
|
||||||
|
|
||||||
// Get session id of the created session
|
// Get session id of the created session
|
||||||
let sessionId: number = -1;
|
let sessionId: number = -1;
|
||||||
for (const row in sessionIdRes) {
|
for (const row of sessionIdRes) {
|
||||||
if (row !== 'meta' && sessionIdRes[row].session_id != null) {
|
if (row.session_id != null) {
|
||||||
sessionId = sessionIdRes[row].session_id;
|
sessionId = row.session_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,10 +307,8 @@ export const checkSession = async (useDev: boolean, userId: string, sessionId: s
|
||||||
let rows = await conn.query('SELECT session_key_hash FROM sessions WHERE user_id = ? AND session_id = ?', [userId, sessionId]);
|
let rows = await conn.query('SELECT session_key_hash FROM sessions WHERE user_id = ? AND session_id = ?', [userId, sessionId]);
|
||||||
|
|
||||||
let savedHash = '';
|
let savedHash = '';
|
||||||
for (let row in rows) {
|
for (let row of rows) {
|
||||||
if (row !== 'meta') {
|
savedHash = row.session_key_hash;
|
||||||
savedHash = rows[row].session_key_hash;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return bcrypt.compareSync(sessionKey, savedHash);
|
return bcrypt.compareSync(sessionKey, savedHash);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user