All checks were successful
Jenkins Production Deployment
Co-authored-by: Patrick Mueller <patrick@mueller-patrick.tech> Reviewed-on: #15 Co-authored-by: Patrick Müller <patrick@plutodev.de> Co-committed-by: Patrick Müller <patrick@plutodev.de>
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import * as dotenv from 'dotenv';
|
|
import {Friendship} from './Friendship.interface';
|
|
import {PartyPlanerDB} from '../PartyPlaner.db';
|
|
|
|
dotenv.config();
|
|
|
|
/**
|
|
* Returns all friends of the given user
|
|
* @param useDev If the dev or prod database should be used
|
|
* @param userId The userId of the user to fetch the friends for
|
|
* @return Friendship[] A list of friends
|
|
*/
|
|
export const getFriendshipData = async (useDev: boolean, userId: string): Promise<Friendship[]> => {
|
|
let conn = PartyPlanerDB.getConnection(useDev);
|
|
try {
|
|
let rows = await conn.query('SELECT f.friendship_id, f.friend_id, u.first_name as friend_first_name, u.last_name as friend_last_name, u.username as friend_username FROM friendships f LEFT OUTER JOIN users u ON f.friend_id = u.user_id WHERE f.user_id = ?', userId);
|
|
|
|
let friends: Friendship[] = [];
|
|
|
|
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;
|
|
} catch (err) {
|
|
throw err;
|
|
}
|
|
};
|