mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-26 17:01:34 +00:00
feat: add getFirstIdentityFromUser helper function
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
e7eb6694a6
commit
3cc321f353
1 changed files with 27 additions and 0 deletions
27
src/identity/utils.ts
Normal file
27
src/identity/utils.ts
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
import { User } from '../users/user.entity';
|
||||||
|
import { Identity } from './identity.entity';
|
||||||
|
import { ProviderType } from './provider-type.enum';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the first identity of a given type from the user
|
||||||
|
* @param {User} user - the user to get the identity from
|
||||||
|
* @param {ProviderType} providerType - the type of the identity
|
||||||
|
* @return {Identity | undefined} the first identity of the user or undefined, if such an identity can not be found
|
||||||
|
*/
|
||||||
|
export async function getFirstIdentityFromUser(
|
||||||
|
user: User,
|
||||||
|
providerType: ProviderType,
|
||||||
|
): Promise<Identity | undefined> {
|
||||||
|
const identities = await user.identities;
|
||||||
|
if (identities === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return identities.find(
|
||||||
|
(aIdentity) => aIdentity.providerType === providerType,
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in a new issue