Add UserEmail.getMainFromUser

This commit is contained in:
Alice Gaudon 2020-04-25 16:09:13 +02:00
parent b13d70bfc0
commit 49fc92df5c

View File

@ -10,6 +10,11 @@ export default class UserEmail extends Model {
return emails.length > 0 ? emails[0] : null; return emails.length > 0 ? emails[0] : 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));
return emails.length > 0 ? emails[0] : null;
}
public user_id?: number; public user_id?: number;
public email?: string; public email?: string;
private main?: boolean; private main?: boolean;