get-parent-entity

A function that gets the parent entity of the currently logged in user.

Installation#

npm install @iqmetrix/get-parent-entity

Interface#

interface ParentEntity {
id: number;
name: string;
role: string;
}
const getParentEntity: () => Promise<ParentEntity>

Example#

import getParentEntity from '@iqmetrix/get-parent-entity';
/**
* Sends an interop request to get parent(company) entity.
*
* @see interop
*
* @return A promise that resolves a ParentEntity { id: number; name: string; role: string; }
*/
const parentEntity = await getParentEntity();
const users = await fetch(`https://example.iqmetrix.net/companies(${parentEntity.Id})/users`);

See tests for more examples.

The function rejects to an error with the name "MissingParentEntityError" if it's unable to read the parent entity from host-interop and cannot fetch the parent entity details from the appropriate service.

Sources#

Last updated on by Paulo Andrade