85 lines
2.3 KiB
TypeScript
85 lines
2.3 KiB
TypeScript
import * as plugins from './plugins.js';
|
|
import type { IIdpSdkAccount, TIdpAccountAuthSource, TIdpAccountRole, TIdpAccountStatus } from './interfaces.js';
|
|
|
|
let activeSmartdataDb: plugins.smartdata.SmartdataDb | null = null;
|
|
|
|
export const setAccountDocSmartdataDb = (smartdataDbArg: plugins.smartdata.SmartdataDb) => {
|
|
activeSmartdataDb = smartdataDbArg;
|
|
};
|
|
|
|
const getDb = () => {
|
|
if (!activeSmartdataDb) {
|
|
throw new Error('IdpSdkAccountDoc has no SmartdataDb configured');
|
|
}
|
|
return activeSmartdataDb;
|
|
};
|
|
|
|
@plugins.smartdata.Collection(() => getDb())
|
|
export class IdpSdkAccountDoc extends plugins.smartdata.SmartDataDbDoc<IdpSdkAccountDoc, IdpSdkAccountDoc> {
|
|
@plugins.smartdata.unI()
|
|
@plugins.smartdata.svDb()
|
|
public id!: string;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public email!: string;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public emailNormalized!: string;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public name: string = '';
|
|
|
|
@plugins.smartdata.svDb()
|
|
public role!: TIdpAccountRole;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public status!: TIdpAccountStatus;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public authSources!: TIdpAccountAuthSource[];
|
|
|
|
@plugins.smartdata.svDb()
|
|
public passwordHash?: string;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public idpSubject?: string;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public createdAt!: number;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public updatedAt!: number;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public lastLoginAt?: number;
|
|
|
|
public toAccount(): IIdpSdkAccount {
|
|
return {
|
|
id: this.id,
|
|
email: this.email,
|
|
emailNormalized: this.emailNormalized,
|
|
name: this.name,
|
|
role: this.role,
|
|
status: this.status,
|
|
authSources: this.authSources || [],
|
|
passwordHash: this.passwordHash,
|
|
idpSubject: this.idpSubject,
|
|
createdAt: this.createdAt,
|
|
updatedAt: this.updatedAt,
|
|
lastLoginAt: this.lastLoginAt,
|
|
};
|
|
}
|
|
|
|
public static async findById(idArg: string): Promise<IdpSdkAccountDoc | null> {
|
|
return IdpSdkAccountDoc.getInstance({ id: idArg });
|
|
}
|
|
|
|
public static async findByEmailNormalized(emailNormalizedArg: string): Promise<IdpSdkAccountDoc | null> {
|
|
return IdpSdkAccountDoc.getInstance({ emailNormalized: emailNormalizedArg });
|
|
}
|
|
|
|
public static async findAdmins(): Promise<IdpSdkAccountDoc[]> {
|
|
return IdpSdkAccountDoc.getInstances({ role: 'admin', status: 'active' });
|
|
}
|
|
}
|