lookupPrincipal
@svenvw/fdm-source / fdm-core/src / lookupPrincipal
Function: lookupPrincipal()
lookupPrincipal(
fdm
,identifier
):Promise
<Principal
[]>
Defined in: fdm-core/src/principal.ts:232
Looks up principals (users or organizations) based on a partial or complete identifier.
This function searches for principals by matching the provided identifier against user emails, and also performs a fuzzy search against organization names and slugs, as well as user usernames, firstnames, surnames and names. It then returns a list of Principal objects representing the matching entities.
Parameters
fdm
any
The FDM instance providing the connection to the database.
identifier
string
The string to search for within principal identifiers (email, username, name or slug). Should have at least 1 character
Returns
Promise
<Principal
[]>
A promise that resolves to an array of Principal objects that match the identifier.
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 searchResults = await lookupPrincipal(fdm, "john");
if (searchResults.length > 0) {
console.log("Found Principals:", searchResults);
} else {
console.log("No principals found matching the identifier.");
}