mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { Not, In } from 'typeorm'
|
|
import { CommunityHandshakeState, CommunityHandshakeStateType} from '..'
|
|
import { Ed25519PublicKey } from 'shared'
|
|
|
|
/**
|
|
* Find a pending community handshake by public key.
|
|
* @param publicKey The public key of the community.
|
|
* @param apiVersion The API version of the community.
|
|
* @param status The status of the community handshake. Optional, if not set, it will find a pending community handshake.
|
|
* @returns The CommunityHandshakeState with associated federated community and community.
|
|
*/
|
|
export function findPendingCommunityHandshake(
|
|
publicKey: Ed25519PublicKey, apiVersion: string, status?: CommunityHandshakeStateType
|
|
): Promise<CommunityHandshakeState | null> {
|
|
return CommunityHandshakeState.findOne({
|
|
where: {
|
|
publicKey: publicKey.asBuffer(),
|
|
apiVersion,
|
|
status: status || Not(In([
|
|
CommunityHandshakeStateType.EXPIRED,
|
|
CommunityHandshakeStateType.FAILED,
|
|
CommunityHandshakeStateType.SUCCESS
|
|
]))
|
|
},
|
|
})
|
|
}
|
|
|
|
export function findPendingCommunityHandshakeOrFailByOneTimeCode(
|
|
oneTimeCode: number
|
|
): Promise<CommunityHandshakeState> {
|
|
return CommunityHandshakeState.findOneOrFail({
|
|
where: { oneTimeCode },
|
|
})
|
|
}
|
|
|