mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
refactor dlt-connector a bit, fix some wrong code
This commit is contained in:
parent
e4dcd7f0ce
commit
9ce8dfd493
@ -4,7 +4,7 @@ dotenv.config()
|
||||
|
||||
const constants = {
|
||||
LOG4JS_CONFIG: 'log4js-config.json',
|
||||
DB_VERSION: '0003-refactor_transaction_recipe',
|
||||
DB_VERSION: '0004-fix_spelling',
|
||||
// default log level on production should be info
|
||||
LOG_LEVEL: process.env.LOG_LEVEL ?? 'info',
|
||||
CONFIG_VERSION: {
|
||||
|
||||
@ -73,4 +73,10 @@ export const CommunityRepository = getDataSource()
|
||||
}
|
||||
return new KeyPair(community)
|
||||
},
|
||||
|
||||
async loadHomeCommunity(): Promise<Community> {
|
||||
return await this.findOneOrFail({
|
||||
where: { foreign: false },
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import { TransactionRecipe } from '@model/TransactionRecipe'
|
||||
import { Arg, Mutation, Query, Resolver } from 'type-graphql'
|
||||
import { QueryFailedError } from 'typeorm'
|
||||
|
||||
import { TransactionRecipe } from '@model/TransactionRecipe'
|
||||
|
||||
import { TRANSMIT_TO_IOTA_INTERRUPTIVE_SLEEP_KEY } from '@/data/const'
|
||||
import { UserRepository } from '@/data/User.repository'
|
||||
import { RegisterAddressContext } from '@/interactions/backendToDb/account/RegisterAddress.context'
|
||||
import { AccountLoggingView } from '@/logging/AccountLogging.view'
|
||||
import { logger } from '@/logging/logger'
|
||||
import { TransactionLoggingView } from '@/logging/TransactionLogging.view'
|
||||
import { InterruptiveSleepManager } from '@/manager/InterruptiveSleepManager'
|
||||
@ -33,6 +33,10 @@ export class AccountResolver {
|
||||
const registerAddressContext = new RegisterAddressContext(userAccountDraft)
|
||||
try {
|
||||
const { transaction, account } = await registerAddressContext.run()
|
||||
logger.info('register address', {
|
||||
account: new AccountLoggingView(account),
|
||||
transaction: new TransactionLoggingView(transaction),
|
||||
})
|
||||
await getDataSource().transaction(async (transactionalEntityManager) => {
|
||||
await transactionalEntityManager.save(account)
|
||||
await transactionalEntityManager.save(transaction)
|
||||
|
||||
@ -2,13 +2,14 @@ import { Decimal } from 'decimal.js-light'
|
||||
import { GraphQLSchema } from 'graphql'
|
||||
import { buildSchema } from 'type-graphql'
|
||||
|
||||
import { AccountResolver } from './resolver/AccountsResolver'
|
||||
import { CommunityResolver } from './resolver/CommunityResolver'
|
||||
import { TransactionResolver } from './resolver/TransactionsResolver'
|
||||
import { DecimalScalar } from './scalar/Decimal'
|
||||
|
||||
export const schema = async (): Promise<GraphQLSchema> => {
|
||||
return buildSchema({
|
||||
resolvers: [TransactionResolver, CommunityResolver],
|
||||
resolvers: [TransactionResolver, CommunityResolver, AccountResolver],
|
||||
scalarsMap: [{ type: Decimal, scalar: DecimalScalar }],
|
||||
validate: {
|
||||
validationError: { target: false },
|
||||
|
||||
@ -25,7 +25,8 @@ export class RegisterAddressContext {
|
||||
public constructor(private userAccountDraft: UserAccountDraft) {}
|
||||
|
||||
public async run(): Promise<TransactionWithAccount> {
|
||||
const communityKeyPair = await CommunityRepository.loadHomeCommunityKeyPair()
|
||||
const community = await CommunityRepository.loadHomeCommunity()
|
||||
const communityKeyPair = new KeyPair(community)
|
||||
const user = await this.loadOrCreateUser(communityKeyPair)
|
||||
if (this.isAccountAlreadyExistOnUser(user)) {
|
||||
throw new TransactionError(
|
||||
@ -37,6 +38,7 @@ export class RegisterAddressContext {
|
||||
const account = this.createAccount(new UserLogic(user).calculateKeyPair(communityKeyPair))
|
||||
account.user = user
|
||||
const createTransactionContext = new CreateTransactionRecipeContext(this.userAccountDraft, {
|
||||
community,
|
||||
account,
|
||||
})
|
||||
await createTransactionContext.run()
|
||||
|
||||
@ -74,9 +74,13 @@ export class CreateTransactionRecipeContext {
|
||||
if (!this.data?.account) {
|
||||
throw new TransactionError(TransactionErrorType.MISSING_PARAMETER, 'account was not set')
|
||||
}
|
||||
if (!this.data.community) {
|
||||
throw new TransactionError(TransactionErrorType.MISSING_PARAMETER, 'community was not set')
|
||||
}
|
||||
this.transactionRecipe = await new RegisterAddressTransactionRole().create(
|
||||
this.draft,
|
||||
this.data.account,
|
||||
this.data.community,
|
||||
)
|
||||
return true
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { Account } from '@entity/Account'
|
||||
import { Community } from '@entity/Community'
|
||||
|
||||
import { AccountLogic } from '@/data/Account.logic'
|
||||
import { CommunityRepository } from '@/data/Community.repository'
|
||||
@ -13,6 +14,7 @@ export class RegisterAddressTransactionRole extends AbstractTransactionRecipeRol
|
||||
async create(
|
||||
userAccountDraft: UserAccountDraft,
|
||||
account: Account,
|
||||
community: Community,
|
||||
): Promise<AbstractTransactionRecipeRole> {
|
||||
const bodyBuilder = new TransactionBodyBuilder()
|
||||
const communityKeyPair = await CommunityRepository.loadHomeCommunityKeyPair()
|
||||
@ -22,6 +24,7 @@ export class RegisterAddressTransactionRole extends AbstractTransactionRecipeRol
|
||||
}
|
||||
this.transactionBuilder
|
||||
.fromTransactionBodyBuilder(bodyBuilder.fromUserAccountDraft(userAccountDraft, account))
|
||||
.setCommunity(community)
|
||||
.setSignature(signingKeyPair.sign(this.transactionBuilder.getTransaction().bodyBytes))
|
||||
.setSigningAccount(account)
|
||||
return this
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user