This service allows for managing users.

Hierarchy (view full)

Constructors

Methods

  • Verifies TFA code which is generated by a TOTP app.

    Returns Promise<IResult<null>>

    Returns a status object.

    Example


    (async () => {
    const {data, res} = await userService.activateTotp();
    })();
  • Changes password for current user.

    Parameters

    • newPassword: string

      New password for current user.

    • currentUserPassword: string

      The password of the currently logged user.

    Returns Promise<IResult<null>>

    Returns a result object. During this action if preferred login mode is OAI_SECURE new jwt cookie will be set.

  • Changes password for user.

    Parameters

    • entityOrId: string | number | IUser

      User's id or user object.

    • newPassword: string

      New user password.

    • currentUserPassword: string

      The password of the currently logged user.

    Returns Promise<IResult<null>>

    Returns a result object.

  • Creates a new user.

    Parameters

    • entity: IUser

      User object.

    Returns Promise<IResult<IUser>>

    Returns promise object that is resolved with the details of newly created user.

    Example


    const userObject: IUser = {
    userName: "newUser",
    password: "userPassword12!@"
    };

    (async () => {
    const {data, res} = await userService.create(userObject);
    })();
  • Gets user that is currently logged in with the list of all roles assigned.

    Returns Promise<IResult<ICurrentUser>>

    Returns promise object that is resolved with the ICurrenUser wrapped by IResult.

    Example


    (async () => {
    const {data, res} = await userService.currentWithEffectiveRoles();
    })();
  • Removes user.

    Parameters

    • entityOrId: string | number | IIdentified

      User's id or user object.

    Returns Promise<IResult<null>>

    Returns promise object that is resolved with the IResult of null.

    Example


    const userId: string = "uniqueUserId";

    (async () => {
    const {data, res} = await userService.delete(userGroupId);
    })();
  • Gets the details of given user.

    Parameters

    • entityOrId: string | number | IUser

      User's id or user object.

    Returns Promise<IResult<IUser>>

    Returns promise object that is resolved with the IUser wrapped by IResult.

    Example


    const userId: number = 1;

    (async () => {
    const {data, res} = await userService.detail(userId);
    })();

    User password is never returned in GET response. Authentication mechanism is provided by another interface.

  • Generates a secret which can be used to setup two-factor authentication with TOTP.

    Returns Promise<IResult<ITotp>>

    Returns the secret and an URL to a QR Code.

    Example


    (async () => {
    const {data, res} = await userService.generateTotpSecret();
    console.log(secret);
    })();
  • Gets the list of emails of users subscribed for newsletter on the current tenant and its subtenants.

    Returns Promise<IResult<string>>

    Server response and data with email addresses as plain text.

  • Create instance of User Inventory Role Service related with given User.

    Parameters

    • entityOrId: string | number | IUser

      User's id or user object.

    Returns UserInventoryRoleService

    Returns UserInventoryRoleService object that is related with given User.

    Example


    const userId: string = "uniqueUserId";

    const userInventoryRoleService = userService.inventoryAssignment(userGroupId);
    (async () => {
    const {data, res} = await userInventoryRoleService.create(...);
    })();
  • Gets the list of users filtered by parameters.

    Parameters

    • filter: object = {}

      Object containing filters for querying users.

    Returns Promise<IResultList<IUser>>

    Returns promise object that is resolved with the IUser wrapped by IResultList.

    Example


    const filter: object = {
    pageSize: 100,
    withTotalPages: true
    };

    (async () => {
    const {data, res, paging} = await userService.list(filter);
    })();
  • Resets user's password to a new one.

    Parameters

    • newPassword: IResetPassword

      Object with token, user's email, new password and its strength indicator.

    • OptionaltenantId: string

      The id of user's tenant (if cannot be inferred from URL).

    Returns Promise<IResult<null>>

    Returns a request result object.

    Example

      const newPassword: IResetPassword = {
    token: '123123ASDAWERER@#!WEDS$@#!WADA#A#EA#EA#EA',
    email: 'user@example.com',
    newPassword: 'myNewPassword',
    passwordStrength: PasswordStrength.GREEN
    };
    const tenantId = 't123456';

    (async () => {
    const { res, data } = await userService.resetPassword(newPassword, tenantId);
    })();
  • Sends an email message with a link allowing user to reset their password.

    Parameters

    • email: string

      The email address to send the message to.

    • OptionaltenantId: string

      The id of user's tenant (if cannot be inferred from URL).

    Returns Promise<IResult<null>>

    Returns a request result object.

    Example

      const email = 'user@example.com';
    const tenantId = 't123456';

    (async () => {
    const { res, data } = await userService.sendPasswordResetMail(email, tenantId);
    })();
  • Updates user data.

    Parameters

    • entity: Partial<IUser>

      User is partially updatable.

    Returns Promise<IResult<IUser>>

    Returns promise object that is resolved with the saved user object.

    Example


    const partialUpdateObject: Partial<IUser> = {
    "id" : "myuser",
    "userName" : "newUserName",
    "email": "newUserEmail@example.com"
    ...
    }

    (async () => {
    const {data, res} = await userService.update(partialUpdateObject);
    })();

    When user is updated with changed permissions or groups, suitable audit record is created with type 'User' and activity 'User updated'.

  • Verifies TFA code which is sent via SMS. If invoked with string '0', new TFA code will be sent.

    Parameters

    • pin: string

      The code to verify.

    Returns Promise<IResult<null>>

    Returns a status object.

    Example


    (async () => {
    const {data, res} = await userService.verifyTFACode('123123');
    })();
  • Verifies TFA code which is generated by a TOTP app.

    Parameters

    • code: any

      The code to verify.

    Returns Promise<IResult<null>>

    Returns a status object.

    Example


    (async () => {
    const {data, res} = await userService.verifyTotpCode('123123');
    })();