Add UserEmail.fromUser()

This commit is contained in:
Alice Gaudon 2020-05-05 17:17:29 +02:00
parent 924104f700
commit 26fdc94e9b
2 changed files with 6 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "wms-core", "name": "wms-core",
"version": "0.4.25", "version": "0.4.26",
"description": "Node web framework", "description": "Node web framework",
"repository": "git@gitlab.com:ArisuOngaku/wms-core.git", "repository": "git@gitlab.com:ArisuOngaku/wms-core.git",
"author": "Alice Gaudon <alice@gaudon.pro>", "author": "Alice Gaudon <alice@gaudon.pro>",

View File

@ -11,10 +11,14 @@ export default class UserEmail extends Model {
} }
public static async getMainFromUser(userID: number): Promise<UserEmail | null> { public static async getMainFromUser(userID: number): Promise<UserEmail | null> {
const emails = await this.models<UserEmail>(this.select().where('user_id', userID).where('main', 1)); const emails = await this.models<UserEmail>(this.select().where('user_id', userID).where('main', 1).first());
return emails.length > 0 ? emails[0] : null; return emails.length > 0 ? emails[0] : null;
} }
public static async fromUser(userID: number): Promise<UserEmail[] | null> {
return await this.models<UserEmail>(this.select().where('user_id', userID));
}
public user_id?: number; public user_id?: number;
public email?: string; public email?: string;
private main?: boolean; private main?: boolean;