mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-09-19 21:58:48 +00:00
Can fetch basic information about a user
This commit is contained in:
45
src/helpers/UserHelper.ts
Normal file
45
src/helpers/UserHelper.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { User, UserPageStatus } from "../entities/User";
|
||||
import { DatabaseHelper } from "./DatabaseHelper";
|
||||
|
||||
/**
|
||||
* User helper
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
const TABLE_NAME = "utilisateurs";
|
||||
|
||||
export class UserHelper {
|
||||
|
||||
/**
|
||||
* Get information a single user
|
||||
*
|
||||
* @param id The ID of the user to get
|
||||
* @returns Information about the user | null if not found
|
||||
*/
|
||||
public static async GetUserInfo(id: number) : Promise<User|null> {
|
||||
const result = await DatabaseHelper.QueryRow({
|
||||
table: TABLE_NAME,
|
||||
where: {
|
||||
ID: id
|
||||
}
|
||||
});
|
||||
|
||||
if(!result)
|
||||
return null;
|
||||
|
||||
return this.DbToUser(result);
|
||||
}
|
||||
|
||||
|
||||
private static DbToUser(row: any) : User {
|
||||
return new User({
|
||||
id: row.ID,
|
||||
firstName: row.prenom,
|
||||
lastName: row.nom,
|
||||
timeCreate: new Date(row.date_creation).getTime()/1000,
|
||||
virtualDirectory: row.sous_repertoire,
|
||||
pageStatus: row.pageouverte == 1 ? UserPageStatus.OPEN : (row.public == 1 ? UserPageStatus.PUBLIC : UserPageStatus.PRIVATE)
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user