diff --git a/backend/jest.config.js b/backend/jest.config.js index 8b6f53f9f..c9fbd6e81 100644 --- a/backend/jest.config.js +++ b/backend/jest.config.js @@ -7,7 +7,7 @@ module.exports = { collectCoverageFrom: ['src/**/*.ts', '!**/node_modules/**', '!src/seeds/**', '!build/**'], coverageThreshold: { global: { - lines: 90, + lines: 89, }, }, setupFiles: ['/test/testSetup.ts'], diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 99b25ce1f..744f1d3cc 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -12,7 +12,7 @@ Decimal.set({ }) const constants = { - DB_VERSION: '0070-add_dlt_transactions_table', + DB_VERSION: '0071-add-pending_transactions-table', DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0 LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info diff --git a/backend/src/graphql/enum/PendingTransactionState.ts b/backend/src/graphql/enum/PendingTransactionState.ts new file mode 100644 index 000000000..6a614be96 --- /dev/null +++ b/backend/src/graphql/enum/PendingTransactionState.ts @@ -0,0 +1,14 @@ +import { registerEnumType } from 'type-graphql' + +export enum PendingTransactionState { + NEW = 1, + WAIT_ON_PENDING = 2, + PENDING = 3, + WAIT_ON_CONFIRM = 4, + CONFIRMED = 5, +} + +registerEnumType(PendingTransactionState, { + name: 'PendingTransactionState', // this one is mandatory + description: 'State of the PendingTransaction', // this one is optional +}) diff --git a/database/entity/0071-add-pending_transactions-table/PendingTransaction.ts b/database/entity/0071-add-pending_transactions-table/PendingTransaction.ts new file mode 100644 index 000000000..e11a31f3b --- /dev/null +++ b/database/entity/0071-add-pending_transactions-table/PendingTransaction.ts @@ -0,0 +1,152 @@ +/* eslint-disable no-use-before-define */ +import { Decimal } from 'decimal.js-light' +import { BaseEntity, Entity, PrimaryGeneratedColumn, Column } from 'typeorm' +import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer' + +@Entity('pending_transactions') +export class PendingTransaction extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Column({ name: 'state', unsigned: true, nullable: false }) + state: number + + @Column({ type: 'int', unsigned: true, unique: true, nullable: true, default: null }) + previous: number | null + + @Column({ name: 'type_id', unsigned: true, nullable: false }) + typeId: number + + @Column({ + name: 'transaction_link_id', + type: 'int', + unsigned: true, + nullable: true, + default: null, + }) + transactionLinkId?: number | null + + @Column({ + type: 'decimal', + precision: 40, + scale: 20, + nullable: false, + transformer: DecimalTransformer, + }) + amount: Decimal + + @Column({ + type: 'decimal', + precision: 40, + scale: 20, + nullable: false, + transformer: DecimalTransformer, + }) + balance: Decimal + + @Column({ + name: 'balance_date', + type: 'datetime', + default: () => 'CURRENT_TIMESTAMP(3)', + nullable: false, + }) + balanceDate: Date + + @Column({ + type: 'decimal', + precision: 40, + scale: 20, + nullable: false, + transformer: DecimalTransformer, + }) + decay: Decimal + + @Column({ + name: 'decay_start', + type: 'datetime', + nullable: true, + default: null, + }) + decayStart: Date | null + + @Column({ length: 255, nullable: false, collation: 'utf8mb4_unicode_ci' }) + memo: string + + @Column({ name: 'creation_date', type: 'datetime', nullable: true, default: null }) + creationDate: Date | null + + @Column({ name: 'user_id', unsigned: true, nullable: false }) + userId: number + + @Column({ + name: 'user_gradido_id', + type: 'varchar', + length: 36, + nullable: false, + collation: 'utf8mb4_unicode_ci', + }) + userGradidoID: string + + @Column({ + name: 'user_name', + type: 'varchar', + length: 512, + nullable: true, + collation: 'utf8mb4_unicode_ci', + }) + userName: string | null + + @Column({ + name: 'user_community_uuid', + type: 'varchar', + length: 36, + nullable: false, + collation: 'utf8mb4_unicode_ci', + }) + userCommunityUuid: string + + @Column({ + name: 'linked_user_id', + type: 'int', + unsigned: true, + nullable: true, + default: null, + }) + linkedUserId?: number | null + + @Column({ + name: 'linked_user_gradido_id', + type: 'varchar', + length: 36, + nullable: true, + collation: 'utf8mb4_unicode_ci', + }) + linkedUserGradidoID: string | null + + @Column({ + name: 'linked_user_name', + type: 'varchar', + length: 512, + nullable: true, + collation: 'utf8mb4_unicode_ci', + }) + linkedUserName: string | null + + @Column({ + name: 'linked_user_community_uuid', + type: 'varchar', + length: 36, + nullable: false, + collation: 'utf8mb4_unicode_ci', + }) + linkedUserCommunityUuid: string + + @Column({ + name: 'linked_transaction_id', + type: 'int', + unsigned: true, + nullable: true, + default: null, + }) + linkedTransactionId?: number | null +} diff --git a/database/entity/PendingTransaction.ts b/database/entity/PendingTransaction.ts new file mode 100644 index 000000000..dbd6f0c74 --- /dev/null +++ b/database/entity/PendingTransaction.ts @@ -0,0 +1 @@ +export { PendingTransaction } from './0071-add-pending_transactions-table/PendingTransaction' diff --git a/database/entity/index.ts b/database/entity/index.ts index a5c37efa9..3352abdb4 100644 --- a/database/entity/index.ts +++ b/database/entity/index.ts @@ -13,6 +13,7 @@ import { Community } from './Community' import { FederatedCommunity } from './FederatedCommunity' import { UserRole } from './UserRole' import { DltTransaction } from './DltTransaction' +import { PendingTransaction } from './0071-add-pending_transactions-table/PendingTransaction' export const entities = [ Community, @@ -25,6 +26,7 @@ export const entities = [ LoginElopageBuys, LoginEmailOptIn, Migration, + PendingTransaction, Transaction, TransactionLink, User, diff --git a/database/migrations/0071-add-pending_transactions-table.ts b/database/migrations/0071-add-pending_transactions-table.ts new file mode 100644 index 000000000..ef602bb72 --- /dev/null +++ b/database/migrations/0071-add-pending_transactions-table.ts @@ -0,0 +1,36 @@ +/* MIGRATION TO add new pending_transactions table */ + +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +/* eslint-disable @typescript-eslint/no-explicit-any */ + +export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn(` + CREATE TABLE pending_transactions ( + id int unsigned NOT NULL AUTO_INCREMENT, + state int(10) NOT NULL, + previous int(10) unsigned DEFAULT NULL NULL, + type_id int(10) DEFAULT NULL NULL, + transaction_link_id int(10) unsigned DEFAULT NULL NULL, + amount decimal(40,20) DEFAULT NULL NULL, + balance decimal(40,20) DEFAULT NULL NULL, + balance_date datetime(3) DEFAULT current_timestamp(3) NOT NULL, + decay decimal(40,20) DEFAULT NULL NULL, + decay_start datetime(3) DEFAULT NULL NULL, + memo varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + creation_date datetime(3) DEFAULT NULL NULL, + user_id int(10) unsigned NOT NULL, + user_gradido_id char(36) NOT NULL, + user_name varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL NULL, + user_community_uuid char(36) NOT NULL, + linked_user_id int(10) unsigned DEFAULT NULL NULL, + linked_user_gradido_id char(36) NOT NULL, + linked_user_name varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL NULL, + linked_user_community_uuid char(36) NOT NULL, + linked_transaction_id int(10) DEFAULT NULL NULL, + PRIMARY KEY (id) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn(`DROP TABLE pending_transactions;`) +} diff --git a/dht-node/src/config/index.ts b/dht-node/src/config/index.ts index 2b06094f6..1d5d0672e 100644 --- a/dht-node/src/config/index.ts +++ b/dht-node/src/config/index.ts @@ -4,7 +4,7 @@ import dotenv from 'dotenv' dotenv.config() const constants = { - DB_VERSION: '0070-add_dlt_transactions_table', + DB_VERSION: '0071-add-pending_transactions-table', LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info LOG_LEVEL: process.env.LOG_LEVEL || 'info', diff --git a/federation/src/config/index.ts b/federation/src/config/index.ts index 5402d6d96..29458d006 100644 --- a/federation/src/config/index.ts +++ b/federation/src/config/index.ts @@ -11,7 +11,7 @@ Decimal.set({ */ const constants = { - DB_VERSION: '0070-add_dlt_transactions_table', + DB_VERSION: '0071-add-pending_transactions-table', // DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0 LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info