1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-23 13:59:22 +00:00
comunicapiv2/src/helpers/UserHelper.ts

47 lines
1.1 KiB
TypeScript
Raw Normal View History

import { User, UserPageStatus } from "../entities/User";
import { DatabaseHelper } from "./DatabaseHelper";
2019-11-23 15:10:51 +00:00
import { AccountImageHelper } from "./AccountImageHelper";
/**
* 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);
}
2019-11-23 15:10:51 +00:00
private static async DbToUser(row: any) : Promise<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,
2019-11-23 15:10:51 +00:00
pageStatus: row.pageouverte == 1 ? UserPageStatus.OPEN : (row.public == 1 ? UserPageStatus.PUBLIC : UserPageStatus.PRIVATE),
accountImage: await AccountImageHelper.Get(row.ID)
});
}
}