mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-12-27 05:58:52 +00:00
Can get the list of friends of a user
This commit is contained in:
parent
8eb69469a7
commit
fe11162953
27
src/entities/Friend.ts
Normal file
27
src/entities/Friend.ts
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Friend information
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
export interface FriendBuilder {
|
||||
friendID: number,
|
||||
accepted: boolean,
|
||||
following: boolean,
|
||||
lastActivityTime: number,
|
||||
canPostTexts: boolean
|
||||
}
|
||||
|
||||
export class Friend implements FriendBuilder {
|
||||
friendID: number; accepted: boolean;
|
||||
following: boolean;
|
||||
lastActivityTime: number;
|
||||
canPostTexts: boolean;
|
||||
|
||||
public constructor(info: FriendBuilder) {
|
||||
for (const key in info) {
|
||||
if (info.hasOwnProperty(key))
|
||||
this[key] = info[key];
|
||||
}
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ import { UserHelper } from "./UserHelper";
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
const USER_TABLE = "utilisateurs";
|
||||
export const USER_TABLE = "utilisateurs";
|
||||
const USERS_TOKENS_TABLE = "comunic_api_users_tokens";
|
||||
|
||||
export class AccountHelper {
|
||||
|
@ -1,4 +1,6 @@
|
||||
import { DatabaseHelper } from "./DatabaseHelper";
|
||||
import { USER_TABLE } from "./AccountHelper";
|
||||
import { Friend } from "../entities/Friend";
|
||||
|
||||
/**
|
||||
* Friends helper
|
||||
@ -10,6 +12,35 @@ const FRIENDS_TABLE = "amis";
|
||||
|
||||
export class FriendsHelper {
|
||||
|
||||
/**
|
||||
* Get the list of friends of the user
|
||||
*
|
||||
* @param userID The ID of the user
|
||||
*/
|
||||
public static async GetList(userID: number) : Promise<Array<Friend>> {
|
||||
const results = await DatabaseHelper.Query({
|
||||
table: FRIENDS_TABLE + " f",
|
||||
where: {
|
||||
ID_personne: userID,
|
||||
},
|
||||
joins: [
|
||||
{
|
||||
table: USER_TABLE + " u",
|
||||
condition: "f.ID_amis = u.ID"
|
||||
}
|
||||
],
|
||||
fields: [
|
||||
"u.last_activity",
|
||||
"f.ID_amis",
|
||||
"f.actif",
|
||||
"f.abonnement",
|
||||
"f.autoriser_post_page"
|
||||
]
|
||||
});
|
||||
|
||||
return results.map((r) => this.DbToFriend(r));
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of friendship requests a user
|
||||
* received
|
||||
@ -80,4 +111,19 @@ export class FriendsHelper {
|
||||
|
||||
return result["autoriser_post_page"] == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a database entry into a {Friend} object
|
||||
*
|
||||
* @param row The row to transform
|
||||
*/
|
||||
private static DbToFriend(row: any) : Friend {
|
||||
return new Friend({
|
||||
friendID: row.ID_amis,
|
||||
accepted: row.actif == 1,
|
||||
following: row.abonnement == 1,
|
||||
lastActivityTime: row.last_activity,
|
||||
canPostTexts: row.autoriser_post_page == 1
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user