getPrincipal
@nmi-agro/fdm-source / fdm-core/src / getPrincipal
Function: getPrincipal()
getPrincipal(
fdm,principal_id):Promise<Principal|undefined>
Defined in: fdm-core/src/principal.ts:33
Retrieves details of a principal (either a user or an organization) by ID.
This function attempts to retrieve 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_id
string
The unique identifier of the principal.
Returns
Promise<Principal | undefined>
A promise that resolves to an object containing the principal's details, or undefined if the principal is not found. The resolved 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 getPrincipal(fdm, "user123");
if (principalDetails) {
console.log("Principal Details:", principalDetails);
} else {
console.log("Principal not found.");
}