Skip to main content

getPrincipals

@nmi-agro/fdm-source


@nmi-agro/fdm-source / fdm-core/src / getPrincipals

Function: getPrincipals()

getPrincipals(fdm, principal_ids): Promise<any>

Defined in: fdm-core/src/principal.ts:75

Retrieves details of multiple principals (each is either user or an organization) by ID.

This function attempts to retrieve each principal's details first from the user table, and if not found, then from the organization table.

Parameters

fdm

PgDatabase

The FDM instance providing the connection to the database.

principal_ids

string[]

The unique identifiers of the principals.

Returns

Promise<any>

A promise that resolves to a map from each principal id to its details. A principal ID will be missing from the map if it is not found. Each detail object includes the name, image, type, and verification status of the principal.

Throws

  • Throws an error if any database operation fails. The error includes a message and context information about the failed operation.

Example

// Example usage:
const principalDetails = await getPrincipals(fdm, ["user123"]);
if (principalDetails.get("user123")) {
console.log("Principal Details:", principalDetails.get("user123"));
} else {
console.log("Principal not found.");
}