Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface AccountRepository<Account>

Repository which stores user accounts.

Type parameters

Hierarchy

  • AccountRepository

Methods

changePassword

  • changePassword(accountId: string, passwordHash: string, salt: undefined | null | string, hashingAlg: number): Promise<void>
  • Change account password.
    The following properties need to be updated:

    throws

    {Error} When account is not found or any other error is encountered.

    Parameters

    • accountId: string

      Account id.

    • passwordHash: string

      Password hash.

    • salt: undefined | null | string

      Password salt.

    • hashingAlg: number

      Hashing algorithm id.

    Returns Promise<void>

insert

  • insert(account: Account): Promise<undefined | null | keyof Account[]>
  • Inserts a new account.
    On successful account insertion, it's generated id needs to be stored in the AccountModel.id property of the account argument and null will be returned.
    It is clear that AccountModel.id, AccountModel.username, AccountModel.email, AccountModel.telephone and maybe another properties will be unique ones. Therefore when duplicates are detected, an array with names of the duplicated properties needs to be returned back. This will inform AuthenticationEngine that insertion failed and account registration needs to be aborted.

    throws

    {Error} When any problems (excepting duplicated fields) are encountered by the repository.

    Parameters

    • account: Account

      Account that needs to be inserted.

    Returns Promise<undefined | null | keyof Account[]>

    null or undefined when account was inserted successfully.
    When account has duplicated fields, their names need to be returned inside of array.

isDuplicate

  • isDuplicate(account: Account): Promise<undefined | null | keyof Account[]>
  • Detect whether an account having same values for unique fields exists in the repository.

    Parameters

    • account: Account

      Account that needs to be checked whether it has duplicated fields.

    Returns Promise<undefined | null | keyof Account[]>

    null or undefined when account has no duplicates.
    When account has duplicated fields, their names need to be returned inside of array.

readByEmail

  • readByEmail(email: string): Promise<undefined | null | Account>
  • Read account from repository by his email.

    throws

    {Error} When any problems are encountered by the repository.

    Parameters

    • email: string

      Account email.

    Returns Promise<undefined | null | Account>

    Account entity or null when not found.

readById

  • readById(accountId: string): Promise<undefined | null | Account>
  • Read account from repository by his id.

    throws

    {Error} When any problems are encountered by the repository.

    Parameters

    • accountId: string

      Account id.

    Returns Promise<undefined | null | Account>

    Account entity or null when not found.

readByTelephone

  • readByTelephone(telephone: string): Promise<undefined | null | Account>
  • Read account from repository by his telephone number.

    throws

    {Error} When any problems are encountered by the repository.

    Parameters

    • telephone: string

      Account telephone.

    Returns Promise<undefined | null | Account>

    Account entity or null when not found.

readByUsername

  • readByUsername(username: string): Promise<undefined | null | Account>
  • Read account from repository by his username.

    throws

    {Error} When any problems are encountered by the repository.

    Parameters

    • username: string

      Account username.

    Returns Promise<undefined | null | Account>

    Account entity or null when not found.

setDisabledUntil

  • setDisabledUntil(accountId: string, until: number): Promise<void>
  • Change account availability status by updating AccountModel.disabledUntil property.

    throws

    {Error} When account is not found or any other error is encountered.

    Parameters

    • accountId: string

      Account id.

    • until: number

      Disabled until timestamp.

    Returns Promise<void>

update

  • update(accountId: string, update: Partial<Account>): Promise<void>
  • Update account.

    throws

    {Error} When account is not found or any other error is encountered.

    Parameters

    • accountId: string

      Account id.

    • update: Partial<Account>

      Fields that needs to be updated.

    Returns Promise<void>