mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
add register address code to backend
This commit is contained in:
parent
b9e138939b
commit
e4dcd7f0ce
@ -1,4 +1,5 @@
|
||||
import { Transaction as DbTransaction } from '@entity/Transaction'
|
||||
import { User } from '@entity/User'
|
||||
import { gql, GraphQLClient } from 'graphql-request'
|
||||
|
||||
import { CONFIG } from '@/config'
|
||||
@ -6,13 +7,31 @@ import { TransactionTypeId } from '@/graphql/enum/TransactionTypeId'
|
||||
import { LogError } from '@/server/LogError'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
|
||||
import { AccountType } from './enum/AccountType'
|
||||
import { TransactionResult } from './model/TransactionResult'
|
||||
import { UserAccountDraft } from './model/UserAccountDraft'
|
||||
import { UserIdentifier } from './model/UserIdentifier'
|
||||
|
||||
const sendTransaction = gql`
|
||||
mutation ($input: TransactionInput!) {
|
||||
sendTransaction(data: $input) {
|
||||
dltTransactionIdHex
|
||||
error {
|
||||
message
|
||||
name
|
||||
}
|
||||
succeed
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const registerAddress = gql`
|
||||
mutation ($input: UserAccountDraft!) {
|
||||
registerAddress(data: $input) {
|
||||
error {
|
||||
message
|
||||
name
|
||||
}
|
||||
succeed
|
||||
}
|
||||
}
|
||||
`
|
||||
@ -63,7 +82,10 @@ export class DltConnectorClient {
|
||||
if (!DltConnectorClient.instance.client) {
|
||||
try {
|
||||
DltConnectorClient.instance.client = new GraphQLClient(CONFIG.DLT_CONNECTOR_URL, {
|
||||
method: 'GET',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
jsonSerializer: {
|
||||
parse: JSON.parse,
|
||||
stringify: JSON.stringify,
|
||||
@ -118,7 +140,45 @@ export class DltConnectorClient {
|
||||
}
|
||||
return succeed
|
||||
} catch (e) {
|
||||
console.log("catch response dlt:", e)
|
||||
throw new LogError('Error send sending transaction to dlt-connector: ', e)
|
||||
}
|
||||
}
|
||||
|
||||
public async registerAddress(dbUser: User): Promise<TransactionResult | undefined> {
|
||||
console.log('dlt:registerAddress')
|
||||
const params = {
|
||||
input: {
|
||||
user: {
|
||||
uuid: dbUser.gradidoID,
|
||||
communityUuid: dbUser.communityUuid,
|
||||
accountNr: 1,
|
||||
} as UserIdentifier,
|
||||
createdAt: dbUser.createdAt.toISOString(),
|
||||
accountType: AccountType.COMMUNITY_HUMAN,
|
||||
} as UserAccountDraft,
|
||||
}
|
||||
try {
|
||||
console.log('before send with', params)
|
||||
const {
|
||||
data: { registerAddress: result },
|
||||
} = await this.client.rawRequest<{ registerAddress: TransactionResult }>(
|
||||
registerAddress,
|
||||
params,
|
||||
)
|
||||
console.log('after send')
|
||||
console.log('result: ', result)
|
||||
logger.info('send register address transaction to dlt-connector', {
|
||||
params,
|
||||
result,
|
||||
})
|
||||
if (result.error) {
|
||||
logger.error('Error sending register address transaction to dlt-connector', result.error)
|
||||
}
|
||||
return result
|
||||
} catch (e) {
|
||||
console.log('exception', e)
|
||||
logger.error('Exception sending register address transaction to dlt-connector', e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
9
backend/src/apis/dltConnector/enum/AccountType.ts
Normal file
9
backend/src/apis/dltConnector/enum/AccountType.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export enum AccountType {
|
||||
NONE = 'NONE', // if no address was found
|
||||
COMMUNITY_HUMAN = 'COMMUNITY_HUMAN', // creation account for human
|
||||
COMMUNITY_GMW = 'COMMUNITY_GMW', // community public budget account
|
||||
COMMUNITY_AUF = 'COMMUNITY_AUF', // community compensation and environment founds account
|
||||
COMMUNITY_PROJECT = 'COMMUNITY_PROJECT', // no creations allowed
|
||||
SUBACCOUNT = 'SUBACCOUNT', // no creations allowed
|
||||
CRYPTO_ACCOUNT = 'CRYPTO_ACCOUNT', // user control his keys, no creations
|
||||
}
|
||||
9
backend/src/apis/dltConnector/model/UserAccountDraft.ts
Normal file
9
backend/src/apis/dltConnector/model/UserAccountDraft.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { AccountType } from '@/apis/dltConnector/enum/AccountType'
|
||||
|
||||
import { UserIdentifier } from './UserIdentifier'
|
||||
|
||||
export interface UserAccountDraft {
|
||||
user: UserIdentifier
|
||||
createdAt: string
|
||||
accountType: AccountType
|
||||
}
|
||||
@ -30,6 +30,7 @@ import { SearchAdminUsersResult } from '@model/AdminUser'
|
||||
import { User } from '@model/User'
|
||||
import { UserAdmin, SearchUsersResult } from '@model/UserAdmin'
|
||||
|
||||
import { DltConnectorClient } from '@/apis/dltConnector/DltConnectorClient'
|
||||
import { subscribe } from '@/apis/KlicktippController'
|
||||
import { encode } from '@/auth/JWT'
|
||||
import { RIGHTS } from '@/auth/RIGHTS'
|
||||
@ -359,6 +360,12 @@ export class UserResolver {
|
||||
}
|
||||
logger.info('createUser() successful...')
|
||||
|
||||
const dltConnector = DltConnectorClient.getInstance()
|
||||
if (dltConnector) {
|
||||
const r = await dltConnector.registerAddress(dbUser)
|
||||
console.log('result from dlt', r)
|
||||
}
|
||||
|
||||
if (redeemCode) {
|
||||
eventRegisterRedeem.affectedUser = dbUser
|
||||
eventRegisterRedeem.actingUser = dbUser
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user