import IUser from '../../Interfaces/User/IUser'; import { IRefObject } from '../../services/database/DatabaseService'; /** * User class */ export default class User { private _user; private _user_ref; /** * Fetch user from database for current org * @param options - Parameters for database query. Only one will be checked at a time, in order of "importance" : email > username > external_id. * @param version - The app version to check * @param orgID - Optionnal, but must be provided if function is called from the backend (used to find user's organization). */ static FetchUser: (options: { email?: string; username?: string; external_id?: string; }, version?: string, orgID?: string) => Promise; /** * Get org ID for a specified user email. * @param userEmail * @throws If relation could not be found for provided email * @returns Promise */ private static _getOrgRelationForUserEmail; /** * Check if a given user email corresponds to a given org ID. * @param userEmail * @param orgId * @returns Promise */ static checkIfUserExistsForOrg: (userEmail: string, orgId: string) => Promise; constructor(user: IUser, user_ref: IRefObject); getDefaultSpaceId: () => string; getFullName: () => string; getEmail: () => string; data: () => IUser; save: (partial?: Partial) => Promise; setFavoriteWarehouse: (warehouse_id: string) => Promise; setDefaultSpaceId: (active_space_id: string) => Promise; disable(): Promise; enable(spaceID: string): Promise; reinitPassword(): Promise; /** * Sets new nip value for given user. * * @param newNip * @param tempNipToken * Used in case of "forgot nip". Corresponds to the token sent by email to the user when they asked for a Nip reset. * If not provided and nip is defined for user, throws error. * @returns boolean (if successful) */ private _setNip; /** * Checks if nip provided is same as nip found in user. * * If user has no nip registered in database, throws an error (should call {@link this._setNip} instead) * If check successful and value returnOnly is false/undefined, saves new value for last_nip_checked. * * @param valueToCheck * @param returnOnly * @returns a promise withe the last nip check for the user */ private _checkNip; private _checkToken; /** * Removes property last_nip_check from User * @returns boolean */ private _removeLastChecked; private _setLastNipCheck; nip: { set: (newNip: number, token?: string) => Promise; check: (valueToCheck: number, returnOnly?: boolean) => Promise; checkToken: (valueToCheck: string) => boolean; removeLastChecked: () => Promise; setLastNipCheck: () => Promise; }; /** * Checks if last_nip_check.date is expired (more than lockTimeoutMinutes, default 30 minutes) * If lockTimeoutMinutes is null, the token never expires (no automatic lock) * * @param valueToCheck IUser['last_nip_check'] * @param lockTimeoutMinutes Délai en minutes avant expiration (par défaut 30 minutes, null = aucun verrouillage) * @returns boolean */ static checkIfNipTokenHasExpired: (valueToCheck?: IUser['last_nip_check'], lockTimeoutMinutes?: number | null) => boolean; }