Merge pull request 'API-19: switching from for...in to for...of' (#9) from API-19 into master

Reviewed-on: #9
This commit is contained in:
Patrick Müller 2021-08-27 14:24:17 +00:00
commit f716d24d51
2 changed files with 42 additions and 54 deletions

View File

@ -71,18 +71,16 @@ export const getUserData = async (useDev: boolean, userId: string): Promise<User
let user: UserData = {} as UserData;
for (let row in rows) {
if (row !== 'meta') {
user = {
username: rows[row].username,
email: rows[row].email,
firstName: rows[row].first_name,
lastName: rows[row].last_name,
lastLogin: rows[row].last_login,
emailIsVerified: rows[row].email_is_verified,
isPremiumUser: rows[row].is_premium_user
};
}
for (let row of rows) {
user = {
username: row.username,
email: row.email,
firstName: row.first_name,
lastName: row.last_name,
lastLogin: row.last_login,
emailIsVerified: row.email_is_verified,
isPremiumUser: row.is_premium_user
};
}
return user;
@ -114,15 +112,13 @@ export const getSessionData = async (useDev: boolean, userId: string): Promise<S
let sessions: SessionData[] = [];
for (let row in rows) {
if (row !== 'meta') {
sessions.push({
sessionId: rows[row].session_id,
type: rows[row].type,
lastLogin: rows[row].last_login,
lastIp: rows[row].last_ip
});
}
for (let row of rows) {
sessions.push({
sessionId: row.session_id,
type: row.type,
lastLogin: row.last_login,
lastIp: row.last_ip
});
}
return sessions;
@ -154,16 +150,14 @@ export const getFriendshipData = async (useDev: boolean, userId: string): Promis
let friends: Friendship[] = [];
for (let row in rows) {
if (row !== 'meta') {
friends.push({
friendshipId: rows[row].friendship_id,
friendId: rows[row].friend_id,
friendFirstName: rows[row].friend_first_name,
friendLastName: rows[row].friend_last_name,
friendUsername: rows[row].friend_username
});
}
for (let row of rows) {
friends.push({
friendshipId: row.friendship_id,
friendId: row.friend_id,
friendFirstName: row.friend_first_name,
friendLastName: row.friend_last_name,
friendUsername: row.friend_username
});
}
return friends;

View File

@ -57,11 +57,9 @@ export const getExistingUsernamesAndEmails = async (useDev: boolean): Promise<an
let usernames: string[] = [];
let emails: string[] = [];
for (let row in rows) {
if (row !== 'meta') {
usernames.push(rows[row].username);
emails.push(rows[row].email);
}
for (let row of rows) {
usernames.push(row.username);
emails.push(row.email);
}
return {
@ -109,9 +107,9 @@ export const registerUser = async (useDev: boolean, username: string, email: str
// Get user id of the created user
let userId: number = -1;
for (const row in userIdRes) {
if (row !== 'meta' && userIdRes[row].user_id != null) {
userId = userIdRes[row].user_id;
for (const row of userIdRes) {
if (row.user_id != null) {
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
let sessionId: number = -1;
for (const row in sessionIdRes) {
if (row !== 'meta' && sessionIdRes[row].session_id != null) {
sessionId = sessionIdRes[row].session_id;
for (const row of sessionIdRes) {
if (row.session_id != null) {
sessionId = row.session_id;
}
}
@ -179,11 +177,9 @@ export const loginUser = async (useDev: boolean, username: string, email: string
let passwordHash: string = '';
let userId: string = '';
for (let row in query_result) {
if (row !== 'meta') {
passwordHash = query_result[row].password_hash;
userId = query_result[row].user_id;
}
for (let row of query_result) {
passwordHash = row.password_hash;
userId = row.user_id;
}
// Wrong password
@ -212,9 +208,9 @@ export const loginUser = async (useDev: boolean, username: string, email: string
// Get session id of the created session
let sessionId: number = -1;
for (const row in sessionIdRes) {
if (row !== 'meta' && sessionIdRes[row].session_id != null) {
sessionId = sessionIdRes[row].session_id;
for (const row of sessionIdRes) {
if (row.session_id != null) {
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 savedHash = '';
for (let row in rows) {
if (row !== 'meta') {
savedHash = rows[row].session_key_hash;
}
for (let row of rows) {
savedHash = row.session_key_hash;
}
return bcrypt.compareSync(sessionKey, savedHash);