mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
/* eslint-disable camelcase */
|
|
import { AddressType_NONE } from 'gradido-blockchain-js'
|
|
import { Arg, Query, Resolver } from 'type-graphql'
|
|
|
|
import { getAddressType } from '@/client/GradidoNode'
|
|
import { KeyPairIdentifier } from '@/data/KeyPairIdentifier'
|
|
import { KeyPairCalculation } from '@/interactions/keyPairCalculation/KeyPairCalculation.context'
|
|
import { logger } from '@/logging/logger'
|
|
import { uuid4ToHash } from '@/utils/typeConverter'
|
|
|
|
import { TransactionErrorType } from '../enum/TransactionErrorType'
|
|
import { UserIdentifier } from '../input/UserIdentifier'
|
|
import { TransactionError } from '../model/TransactionError'
|
|
import { TransactionResult } from '../model/TransactionResult'
|
|
|
|
@Resolver()
|
|
export class AccountResolver {
|
|
@Query(() => Boolean)
|
|
async isAccountExist(@Arg('data') userIdentifier: UserIdentifier): Promise<boolean> {
|
|
const accountKeyPair = await KeyPairCalculation(new KeyPairIdentifier(userIdentifier))
|
|
const publicKey = accountKeyPair.getPublicKey()
|
|
if (!publicKey) {
|
|
throw new TransactionResult(
|
|
new TransactionError(TransactionErrorType.NOT_FOUND, 'cannot get user public key'),
|
|
)
|
|
}
|
|
|
|
// ask gradido node server for account type, if type !== NONE account exist
|
|
const addressType = await getAddressType(
|
|
publicKey.data(),
|
|
uuid4ToHash(userIdentifier.communityUuid).convertToHex(),
|
|
)
|
|
logger.info('isAccountExist', userIdentifier)
|
|
return addressType !== AddressType_NONE
|
|
}
|
|
}
|