split DltConnectorClient into multiple files similar to gms client

This commit is contained in:
einhorn_b 2023-12-28 19:24:01 +01:00
parent ba13144ad3
commit 3b6240de1f
13 changed files with 73 additions and 57 deletions

View File

@ -16,6 +16,7 @@ module.exports = {
moduleNameMapper: {
'@/(.*)': '<rootDir>/src/$1',
'@arg/(.*)': '<rootDir>/src/graphql/arg/$1',
'@dltConnector/(.*)': '<rootDir>/src/apis/dltConnector/$1',
'@enum/(.*)': '<rootDir>/src/graphql/enum/$1',
'@model/(.*)': '<rootDir>/src/graphql/model/$1',
'@union/(.*)': '<rootDir>/src/graphql/union/$1',

View File

@ -1,3 +1,4 @@
import { Contribution } from '@entity/Contribution'
import { Transaction as DbTransaction } from '@entity/Transaction'
import { User as DbUser } from '@entity/User'
import { gql, GraphQLClient } from 'graphql-request'
@ -6,7 +7,9 @@ import { CONFIG } from '@/config'
import { TransactionTypeId } from '@/graphql/enum/TransactionTypeId'
import { LogError } from '@/server/LogError'
import { backendLogger as logger } from '@/server/logger'
import { Contribution } from '@entity/Contribution'
import { TransactionResult } from './model/TransactionResult'
import { UserIdentifier } from './model/UserIdentifier'
const sendTransaction = gql`
mutation ($input: TransactionInput!) {
@ -16,52 +19,6 @@ const sendTransaction = gql`
}
`
enum TransactionType {
GRADIDO_TRANSFER = 1,
GRADIDO_CREATION = 2,
GROUP_FRIENDS_UPDATE = 3,
REGISTER_ADDRESS = 4,
GRADIDO_DEFERRED_TRANSFER = 5,
COMMUNITY_ROOT = 6,
}
enum TransactionErrorType {
NOT_IMPLEMENTED_YET = 'Not Implemented yet',
MISSING_PARAMETER = 'Missing parameter',
ALREADY_EXIST = 'Already exist',
DB_ERROR = 'DB Error',
PROTO_DECODE_ERROR = 'Proto Decode Error',
PROTO_ENCODE_ERROR = 'Proto Encode Error',
INVALID_SIGNATURE = 'Invalid Signature',
LOGIC_ERROR = 'Logic Error',
NOT_FOUND = 'Not found',
}
interface TransactionError {
type: TransactionErrorType
message: string
name: string
}
interface TransactionRecipe {
id: number
createdAt: string
type: TransactionType
topic: string
}
interface TransactionResult {
error?: TransactionError
recipe?: TransactionRecipe
succeed: boolean
}
interface UserIdentifier {
uuid: string
communityUuid: string
accountNr?: number
}
// from ChatGPT
function getTransactionTypeString(id: TransactionTypeId): string {
const key = Object.keys(TransactionTypeId).find(

View File

@ -0,0 +1,14 @@
/**
* Error Types for dlt-connector graphql responses
*/
export enum TransactionErrorType {
NOT_IMPLEMENTED_YET = 'Not Implemented yet',
MISSING_PARAMETER = 'Missing parameter',
ALREADY_EXIST = 'Already exist',
DB_ERROR = 'DB Error',
PROTO_DECODE_ERROR = 'Proto Decode Error',
PROTO_ENCODE_ERROR = 'Proto Encode Error',
INVALID_SIGNATURE = 'Invalid Signature',
LOGIC_ERROR = 'Logic Error',
NOT_FOUND = 'Not found',
}

View File

@ -0,0 +1,11 @@
/**
* Transaction Types on Blockchain
*/
export enum TransactionType {
GRADIDO_TRANSFER = 1,
GRADIDO_CREATION = 2,
GROUP_FRIENDS_UPDATE = 3,
REGISTER_ADDRESS = 4,
GRADIDO_DEFERRED_TRANSFER = 5,
COMMUNITY_ROOT = 6,
}

View File

@ -0,0 +1,7 @@
import { TransactionErrorType } from '@dltConnector/enum/TransactionErrorType'
export interface TransactionError {
type: TransactionErrorType
message: string
name: string
}

View File

@ -0,0 +1,8 @@
import { TransactionType } from '@dltConnector/enum/TransactionType'
export interface TransactionRecipe {
id: number
createdAt: string
type: TransactionType
topic: string
}

View File

@ -0,0 +1,8 @@
import { TransactionError } from './TransactionError'
import { TransactionRecipe } from './TransactionRecipe'
export interface TransactionResult {
error?: TransactionError
recipe?: TransactionRecipe
succeed: boolean
}

View File

@ -0,0 +1,5 @@
export interface UserIdentifier {
uuid: string
communityUuid: string
accountNr?: number
}

View File

@ -22,17 +22,15 @@ import { logger, i18n as localization } from '@test/testSetup'
import { CONFIG } from '@/config'
import { TransactionTypeId } from '@/graphql/enum/TransactionTypeId'
import { sendTransactionsToDltConnector } from './sendTransactionsToDltConnector'
import { Contribution } from '@entity/Contribution'
import { User } from '@entity/User'
import { userFactory } from '@/seeds/factory/user'
import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg'
import { creations } from '@/seeds/creation'
import { creationFactory } from '@/seeds/factory/creation'
import { userFactory } from '@/seeds/factory/user'
import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg'
import { bobBaumeister } from '@/seeds/users/bob-baumeister'
import { peterLustig } from '@/seeds/users/peter-lustig'
import { raeuberHotzenplotz } from '@/seeds/users/raeuber-hotzenplotz'
import { bobBaumeister } from '@/seeds/users/bob-baumeister'
import { sendTransactionsToDltConnector } from './sendTransactionsToDltConnector'
/*
// Mock the GraphQLClient

View File

@ -3,7 +3,8 @@ import { Community } from '@entity/Community'
import { DltTransaction } from '@entity/DltTransaction'
import { Transaction } from '@entity/Transaction'
import { DltConnectorClient } from '@/apis/DltConnectorClient'
import { DltConnectorClient } from '@dltConnector/DltConnectorClient'
import { backendLogger as logger } from '@/server/logger'
import { Monitor, MonitorNames } from '@/util/Monitor'
@ -52,7 +53,6 @@ export async function sendTransactionsToDltConnector(): Promise<void> {
`error while sending to dlt-connector or writing messageId of dltTx=${dltTx.id}`,
e,
)
console.log('error', e)
}
}
} else {

View File

@ -49,6 +49,7 @@
"paths": { /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
"@/*": ["src/*"],
"@arg/*": ["src/graphql/arg/*"],
"@dltConnector/*": ["src/apis/dltConnector/*"],
"@enum/*": ["src/graphql/enum/*"],
"@model/*": ["src/graphql/model/*"],
"@union/*": ["src/graphql/union/*"],

View File

@ -37,10 +37,14 @@ export class CreateTransactionRecipeContext {
return this.transactionRecipeRole.getTransaction()
}
public async run(): Promise<void> {
/**
* @returns true if a transaction recipe was created and false if it wasn't necessary
*/
public async run(): Promise<boolean> {
if (this.draft instanceof TransactionDraft) {
this.transactionRecipeRole = new TransactionRecipeRole()
await this.transactionRecipeRole.create(this.draft)
return true
} else if (this.draft instanceof CommunityDraft) {
if (!this.community) {
throw new TransactionError(TransactionErrorType.MISSING_PARAMETER, 'community was not set')
@ -49,6 +53,8 @@ export class CreateTransactionRecipeContext {
this.draft,
this.community,
)
return true
}
return false
}
}