From 3ec740e0a5b1ab4893865bc29d7216b084a1afc0 Mon Sep 17 00:00:00 2001 From: einhorn_b Date: Tue, 9 Jan 2024 16:32:06 +0100 Subject: [PATCH] fix some bugs --- dlt-connector/jest.config.js | 2 +- .../src/data/proto/3_3/GradidoTransaction.ts | 15 ++++++++++++++ dlt-connector/src/graphql/schema.ts | 1 - .../logging/ConfirmBackendTransaction.view.ts | 20 ------------------- .../src/logging/DecayLogging.view.ts | 20 ------------------- .../logging/TransactionBodyLogging.view.ts | 5 +++-- .../logging/TransactionDraftLogging.view.ts | 4 ++-- dlt-connector/test/testSetup.ts | 4 ++-- 8 files changed, 23 insertions(+), 48 deletions(-) delete mode 100644 dlt-connector/src/logging/ConfirmBackendTransaction.view.ts delete mode 100644 dlt-connector/src/logging/DecayLogging.view.ts diff --git a/dlt-connector/jest.config.js b/dlt-connector/jest.config.js index 2de18cf50..69bc64bb2 100644 --- a/dlt-connector/jest.config.js +++ b/dlt-connector/jest.config.js @@ -6,7 +6,7 @@ module.exports = { collectCoverageFrom: ['src/**/*.ts', '!**/node_modules/**', '!src/seeds/**', '!build/**'], coverageThreshold: { global: { - lines: 71, + lines: 66, }, }, setupFiles: ['/test/testSetup.ts'], diff --git a/dlt-connector/src/data/proto/3_3/GradidoTransaction.ts b/dlt-connector/src/data/proto/3_3/GradidoTransaction.ts index 4aaa3e25c..f38bcbd1f 100644 --- a/dlt-connector/src/data/proto/3_3/GradidoTransaction.ts +++ b/dlt-connector/src/data/proto/3_3/GradidoTransaction.ts @@ -1,5 +1,8 @@ import { Field, Message } from 'protobufjs' +import { TransactionErrorType } from '@/graphql/enum/TransactionErrorType' +import { TransactionError } from '@/graphql/model/TransactionError' +import { logger } from '@/logging/logger' import { LogError } from '@/server/LogError' import { SignatureMap } from './SignatureMap' @@ -41,4 +44,16 @@ export class GradidoTransaction extends Message { } return sigPair[0] } + + getTransactionBody(): TransactionBody { + try { + return TransactionBody.decode(new Uint8Array(this.bodyBytes)) + } catch (error) { + logger.error('error decoding body from gradido transaction: %s', error) + throw new TransactionError( + TransactionErrorType.PROTO_DECODE_ERROR, + 'cannot decode body from gradido transaction', + ) + } + } } diff --git a/dlt-connector/src/graphql/schema.ts b/dlt-connector/src/graphql/schema.ts index 19a6d5566..bbd61c63f 100755 --- a/dlt-connector/src/graphql/schema.ts +++ b/dlt-connector/src/graphql/schema.ts @@ -10,7 +10,6 @@ export const schema = async (): Promise => { return buildSchema({ resolvers: [TransactionResolver, CommunityResolver], scalarsMap: [{ type: Decimal, scalar: DecimalScalar }], - emitSchemaFile: true, validate: { validationError: { target: false }, skipMissingProperties: true, diff --git a/dlt-connector/src/logging/ConfirmBackendTransaction.view.ts b/dlt-connector/src/logging/ConfirmBackendTransaction.view.ts deleted file mode 100644 index 667d290dd..000000000 --- a/dlt-connector/src/logging/ConfirmBackendTransaction.view.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { ConfirmBackendTransaction } from '@/graphql/model/ConfirmBackendTransaction' - -import { AbstractLoggingView } from './AbstractLogging.view' - -export class ConfirmBackendTransactionView extends AbstractLoggingView { - public constructor(private self: ConfirmBackendTransaction) { - super() - } - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - public toJSON(): any { - return { - transactionId: this.self.transactionId, - iotaMessageId: this.self.iotaMessageId, - gradidoId: this.self.gradidoId, - balance: this.decimalToString(this.self.balance), - balanceDate: this.self.balanceDate, - } - } -} diff --git a/dlt-connector/src/logging/DecayLogging.view.ts b/dlt-connector/src/logging/DecayLogging.view.ts deleted file mode 100644 index cf7817f58..000000000 --- a/dlt-connector/src/logging/DecayLogging.view.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Decay } from '@/graphql/model/Decay' - -import { AbstractLoggingView } from './AbstractLogging.view' - -export class DecayLoggingView extends AbstractLoggingView { - public constructor(private self: Decay) { - super() - } - - public toJSON() { - return { - balance: this.decimalToString(this.self.balance), - decay: this.decimalToString(this.self.decay), - roundedDecay: this.decimalToString(this.self.roundedDecay), - start: this.dateToString(this.self.start), - end: this.dateToString(this.self.end), - duration: this.self.duration + 's', - } - } -} diff --git a/dlt-connector/src/logging/TransactionBodyLogging.view.ts b/dlt-connector/src/logging/TransactionBodyLogging.view.ts index 9e08bbfa6..0c287b0a5 100644 --- a/dlt-connector/src/logging/TransactionBodyLogging.view.ts +++ b/dlt-connector/src/logging/TransactionBodyLogging.view.ts @@ -1,5 +1,6 @@ -import { getCrossGroupTypeEnumValue } from '@/data/proto/3_3/enum/CrossGroupType' +import { CrossGroupType } from '@/data/proto/3_3/enum/CrossGroupType' import { TransactionBody } from '@/data/proto/3_3/TransactionBody' +import { getEnumValue } from '@/utils/typeConverter' import { AbstractLoggingView } from './AbstractLogging.view' import { CommunityRootLoggingView } from './CommunityRootLogging.view' @@ -20,7 +21,7 @@ export class TransactionBodyLoggingView extends AbstractLoggingView { memo: this.self.memo, createdAt: this.timestampToDateString(this.self.createdAt), versionNumber: this.self.versionNumber, - type: getCrossGroupTypeEnumValue(this.self.type), + type: getEnumValue(CrossGroupType, this.self.type), otherGroup: this.self.otherGroup, transfer: this.self.transfer ? new GradidoTransferLoggingView(this.self.transfer).toJSON() diff --git a/dlt-connector/src/logging/TransactionDraftLogging.view.ts b/dlt-connector/src/logging/TransactionDraftLogging.view.ts index f2115f591..b3fbbb8ae 100644 --- a/dlt-connector/src/logging/TransactionDraftLogging.view.ts +++ b/dlt-connector/src/logging/TransactionDraftLogging.view.ts @@ -12,8 +12,8 @@ export class TransactionDraftLoggingView extends AbstractLoggingView { public toJSON() { return { - senderUser: new UserIdentifierLoggingView(this.self.senderUser).toJSON(), - recipientUser: new UserIdentifierLoggingView(this.self.recipientUser).toJSON(), + user: new UserIdentifierLoggingView(this.self.user).toJSON(), + linkedUser: new UserIdentifierLoggingView(this.self.linkedUser).toJSON(), backendTransactionId: this.self.backendTransactionId, amount: this.decimalToString(this.self.amount), type: getEnumValue(InputTransactionType, this.self.type), diff --git a/dlt-connector/test/testSetup.ts b/dlt-connector/test/testSetup.ts index 1a76560ed..71170cbf0 100644 --- a/dlt-connector/test/testSetup.ts +++ b/dlt-connector/test/testSetup.ts @@ -2,8 +2,8 @@ import { logger } from '@/logging/logger' jest.setTimeout(1000000) -jest.mock('@/server/logger', () => { - const originalModule = jest.requireActual('@/server/logger') +jest.mock('@/logging/logger', () => { + const originalModule = jest.requireActual('@/logging/logger') return { __esModule: true, ...originalModule,