Description

This service allows for managing users.

Hierarchy

Constructors

Methods

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

    Returns

    Returns a status object.

    Example


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

    Returns Promise<IResult<null>>

  • Changes password for current user.

    Returns

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

    Parameters

    • newPassword: string

      New password for current user.

    • currentUserPassword: string

      The password of the currently logged user.

    Returns Promise<IResult<null>>

  • Changes password for user.

    Returns

    Returns a result object.

    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>>

  • Creates a new user.

    Returns

    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);
    })();

    Parameters

    • entity: IUser

      User object.

    Returns Promise<IResult<IUser>>

  • Gets user that is currently logged in with the list of all roles assigned.

    Returns

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

    Example


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

    Returns Promise<IResult<ICurrentUser>>

  • Removes user.

    Returns

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

    Example


    const userId: string = "uniqueUserId";

    (async () => {
    const {data, res} = await userService.delete(userGroupId);
    })();

    Parameters

    • entityOrId: string | number | IIdentified

      User's id or user object.

    Returns Promise<IResult<null>>

  • Gets the details of given user.

    Returns

    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.

    Parameters

    • entityOrId: string | number | IUser

      User's id or user object.

    Returns Promise<IResult<IUser>>

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

    Returns

    Returns the secret and an URL to a QR Code.

    Example


    (async () => {
    const {data, res} = await userService.generateTotpSecret();
    console.log(secret);
    })();

    Returns Promise<IResult<ITotp>>

  • Gets the list of emails of users subscribed for newsletter on the current tenant and its subtenants.

    Returns

    Server response and data with email addresses as plain text.

    Returns Promise<IResult<string>>

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

    Returns

    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(...);
    })();

    Parameters

    • entityOrId: string | number | IUser

      User's id or user object.

    Returns UserInventoryRoleService

  • Gets the list of users filtered by parameters.

    Returns

    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);
    })();

    Parameters

    • filter: object = {}

      Object containing filters for querying users.

    Returns Promise<IResultList<IUser>>

  • Resets user's password to a new one.

    Returns

    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);
    })();

    Parameters

    • newPassword: IResetPassword

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

    • Optional tenantId: string

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

    Returns Promise<IResult<null>>

  • Sends an email message with a link allowing user to reset their password.

    Returns

    Returns a request result object.

    Example

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

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

    Parameters

    • email: string

      The email address to send the message to.

    • Optional tenantId: string

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

    Returns Promise<IResult<null>>

  • Updates user data.

    Returns

    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'.

    Parameters

    • entity: Partial<IUser>

      User is partially updatable.

    Returns Promise<IResult<IUser>>

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

    Returns

    Returns a status object.

    Example


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

    Parameters

    • pin: string

      The code to verify.

    Returns Promise<IResult<null>>

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

    Returns

    Returns a status object.

    Example


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

    Parameters

    • code: any

      The code to verify.

    Returns Promise<IResult<null>>