From dc9efdae6713f14ae4d91d657c8babf40cc00e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Fri, 31 Mar 2023 20:12:59 +0200 Subject: [PATCH 01/20] first migration step --- ...-community-sendcoins-transactions_table.ts | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 database/migrations/0065-x-community-sendcoins-transactions_table.ts diff --git a/database/migrations/0065-x-community-sendcoins-transactions_table.ts b/database/migrations/0065-x-community-sendcoins-transactions_table.ts new file mode 100644 index 000000000..73b854d70 --- /dev/null +++ b/database/migrations/0065-x-community-sendcoins-transactions_table.ts @@ -0,0 +1,134 @@ +/* MIGRATION TO add users that have a transaction but do not exist */ + +/* 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( + 'ALTER TABLE `transactions` MODIFY COLUMN `previous` int(10) unsigned DEFAULT NULL NULL AFTER `id`;', + ) + await queryFn( + 'ALTER TABLE `transactions` MODIFY COLUMN `type_id` int(10) DEFAULT NULL NULL AFTER `previous`;', + ) + await queryFn( + 'ALTER TABLE `transactions` MODIFY COLUMN `transaction_link_id` int(10) unsigned DEFAULT NULL NULL AFTER `type_id`;', + ) + await queryFn( + 'ALTER TABLE `transactions` MODIFY COLUMN `amount` decimal(40,20) DEFAULT NULL NULL AFTER `transaction_link_id`;', + ) + await queryFn( + 'ALTER TABLE `transactions` MODIFY COLUMN `balance` decimal(40,20) DEFAULT NULL NULL AFTER `amount`;', + ) + await queryFn( + 'ALTER TABLE `transactions` MODIFY COLUMN `balance_date` datetime(3) DEFAULT current_timestamp(3) NOT NULL AFTER `balance`;', + ) + await queryFn( + 'ALTER TABLE `transactions` MODIFY COLUMN `decay` decimal(40,20) DEFAULT NULL NULL AFTER `balance_date`;', + ) + await queryFn( + 'ALTER TABLE `transactions` MODIFY COLUMN `decay_start` datetime(3) DEFAULT NULL NULL AFTER `decay`;', + ) + await queryFn( + 'ALTER TABLE `transactions` MODIFY COLUMN `memo` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL AFTER `decay_start`;', + ) + await queryFn( + 'ALTER TABLE `transactions` MODIFY COLUMN `creation_date` datetime(3) DEFAULT NULL NULL AFTER `memo`;', + ) + await queryFn( + 'ALTER TABLE `transactions` MODIFY COLUMN `user_id` int(10) unsigned NOT NULL AFTER `creation_date`;', + ) + await queryFn( + 'ALTER TABLE `transactions` ADD COLUMN `user_gradido_id` char(36) DEFAULT NULL NULL AFTER `user_id`;', + ) + await queryFn( + 'ALTER TABLE `transactions` ADD COLUMN `user_community_uuid` char(36) DEFAULT NULL NULL AFTER `user_gradido_id`;', + ) + await queryFn( + 'ALTER TABLE `transactions` ADD COLUMN `user_name` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL NULL AFTER `user_community_uuid`;', + ) + await queryFn( + 'ALTER TABLE `transactions` MODIFY COLUMN `linked_user_id` int(10) unsigned DEFAULT NULL NULL AFTER `user_name`;', + ) + await queryFn( + 'ALTER TABLE `transactions` ADD COLUMN `linked_user_gradido_id` char(36) DEFAULT NULL NULL AFTER `linked_user_id`;', + ) + await queryFn( + 'ALTER TABLE `transactions` ADD COLUMN `linked_user_community_uuid` char(36) DEFAULT NULL NULL AFTER `linked_user_gradido_id`;', + ) + await queryFn( + 'ALTER TABLE `transactions` ADD COLUMN `linked_user_name` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL NULL AFTER `linked_user_community_uuid`;', + ) + await queryFn( + 'ALTER TABLE `transactions` MODIFY COLUMN `linked_transaction_id` int(10) DEFAULT NULL NULL AFTER `linked_user_name`;', + ) + + await queryFn(` + CREATE TABLE IF NOT EXISTS \`pending_transactions\` ( + \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, + \`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_community_uuid\` char(36) NOT NULL, + \`user_name\` varchar(512) COLLATE utf8mb4_unicode_ci NOT NULL, + \`linked_user_id\` int(10) unsigned DEFAULT NULL NULL, + \`linked_user_gradido_id\` char(36) NOT NULL, + \`linked_user_community_uuid\` char(36) NOT NULL, + \`linked_user_name\` varchar(512) NULL, + \`linked_transaction_id\` int(10) DEFAULT NULL NULL, + \`x_transaction_state\` varchar(100) NOT NULL COMMENT 'States to handle 2-Phase-Commit handshake', + \`created_at\` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + \`updated_at\` datetime(3) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(3), + \`deleted_at\` datetime(3) NULL DEFAULT NULL, + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`) + + /* + const userIds = await queryFn(` + SELECT user_id FROM transactions + WHERE NOT EXISTS (SELECT id FROM users WHERE id = user_id) GROUP BY user_id;`) + + for (let i = 0; i < missingUserIds.length; i++) { + let gradidoId = '' + let countIds: any[] = [] + do { + gradidoId = uuidv4() + countIds = await queryFn( + `SELECT COUNT(*) FROM \`users\` WHERE \`gradido_id\` = "${gradidoId}"`, + ) + } while (countIds[0] > 0) + + const userContact = (await queryFn(` + INSERT INTO user_contacts + (type, user_id, email, email_checked, created_at, deleted_at) + VALUES + ('EMAIL', ${missingUserIds[i].user_id}, 'deleted.user${missingUserIds[i].user_id}@gradido.net', 0, NOW(), NOW());`)) as unknown as OkPacket + + await queryFn(` + INSERT INTO users + (id, gradido_id, email_id, first_name, last_name, deleted_at, password_encryption_type, created_at, language) + VALUES + (${missingUserIds[i].user_id}, '${gradidoId}', ${userContact.insertId}, 'DELETED', 'USER', NOW(), 0, NOW(), 'de');`) + } + */ +} + +/* eslint-disable @typescript-eslint/no-empty-function */ +/* eslint-disable-next-line @typescript-eslint/no-unused-vars */ +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn('ALTER TABLE `transactions` DROP COLUMN `user_gradido_id`;') + await queryFn('ALTER TABLE `transactions` DROP COLUMN `user_community_uuid`;') + await queryFn('ALTER TABLE `transactions` DROP COLUMN `user_name`;') + await queryFn('ALTER TABLE `transactions` DROP COLUMN `linked_user_gradido_id`;') + await queryFn('ALTER TABLE `transactions` DROP COLUMN `linked_user_community_uuid`;') + await queryFn('ALTER TABLE `transactions` DROP COLUMN `linked_user_name`;') + await queryFn(`DROP TABLE IF EXISTS pending_transactions;`) +} From 588afdb8d7e122930f0f5f67b6b8a30d76d2af70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 4 Apr 2023 01:56:34 +0200 Subject: [PATCH 02/20] add new attributes for x-community-sendCoins --- backend/src/config/index.ts | 2 +- .../graphql/resolver/ContributionResolver.ts | 2 + .../graphql/resolver/TransactionResolver.ts | 8 + backend/src/util/virtualTransactions.ts | 70 +++++---- .../Transaction.ts | 147 ++++++++++++++++++ database/entity/Transaction.ts | 2 +- ...-community-sendcoins-transactions_table.ts | 42 ++--- 7 files changed, 214 insertions(+), 59 deletions(-) create mode 100644 database/entity/0065-x-community-sendcoins-transactions_table/Transaction.ts diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 23ede1f27..959700814 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -12,7 +12,7 @@ Decimal.set({ }) const constants = { - DB_VERSION: '0064-event_rename', + DB_VERSION: '0065-x-community-sendcoins-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/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 5969eaef2..7068fd4ab 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -501,6 +501,8 @@ export class ContributionResolver { transaction.typeId = TransactionTypeId.CREATION transaction.memo = contribution.memo transaction.userId = contribution.userId + transaction.userGradidoID = user.gradidoID + transaction.userName = user.firstName + ' ' + user.lastName transaction.previous = lastTransaction ? lastTransaction.id : null transaction.amount = contribution.amount transaction.creationDate = contribution.contributionDate diff --git a/backend/src/graphql/resolver/TransactionResolver.ts b/backend/src/graphql/resolver/TransactionResolver.ts index 430cdb363..4706df794 100644 --- a/backend/src/graphql/resolver/TransactionResolver.ts +++ b/backend/src/graphql/resolver/TransactionResolver.ts @@ -87,7 +87,11 @@ export const executeTransaction = async ( transactionSend.typeId = TransactionTypeId.SEND transactionSend.memo = memo transactionSend.userId = sender.id + transactionSend.userGradidoID = sender.gradidoID + transactionSend.userName = sender.firstName + ' ' + sender.lastName transactionSend.linkedUserId = recipient.id + transactionSend.linkedUserGradidoID = recipient.gradidoID + transactionSend.linkedUserName = recipient.firstName + ' ' + recipient.lastName transactionSend.amount = amount.mul(-1) transactionSend.balance = sendBalance.balance transactionSend.balanceDate = receivedCallDate @@ -103,7 +107,11 @@ export const executeTransaction = async ( transactionReceive.typeId = TransactionTypeId.RECEIVE transactionReceive.memo = memo transactionReceive.userId = recipient.id + transactionReceive.userGradidoID = recipient.gradidoID + transactionReceive.userName = recipient.firstName + ' ' + recipient.lastName transactionReceive.linkedUserId = sender.id + transactionReceive.linkedUserGradidoID = sender.gradidoID + transactionReceive.linkedUserName = sender.firstName + ' ' + sender.lastName transactionReceive.amount = amount const receiveBalance = await calculateBalance(recipient.id, amount, receivedCallDate) transactionReceive.balance = receiveBalance ? receiveBalance.balance : amount diff --git a/backend/src/util/virtualTransactions.ts b/backend/src/util/virtualTransactions.ts index 68a37746b..cd73f9feb 100644 --- a/backend/src/util/virtualTransactions.ts +++ b/backend/src/util/virtualTransactions.ts @@ -40,19 +40,25 @@ const virtualLinkTransaction = ( user: User, ): Transaction => { const linkDbTransaction: dbTransaction = { - id: -2, - userId: -1, - previous: -1, - typeId: TransactionTypeId.LINK_SUMMARY, - amount: amount.toDecimalPlaces(2, Decimal.ROUND_FLOOR), - balance: balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), - balanceDate: validUntil, - decayStart: createdAt, - decay: decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR), - memo: '', - creationDate: null, - contribution: null, - ...defaultModelFunctions, + id: -2, + userId: -1, + previous: -1, + typeId: TransactionTypeId.LINK_SUMMARY, + amount: amount.toDecimalPlaces(2, Decimal.ROUND_FLOOR), + balance: balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), + balanceDate: validUntil, + decayStart: createdAt, + decay: decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR), + memo: '', + creationDate: null, + contribution: null, + ...defaultModelFunctions, + userGradidoID: '', + userCommunityUuid: '', + userName: '', + linkedUserGradidoID: '', + linkedUserCommunityUuid: '', + linkedUserName: '' } return new Transaction(linkDbTransaction, user) } @@ -67,22 +73,28 @@ const virtualDecayTransaction = ( const decay = calculateDecay(balance, balanceDate, time) // const balance = decay.balance.minus(lastTransaction.balance) const decayDbTransaction: dbTransaction = { - id: -1, - userId: -1, - previous: -1, - typeId: TransactionTypeId.DECAY, - amount: decay.decay ? decay.roundedDecay : new Decimal(0), - balance: decay.balance - .toDecimalPlaces(2, Decimal.ROUND_DOWN) - .minus(holdAvailabeAmount.toString()) - .toDecimalPlaces(2, Decimal.ROUND_DOWN), - balanceDate: time, - decay: decay.decay ? decay.roundedDecay : new Decimal(0), - decayStart: decay.start, - memo: '', - creationDate: null, - contribution: null, - ...defaultModelFunctions, + id: -1, + userId: -1, + previous: -1, + typeId: TransactionTypeId.DECAY, + amount: decay.decay ? decay.roundedDecay : new Decimal(0), + balance: decay.balance + .toDecimalPlaces(2, Decimal.ROUND_DOWN) + .minus(holdAvailabeAmount.toString()) + .toDecimalPlaces(2, Decimal.ROUND_DOWN), + balanceDate: time, + decay: decay.decay ? decay.roundedDecay : new Decimal(0), + decayStart: decay.start, + memo: '', + creationDate: null, + contribution: null, + ...defaultModelFunctions, + userGradidoID: '', + userCommunityUuid: '', + userName: '', + linkedUserGradidoID: '', + linkedUserCommunityUuid: '', + linkedUserName: '' } return new Transaction(decayDbTransaction, user) } diff --git a/database/entity/0065-x-community-sendcoins-transactions_table/Transaction.ts b/database/entity/0065-x-community-sendcoins-transactions_table/Transaction.ts new file mode 100644 index 000000000..b3f88f0d1 --- /dev/null +++ b/database/entity/0065-x-community-sendcoins-transactions_table/Transaction.ts @@ -0,0 +1,147 @@ +import Decimal from 'decimal.js-light' +import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn } from 'typeorm' +import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer' +import { Contribution } from '../Contribution' + +@Entity('transactions') +export class Transaction extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: 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', + 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', + length: 36, + nullable: false, + collation: 'utf8mb4_unicode_ci', + }) + userGradidoID: string + + @Column({ + name: 'user_community_uuid', + length: 36, + nullable: false, + collation: 'utf8mb4_unicode_ci', + }) + userCommunityUuid: string + + @Column({ + name: 'user_name', + length: 512, + nullable: false, + collation: 'utf8mb4_unicode_ci', + }) + userName: string + + @Column({ + name: 'linked_user_id', + type: 'int', + unsigned: true, + nullable: true, + default: null, + }) + linkedUserId?: number | null + + @Column({ + name: 'linked_user_gradido_id', + length: 36, + nullable: false, + collation: 'utf8mb4_unicode_ci', + }) + linkedUserGradidoID: string + + @Column({ + name: 'linked_user_community_uuid', + length: 36, + nullable: false, + collation: 'utf8mb4_unicode_ci', + }) + linkedUserCommunityUuid: string + + @Column({ + name: 'linked_user_name', + length: 512, + nullable: false, + collation: 'utf8mb4_unicode_ci', + }) + linkedUserName: string + + @Column({ + name: 'linked_transaction_id', + type: 'int', + unsigned: true, + nullable: true, + default: null, + }) + linkedTransactionId?: number | null + + @OneToOne(() => Contribution, (contribution) => contribution.transaction) + @JoinColumn({ name: 'id', referencedColumnName: 'transactionId' }) + contribution?: Contribution | null +} diff --git a/database/entity/Transaction.ts b/database/entity/Transaction.ts index 5365b0f70..3e3355b13 100644 --- a/database/entity/Transaction.ts +++ b/database/entity/Transaction.ts @@ -1 +1 @@ -export { Transaction } from './0036-unique_previous_in_transactions/Transaction' +export { Transaction } from './0065-x-community-sendcoins-transactions_table/Transaction' diff --git a/database/migrations/0065-x-community-sendcoins-transactions_table.ts b/database/migrations/0065-x-community-sendcoins-transactions_table.ts index 73b854d70..d3228b8d9 100644 --- a/database/migrations/0065-x-community-sendcoins-transactions_table.ts +++ b/database/migrations/0065-x-community-sendcoins-transactions_table.ts @@ -62,6 +62,20 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis 'ALTER TABLE `transactions` MODIFY COLUMN `linked_transaction_id` int(10) DEFAULT NULL NULL AFTER `linked_user_name`;', ) + await queryFn( + `UPDATE transactions t, users u SET t.user_gradido_id = u.gradido_id, t.user_name = concat(u.first_name, ' ', u.last_name) WHERE t.user_id = u.id and t.user_gradido_id is null;`, + ) + await queryFn( + 'ALTER TABLE `transactions` MODIFY COLUMN `user_gradido_id` char(36) NOT NULL AFTER `user_id`;', + ) + await queryFn( + 'ALTER TABLE `transactions` MODIFY COLUMN `user_name` varchar(512) COLLATE utf8mb4_unicode_ci NOT NULL AFTER `user_community_uuid`;', + ) + + await queryFn( + `UPDATE transactions t, users u SET t.linked_user_gradido_id = u.gradido_id, t.linked_user_name = concat(u.first_name, ' ', u.last_name) WHERE t.linked_user_id = u.id and t.linked_user_id is null and t.linked_user_gradido_id is null;`, + ) + await queryFn(` CREATE TABLE IF NOT EXISTS \`pending_transactions\` ( \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, @@ -91,34 +105,6 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis PRIMARY KEY (\`id\`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`) - /* - const userIds = await queryFn(` - SELECT user_id FROM transactions - WHERE NOT EXISTS (SELECT id FROM users WHERE id = user_id) GROUP BY user_id;`) - - for (let i = 0; i < missingUserIds.length; i++) { - let gradidoId = '' - let countIds: any[] = [] - do { - gradidoId = uuidv4() - countIds = await queryFn( - `SELECT COUNT(*) FROM \`users\` WHERE \`gradido_id\` = "${gradidoId}"`, - ) - } while (countIds[0] > 0) - - const userContact = (await queryFn(` - INSERT INTO user_contacts - (type, user_id, email, email_checked, created_at, deleted_at) - VALUES - ('EMAIL', ${missingUserIds[i].user_id}, 'deleted.user${missingUserIds[i].user_id}@gradido.net', 0, NOW(), NOW());`)) as unknown as OkPacket - - await queryFn(` - INSERT INTO users - (id, gradido_id, email_id, first_name, last_name, deleted_at, password_encryption_type, created_at, language) - VALUES - (${missingUserIds[i].user_id}, '${gradidoId}', ${userContact.insertId}, 'DELETED', 'USER', NOW(), 0, NOW(), 'de');`) - } - */ } /* eslint-disable @typescript-eslint/no-empty-function */ From a900c163e3a62d2028fed9825f5d5d77402ccd1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 4 Apr 2023 01:58:29 +0200 Subject: [PATCH 03/20] update cypress --- e2e-tests/yarn.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/e2e-tests/yarn.lock b/e2e-tests/yarn.lock index c0f623e47..20956c5d0 100644 --- a/e2e-tests/yarn.lock +++ b/e2e-tests/yarn.lock @@ -2193,10 +2193,10 @@ crypto-browserify@^3.0.0: randombytes "^2.0.0" randomfill "^1.0.3" -cypress@^10.4.0: - version "10.8.0" - resolved "https://registry.yarnpkg.com/cypress/-/cypress-10.8.0.tgz#12a681f2642b6f13d636bab65d5b71abdb1497a5" - integrity sha512-QVse0dnLm018hgti2enKMVZR9qbIO488YGX06nH5j3Dg1isL38DwrBtyrax02CANU6y8F4EJUuyW6HJKw1jsFA== +cypress@^12.7.0: + version "12.9.0" + resolved "https://registry.yarnpkg.com/cypress/-/cypress-12.9.0.tgz#e6ab43cf329fd7c821ef7645517649d72ccf0a12" + integrity sha512-Ofe09LbHKgSqX89Iy1xen2WvpgbvNxDzsWx3mgU1mfILouELeXYGwIib3ItCwoRrRifoQwcBFmY54Vs0zw7QCg== dependencies: "@cypress/request" "^2.88.10" "@cypress/xvfb" "^1.2.4" @@ -2215,7 +2215,7 @@ cypress@^10.4.0: commander "^5.1.0" common-tags "^1.8.0" dayjs "^1.10.4" - debug "^4.3.2" + debug "^4.3.4" enquirer "^2.3.6" eventemitter2 "6.4.7" execa "4.1.0" From c9631f0028dfa38daa063b377a8bf02dc7c86870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 4 Apr 2023 02:20:59 +0200 Subject: [PATCH 04/20] init new tx-attributes --- backend/src/graphql/resolver/TransactionLinkResolver.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.ts b/backend/src/graphql/resolver/TransactionLinkResolver.ts index a5f8c0ee6..d10a81c51 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.ts @@ -266,6 +266,8 @@ export class TransactionLinkResolver { transaction.typeId = TransactionTypeId.CREATION transaction.memo = contribution.memo transaction.userId = contribution.userId + transaction.userGradidoID = user.gradidoID + transaction.userName = user.firstName + ' ' + user.lastName transaction.previous = lastTransaction ? lastTransaction.id : null transaction.amount = contribution.amount transaction.creationDate = contribution.contributionDate From 6bedba53c48d1c7ef0ab2b5919b0b13fe07af279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 4 Apr 2023 23:12:05 +0200 Subject: [PATCH 05/20] linting --- backend/src/util/virtualTransactions.ts | 82 ++++++++++++------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/backend/src/util/virtualTransactions.ts b/backend/src/util/virtualTransactions.ts index cd73f9feb..d06d85908 100644 --- a/backend/src/util/virtualTransactions.ts +++ b/backend/src/util/virtualTransactions.ts @@ -40,25 +40,25 @@ const virtualLinkTransaction = ( user: User, ): Transaction => { const linkDbTransaction: dbTransaction = { - id: -2, - userId: -1, - previous: -1, - typeId: TransactionTypeId.LINK_SUMMARY, - amount: amount.toDecimalPlaces(2, Decimal.ROUND_FLOOR), - balance: balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), - balanceDate: validUntil, - decayStart: createdAt, - decay: decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR), - memo: '', - creationDate: null, - contribution: null, - ...defaultModelFunctions, - userGradidoID: '', - userCommunityUuid: '', - userName: '', - linkedUserGradidoID: '', - linkedUserCommunityUuid: '', - linkedUserName: '' + id: -2, + userId: -1, + previous: -1, + typeId: TransactionTypeId.LINK_SUMMARY, + amount: amount.toDecimalPlaces(2, Decimal.ROUND_FLOOR), + balance: balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), + balanceDate: validUntil, + decayStart: createdAt, + decay: decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR), + memo: '', + creationDate: null, + contribution: null, + ...defaultModelFunctions, + userGradidoID: '', + userCommunityUuid: '', + userName: '', + linkedUserGradidoID: '', + linkedUserCommunityUuid: '', + linkedUserName: '', } return new Transaction(linkDbTransaction, user) } @@ -73,28 +73,28 @@ const virtualDecayTransaction = ( const decay = calculateDecay(balance, balanceDate, time) // const balance = decay.balance.minus(lastTransaction.balance) const decayDbTransaction: dbTransaction = { - id: -1, - userId: -1, - previous: -1, - typeId: TransactionTypeId.DECAY, - amount: decay.decay ? decay.roundedDecay : new Decimal(0), - balance: decay.balance - .toDecimalPlaces(2, Decimal.ROUND_DOWN) - .minus(holdAvailabeAmount.toString()) - .toDecimalPlaces(2, Decimal.ROUND_DOWN), - balanceDate: time, - decay: decay.decay ? decay.roundedDecay : new Decimal(0), - decayStart: decay.start, - memo: '', - creationDate: null, - contribution: null, - ...defaultModelFunctions, - userGradidoID: '', - userCommunityUuid: '', - userName: '', - linkedUserGradidoID: '', - linkedUserCommunityUuid: '', - linkedUserName: '' + id: -1, + userId: -1, + previous: -1, + typeId: TransactionTypeId.DECAY, + amount: decay.decay ? decay.roundedDecay : new Decimal(0), + balance: decay.balance + .toDecimalPlaces(2, Decimal.ROUND_DOWN) + .minus(holdAvailabeAmount.toString()) + .toDecimalPlaces(2, Decimal.ROUND_DOWN), + balanceDate: time, + decay: decay.decay ? decay.roundedDecay : new Decimal(0), + decayStart: decay.start, + memo: '', + creationDate: null, + contribution: null, + ...defaultModelFunctions, + userGradidoID: '', + userCommunityUuid: '', + userName: '', + linkedUserGradidoID: '', + linkedUserCommunityUuid: '', + linkedUserName: '', } return new Transaction(decayDbTransaction, user) } From 71f0f6c7f99cca6106c02a8825f76f2f56c1785f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Thu, 6 Apr 2023 15:59:59 +0200 Subject: [PATCH 06/20] rework PR-comments --- .../graphql/resolver/ContributionResolver.ts | 3 ++- .../resolver/TransactionLinkResolver.ts | 3 ++- .../graphql/resolver/TransactionResolver.ts | 9 +++++---- backend/src/util/utilities.ts | 19 ++++++++++++++++++ backend/src/util/virtualTransactions.ts | 20 +++++++++---------- .../Transaction.ts | 20 +++++++++---------- ...-community-sendcoins-transactions_table.ts | 3 ++- 7 files changed, 50 insertions(+), 27 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 741ed2a83..2bb2e0faf 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -55,6 +55,7 @@ import { } from './util/creations' import { findContributions } from './util/findContributions' import { getLastTransaction } from './util/getLastTransaction' +import { fullName } from '@/util/utilities' @Resolver() export class ContributionResolver { @@ -502,7 +503,7 @@ export class ContributionResolver { transaction.memo = contribution.memo transaction.userId = contribution.userId transaction.userGradidoID = user.gradidoID - transaction.userName = user.firstName + ' ' + user.lastName + transaction.userName = fullName(user.firstName, user.lastName) transaction.previous = lastTransaction ? lastTransaction.id : null transaction.amount = contribution.amount transaction.creationDate = contribution.contributionDate diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.ts b/backend/src/graphql/resolver/TransactionLinkResolver.ts index 856fc5c28..6490b8c9d 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.ts @@ -40,6 +40,7 @@ import { executeTransaction } from './TransactionResolver' import { getUserCreation, validateContribution } from './util/creations' import { getLastTransaction } from './util/getLastTransaction' import transactionLinkList from './util/transactionLinkList' +import { fullName } from '@/util/utilities' // TODO: do not export, test it inside the resolver export const transactionLinkCode = (date: Date): string => { @@ -267,7 +268,7 @@ export class TransactionLinkResolver { transaction.memo = contribution.memo transaction.userId = contribution.userId transaction.userGradidoID = user.gradidoID - transaction.userName = user.firstName + ' ' + user.lastName + transaction.userName = fullName(user.firstName, user.lastName) transaction.previous = lastTransaction ? lastTransaction.id : null transaction.amount = contribution.amount transaction.creationDate = contribution.contributionDate diff --git a/backend/src/graphql/resolver/TransactionResolver.ts b/backend/src/graphql/resolver/TransactionResolver.ts index 5414de413..44cf35f7d 100644 --- a/backend/src/graphql/resolver/TransactionResolver.ts +++ b/backend/src/graphql/resolver/TransactionResolver.ts @@ -37,6 +37,7 @@ import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const' import { findUserByIdentifier } from './util/findUserByIdentifier' import { getLastTransaction } from './util/getLastTransaction' import { getTransactionList } from './util/getTransactionList' +import { fullName } from '@/util/utilities' export const executeTransaction = async ( amount: Decimal, @@ -88,10 +89,10 @@ export const executeTransaction = async ( transactionSend.memo = memo transactionSend.userId = sender.id transactionSend.userGradidoID = sender.gradidoID - transactionSend.userName = sender.firstName + ' ' + sender.lastName + transactionSend.userName = fullName(sender.firstName, sender.lastName) transactionSend.linkedUserId = recipient.id transactionSend.linkedUserGradidoID = recipient.gradidoID - transactionSend.linkedUserName = recipient.firstName + ' ' + recipient.lastName + transactionSend.linkedUserName = fullName(recipient.firstName, recipient.lastName) transactionSend.amount = amount.mul(-1) transactionSend.balance = sendBalance.balance transactionSend.balanceDate = receivedCallDate @@ -108,10 +109,10 @@ export const executeTransaction = async ( transactionReceive.memo = memo transactionReceive.userId = recipient.id transactionReceive.userGradidoID = recipient.gradidoID - transactionReceive.userName = recipient.firstName + ' ' + recipient.lastName + transactionReceive.userName = fullName(recipient.firstName, recipient.lastName) transactionReceive.linkedUserId = sender.id transactionReceive.linkedUserGradidoID = sender.gradidoID - transactionReceive.linkedUserName = sender.firstName + ' ' + sender.lastName + transactionReceive.linkedUserName = fullName(sender.firstName, sender.lastName) transactionReceive.amount = amount const receiveBalance = await calculateBalance(recipient.id, amount, receivedCallDate) transactionReceive.balance = receiveBalance ? receiveBalance.balance : amount diff --git a/backend/src/util/utilities.ts b/backend/src/util/utilities.ts index 2cf53f1e4..9a318f576 100644 --- a/backend/src/util/utilities.ts +++ b/backend/src/util/utilities.ts @@ -14,3 +14,22 @@ export const decimalSeparatorByLanguage = (a: Decimal, language: string): string i18n.setLocale(rememberLocaleToRestore) return result } + +export const fullName = (firstName: string, lastName: string): string => { + return [firstName, lastName].filter(Boolean).join(' ') +} + +export const userName = (f?: string, l?: string): string | null => { + let name: string | null + if(f && l) { + name = f + ' ' + l + } else if (f && !l) { + name = f + } else if (!f && l) { + name = l + } else { + name = null + } + + return name +} \ No newline at end of file diff --git a/backend/src/util/virtualTransactions.ts b/backend/src/util/virtualTransactions.ts index a953552b2..2bc2a591e 100644 --- a/backend/src/util/virtualTransactions.ts +++ b/backend/src/util/virtualTransactions.ts @@ -55,11 +55,11 @@ const virtualLinkTransaction = ( contribution: null, ...defaultModelFunctions, userGradidoID: '', - userCommunityUuid: '', - userName: '', - linkedUserGradidoID: '', - linkedUserCommunityUuid: '', - linkedUserName: '', + userCommunityUuid: null, + userName: null, + linkedUserGradidoID: null, + linkedUserCommunityUuid: null, + linkedUserName: null, } return new Transaction(linkDbTransaction, user) } @@ -91,11 +91,11 @@ const virtualDecayTransaction = ( contribution: null, ...defaultModelFunctions, userGradidoID: '', - userCommunityUuid: '', - userName: '', - linkedUserGradidoID: '', - linkedUserCommunityUuid: '', - linkedUserName: '', + userCommunityUuid: null, + userName: null, + linkedUserGradidoID: null, + linkedUserCommunityUuid: null, + linkedUserName: null, } return new Transaction(decayDbTransaction, user) } diff --git a/database/entity/0065-x-community-sendcoins-transactions_table/Transaction.ts b/database/entity/0065-x-community-sendcoins-transactions_table/Transaction.ts index b3f88f0d1..050661824 100644 --- a/database/entity/0065-x-community-sendcoins-transactions_table/Transaction.ts +++ b/database/entity/0065-x-community-sendcoins-transactions_table/Transaction.ts @@ -86,18 +86,18 @@ export class Transaction extends BaseEntity { @Column({ name: 'user_community_uuid', length: 36, - nullable: false, + nullable: true, collation: 'utf8mb4_unicode_ci', }) - userCommunityUuid: string + userCommunityUuid: string | null @Column({ name: 'user_name', length: 512, - nullable: false, + nullable: true, collation: 'utf8mb4_unicode_ci', }) - userName: string + userName: string | null @Column({ name: 'linked_user_id', @@ -111,26 +111,26 @@ export class Transaction extends BaseEntity { @Column({ name: 'linked_user_gradido_id', length: 36, - nullable: false, + nullable: true, collation: 'utf8mb4_unicode_ci', }) - linkedUserGradidoID: string + linkedUserGradidoID: string | null @Column({ name: 'linked_user_community_uuid', length: 36, - nullable: false, + nullable: true, collation: 'utf8mb4_unicode_ci', }) - linkedUserCommunityUuid: string + linkedUserCommunityUuid: string | null @Column({ name: 'linked_user_name', length: 512, - nullable: false, + nullable: true, collation: 'utf8mb4_unicode_ci', }) - linkedUserName: string + linkedUserName: string | null @Column({ name: 'linked_transaction_id', diff --git a/database/migrations/0065-x-community-sendcoins-transactions_table.ts b/database/migrations/0065-x-community-sendcoins-transactions_table.ts index d3228b8d9..a09d416a7 100644 --- a/database/migrations/0065-x-community-sendcoins-transactions_table.ts +++ b/database/migrations/0065-x-community-sendcoins-transactions_table.ts @@ -68,10 +68,11 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis await queryFn( 'ALTER TABLE `transactions` MODIFY COLUMN `user_gradido_id` char(36) NOT NULL AFTER `user_id`;', ) + /* await queryFn( 'ALTER TABLE `transactions` MODIFY COLUMN `user_name` varchar(512) COLLATE utf8mb4_unicode_ci NOT NULL AFTER `user_community_uuid`;', ) - + */ await queryFn( `UPDATE transactions t, users u SET t.linked_user_gradido_id = u.gradido_id, t.linked_user_name = concat(u.first_name, ' ', u.last_name) WHERE t.linked_user_id = u.id and t.linked_user_id is null and t.linked_user_gradido_id is null;`, ) From c62532c89ae2acf7beef94c4127e2ca6bc8884b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Mon, 17 Apr 2023 12:45:20 +0200 Subject: [PATCH 07/20] linting --- backend/src/graphql/resolver/ContributionResolver.ts | 2 +- backend/src/graphql/resolver/TransactionLinkResolver.ts | 2 +- backend/src/graphql/resolver/TransactionResolver.ts | 2 +- backend/src/util/utilities.ts | 8 ++++---- .../Transaction.ts | 4 ++++ 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 357908bdc..696ed9ea7 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -44,6 +44,7 @@ import { LogError } from '@/server/LogError' import { backendLogger as logger } from '@/server/logger' import { calculateDecay } from '@/util/decay' import { TRANSACTIONS_LOCK } from '@/util/TRANSACTIONS_LOCK' +import { fullName } from '@/util/utilities' import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const' import { @@ -55,7 +56,6 @@ import { } from './util/creations' import { findContributions } from './util/findContributions' import { getLastTransaction } from './util/getLastTransaction' -import { fullName } from '@/util/utilities' @Resolver() export class ContributionResolver { diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.ts b/backend/src/graphql/resolver/TransactionLinkResolver.ts index 914b2c081..a97078f66 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.ts @@ -34,13 +34,13 @@ import { LogError } from '@/server/LogError' import { backendLogger as logger } from '@/server/logger' import { calculateDecay } from '@/util/decay' import { TRANSACTIONS_LOCK } from '@/util/TRANSACTIONS_LOCK' +import { fullName } from '@/util/utilities' import { calculateBalance } from '@/util/validate' import { executeTransaction } from './TransactionResolver' import { getUserCreation, validateContribution } from './util/creations' import { getLastTransaction } from './util/getLastTransaction' import { transactionLinkList } from './util/transactionLinkList' -import { fullName } from '@/util/utilities' // TODO: do not export, test it inside the resolver export const transactionLinkCode = (date: Date): string => { diff --git a/backend/src/graphql/resolver/TransactionResolver.ts b/backend/src/graphql/resolver/TransactionResolver.ts index 65aa29435..7e2a10404 100644 --- a/backend/src/graphql/resolver/TransactionResolver.ts +++ b/backend/src/graphql/resolver/TransactionResolver.ts @@ -29,6 +29,7 @@ import { LogError } from '@/server/LogError' import { backendLogger as logger } from '@/server/logger' import { communityUser } from '@/util/communityUser' import { TRANSACTIONS_LOCK } from '@/util/TRANSACTIONS_LOCK' +import { fullName } from '@/util/utilities' import { calculateBalance } from '@/util/validate' import { virtualLinkTransaction, virtualDecayTransaction } from '@/util/virtualTransactions' @@ -37,7 +38,6 @@ import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const' import { findUserByIdentifier } from './util/findUserByIdentifier' import { getLastTransaction } from './util/getLastTransaction' import { getTransactionList } from './util/getTransactionList' -import { fullName } from '@/util/utilities' export const executeTransaction = async ( amount: Decimal, diff --git a/backend/src/util/utilities.ts b/backend/src/util/utilities.ts index 9a318f576..4dc71ff7f 100644 --- a/backend/src/util/utilities.ts +++ b/backend/src/util/utilities.ts @@ -16,12 +16,12 @@ export const decimalSeparatorByLanguage = (a: Decimal, language: string): string } export const fullName = (firstName: string, lastName: string): string => { - return [firstName, lastName].filter(Boolean).join(' ') + return [firstName, lastName].filter(Boolean).join(' ') } export const userName = (f?: string, l?: string): string | null => { let name: string | null - if(f && l) { + if (f && l) { name = f + ' ' + l } else if (f && !l) { name = f @@ -30,6 +30,6 @@ export const userName = (f?: string, l?: string): string | null => { } else { name = null } - + return name -} \ No newline at end of file +} diff --git a/database/entity/0065-x-community-sendcoins-transactions_table/Transaction.ts b/database/entity/0065-x-community-sendcoins-transactions_table/Transaction.ts index 050661824..0da9a2265 100644 --- a/database/entity/0065-x-community-sendcoins-transactions_table/Transaction.ts +++ b/database/entity/0065-x-community-sendcoins-transactions_table/Transaction.ts @@ -144,4 +144,8 @@ export class Transaction extends BaseEntity { @OneToOne(() => Contribution, (contribution) => contribution.transaction) @JoinColumn({ name: 'id', referencedColumnName: 'transactionId' }) contribution?: Contribution | null + + @OneToOne(() => Transaction) + @JoinColumn({ name: 'previous' }) + previousTransaction?: Transaction | null } From 4a33703f054853d6cf8d410d3f5d5afd6d050714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 19 Apr 2023 01:50:53 +0200 Subject: [PATCH 08/20] linting --- .../migrations/0065-x-community-sendcoins-transactions_table.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/database/migrations/0065-x-community-sendcoins-transactions_table.ts b/database/migrations/0065-x-community-sendcoins-transactions_table.ts index a09d416a7..9f80460ed 100644 --- a/database/migrations/0065-x-community-sendcoins-transactions_table.ts +++ b/database/migrations/0065-x-community-sendcoins-transactions_table.ts @@ -105,7 +105,6 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis \`deleted_at\` datetime(3) NULL DEFAULT NULL, PRIMARY KEY (\`id\`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`) - } /* eslint-disable @typescript-eslint/no-empty-function */ From 9c6296610963623f8c5bf122e2b481848fb47688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 19 Apr 2023 23:03:27 +0200 Subject: [PATCH 09/20] add explicit type: 'varchar' for string columns in transaction entity --- .../Transaction.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/database/entity/0065-x-community-sendcoins-transactions_table/Transaction.ts b/database/entity/0065-x-community-sendcoins-transactions_table/Transaction.ts index 0da9a2265..9202f9fd3 100644 --- a/database/entity/0065-x-community-sendcoins-transactions_table/Transaction.ts +++ b/database/entity/0065-x-community-sendcoins-transactions_table/Transaction.ts @@ -77,6 +77,7 @@ export class Transaction extends BaseEntity { @Column({ name: 'user_gradido_id', + type: 'varchar', length: 36, nullable: false, collation: 'utf8mb4_unicode_ci', @@ -85,6 +86,7 @@ export class Transaction extends BaseEntity { @Column({ name: 'user_community_uuid', + type: 'varchar', length: 36, nullable: true, collation: 'utf8mb4_unicode_ci', @@ -93,6 +95,7 @@ export class Transaction extends BaseEntity { @Column({ name: 'user_name', + type: 'varchar', length: 512, nullable: true, collation: 'utf8mb4_unicode_ci', @@ -110,6 +113,7 @@ export class Transaction extends BaseEntity { @Column({ name: 'linked_user_gradido_id', + type: 'varchar', length: 36, nullable: true, collation: 'utf8mb4_unicode_ci', @@ -118,6 +122,7 @@ export class Transaction extends BaseEntity { @Column({ name: 'linked_user_community_uuid', + type: 'varchar', length: 36, nullable: true, collation: 'utf8mb4_unicode_ci', @@ -126,6 +131,7 @@ export class Transaction extends BaseEntity { @Column({ name: 'linked_user_name', + type: 'varchar', length: 512, nullable: true, collation: 'utf8mb4_unicode_ci', From 6a63e5956d3641a0bd3ea17cc903a1392a209757 Mon Sep 17 00:00:00 2001 From: Claus-Peter Huebner Date: Thu, 4 May 2023 20:48:43 +0200 Subject: [PATCH 10/20] adaptions after master-merge --- .../Transaction.ts | 0 database/entity/Transaction.ts | 2 +- ...able.ts => 0066-x-community-sendcoins-transactions_table.ts} | 0 dht-node/src/config/index.ts | 2 +- federation/src/config/index.ts | 2 +- 5 files changed, 3 insertions(+), 3 deletions(-) rename database/entity/{0065-x-community-sendcoins-transactions_table => 0066-x-community-sendcoins-transactions_table}/Transaction.ts (100%) rename database/migrations/{0065-x-community-sendcoins-transactions_table.ts => 0066-x-community-sendcoins-transactions_table.ts} (100%) diff --git a/database/entity/0065-x-community-sendcoins-transactions_table/Transaction.ts b/database/entity/0066-x-community-sendcoins-transactions_table/Transaction.ts similarity index 100% rename from database/entity/0065-x-community-sendcoins-transactions_table/Transaction.ts rename to database/entity/0066-x-community-sendcoins-transactions_table/Transaction.ts diff --git a/database/entity/Transaction.ts b/database/entity/Transaction.ts index 3e3355b13..4000e3c85 100644 --- a/database/entity/Transaction.ts +++ b/database/entity/Transaction.ts @@ -1 +1 @@ -export { Transaction } from './0065-x-community-sendcoins-transactions_table/Transaction' +export { Transaction } from './0066-x-community-sendcoins-transactions_table/Transaction' diff --git a/database/migrations/0065-x-community-sendcoins-transactions_table.ts b/database/migrations/0066-x-community-sendcoins-transactions_table.ts similarity index 100% rename from database/migrations/0065-x-community-sendcoins-transactions_table.ts rename to database/migrations/0066-x-community-sendcoins-transactions_table.ts diff --git a/dht-node/src/config/index.ts b/dht-node/src/config/index.ts index 5c4676337..eca5dbbb5 100644 --- a/dht-node/src/config/index.ts +++ b/dht-node/src/config/index.ts @@ -3,7 +3,7 @@ import dotenv from 'dotenv' dotenv.config() const constants = { - DB_VERSION: '0065-refactor_communities_table', + DB_VERSION: '0066-x-community-sendcoins-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 70a155d63..66d8a056c 100644 --- a/federation/src/config/index.ts +++ b/federation/src/config/index.ts @@ -11,7 +11,7 @@ Decimal.set({ */ const constants = { - DB_VERSION: '0065-refactor_communities_table', + DB_VERSION: '0066-x-community-sendcoins-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 From 0cd2b7646d1190825612f5637db1abe78ea5e354 Mon Sep 17 00:00:00 2001 From: Claus-Peter Huebner Date: Mon, 8 May 2023 11:03:01 +0200 Subject: [PATCH 11/20] rework PR-comments --- backend/src/util/utilities.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/src/util/utilities.ts b/backend/src/util/utilities.ts index 4dc71ff7f..30c1effdb 100644 --- a/backend/src/util/utilities.ts +++ b/backend/src/util/utilities.ts @@ -19,14 +19,14 @@ export const fullName = (firstName: string, lastName: string): string => { return [firstName, lastName].filter(Boolean).join(' ') } -export const userName = (f?: string, l?: string): string | null => { +export const userName = (firstName?: string, lastName?: string): string | null => { let name: string | null - if (f && l) { - name = f + ' ' + l - } else if (f && !l) { - name = f - } else if (!f && l) { - name = l + if (firstName && lastName) { + name = firstName + ' ' + lastName + } else if (firstName && !lastName) { + name = firstName + } else if (!firstName && lastName) { + name = lastName } else { name = null } From 03246bb54a4f7169fd86a162b8572202e14390a7 Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Mon, 8 May 2023 17:03:37 +0200 Subject: [PATCH 12/20] Update backend/src/util/utilities.ts Co-authored-by: Hannes Heine --- backend/src/util/utilities.ts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/backend/src/util/utilities.ts b/backend/src/util/utilities.ts index 30c1effdb..df2166cfd 100644 --- a/backend/src/util/utilities.ts +++ b/backend/src/util/utilities.ts @@ -19,17 +19,3 @@ export const fullName = (firstName: string, lastName: string): string => { return [firstName, lastName].filter(Boolean).join(' ') } -export const userName = (firstName?: string, lastName?: string): string | null => { - let name: string | null - if (firstName && lastName) { - name = firstName + ' ' + lastName - } else if (firstName && !lastName) { - name = firstName - } else if (!firstName && lastName) { - name = lastName - } else { - name = null - } - - return name -} From 20daf80c44d5694d5d7c71fd1f508911114385d6 Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Mon, 8 May 2023 17:14:55 +0200 Subject: [PATCH 13/20] Update database/migrations/0066-x-community-sendcoins-transactions_table.ts Co-authored-by: Hannes Heine --- ...-community-sendcoins-transactions_table.ts | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/database/migrations/0066-x-community-sendcoins-transactions_table.ts b/database/migrations/0066-x-community-sendcoins-transactions_table.ts index 9f80460ed..a56c6df00 100644 --- a/database/migrations/0066-x-community-sendcoins-transactions_table.ts +++ b/database/migrations/0066-x-community-sendcoins-transactions_table.ts @@ -77,34 +77,6 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis `UPDATE transactions t, users u SET t.linked_user_gradido_id = u.gradido_id, t.linked_user_name = concat(u.first_name, ' ', u.last_name) WHERE t.linked_user_id = u.id and t.linked_user_id is null and t.linked_user_gradido_id is null;`, ) - await queryFn(` - CREATE TABLE IF NOT EXISTS \`pending_transactions\` ( - \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, - \`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_community_uuid\` char(36) NOT NULL, - \`user_name\` varchar(512) COLLATE utf8mb4_unicode_ci NOT NULL, - \`linked_user_id\` int(10) unsigned DEFAULT NULL NULL, - \`linked_user_gradido_id\` char(36) NOT NULL, - \`linked_user_community_uuid\` char(36) NOT NULL, - \`linked_user_name\` varchar(512) NULL, - \`linked_transaction_id\` int(10) DEFAULT NULL NULL, - \`x_transaction_state\` varchar(100) NOT NULL COMMENT 'States to handle 2-Phase-Commit handshake', - \`created_at\` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), - \`updated_at\` datetime(3) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(3), - \`deleted_at\` datetime(3) NULL DEFAULT NULL, - PRIMARY KEY (\`id\`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`) } /* eslint-disable @typescript-eslint/no-empty-function */ From 920b0f6d027a5fb362765a3044327741d1b80ed3 Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Mon, 8 May 2023 17:15:06 +0200 Subject: [PATCH 14/20] Update database/migrations/0066-x-community-sendcoins-transactions_table.ts Co-authored-by: Hannes Heine --- .../migrations/0066-x-community-sendcoins-transactions_table.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/database/migrations/0066-x-community-sendcoins-transactions_table.ts b/database/migrations/0066-x-community-sendcoins-transactions_table.ts index a56c6df00..10693bdba 100644 --- a/database/migrations/0066-x-community-sendcoins-transactions_table.ts +++ b/database/migrations/0066-x-community-sendcoins-transactions_table.ts @@ -88,5 +88,4 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom await queryFn('ALTER TABLE `transactions` DROP COLUMN `linked_user_gradido_id`;') await queryFn('ALTER TABLE `transactions` DROP COLUMN `linked_user_community_uuid`;') await queryFn('ALTER TABLE `transactions` DROP COLUMN `linked_user_name`;') - await queryFn(`DROP TABLE IF EXISTS pending_transactions;`) } From b87373947adbd7b047afbc9a80fc8a12e5770457 Mon Sep 17 00:00:00 2001 From: Claus-Peter Huebner Date: Tue, 9 May 2023 01:27:13 +0200 Subject: [PATCH 15/20] linting --- backend/src/util/utilities.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/util/utilities.ts b/backend/src/util/utilities.ts index df2166cfd..6bd70b941 100644 --- a/backend/src/util/utilities.ts +++ b/backend/src/util/utilities.ts @@ -18,4 +18,3 @@ export const decimalSeparatorByLanguage = (a: Decimal, language: string): string export const fullName = (firstName: string, lastName: string): string => { return [firstName, lastName].filter(Boolean).join(' ') } - From 864beb7914b7ab93fb0aa6aa6be89f60a7667b2e Mon Sep 17 00:00:00 2001 From: Claus-Peter Huebner Date: Tue, 9 May 2023 18:23:21 +0200 Subject: [PATCH 16/20] linting --- .../migrations/0066-x-community-sendcoins-transactions_table.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/database/migrations/0066-x-community-sendcoins-transactions_table.ts b/database/migrations/0066-x-community-sendcoins-transactions_table.ts index 10693bdba..62dd95f62 100644 --- a/database/migrations/0066-x-community-sendcoins-transactions_table.ts +++ b/database/migrations/0066-x-community-sendcoins-transactions_table.ts @@ -76,7 +76,6 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis await queryFn( `UPDATE transactions t, users u SET t.linked_user_gradido_id = u.gradido_id, t.linked_user_name = concat(u.first_name, ' ', u.last_name) WHERE t.linked_user_id = u.id and t.linked_user_id is null and t.linked_user_gradido_id is null;`, ) - } /* eslint-disable @typescript-eslint/no-empty-function */ From bcb08fc0fb222b38e59964f4014e79cb0be26a43 Mon Sep 17 00:00:00 2001 From: Claus-Peter Huebner Date: Tue, 9 May 2023 20:06:50 +0200 Subject: [PATCH 17/20] correct migration after test with production data --- .../migrations/0066-x-community-sendcoins-transactions_table.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/0066-x-community-sendcoins-transactions_table.ts b/database/migrations/0066-x-community-sendcoins-transactions_table.ts index 62dd95f62..65c21e0b5 100644 --- a/database/migrations/0066-x-community-sendcoins-transactions_table.ts +++ b/database/migrations/0066-x-community-sendcoins-transactions_table.ts @@ -74,7 +74,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis ) */ await queryFn( - `UPDATE transactions t, users u SET t.linked_user_gradido_id = u.gradido_id, t.linked_user_name = concat(u.first_name, ' ', u.last_name) WHERE t.linked_user_id = u.id and t.linked_user_id is null and t.linked_user_gradido_id is null;`, + `UPDATE transactions t, users u SET t.linked_user_gradido_id = u.gradido_id, t.linked_user_name = concat(u.first_name, ' ', u.last_name) WHERE t.linked_user_id = u.id and t.linked_user_gradido_id is null;`, ) } From 15f0d062ee45a2d96c0e0135cde2083a1a2f383d Mon Sep 17 00:00:00 2001 From: Claus-Peter Huebner Date: Wed, 10 May 2023 00:29:33 +0200 Subject: [PATCH 18/20] remove commented code --- .../0066-x-community-sendcoins-transactions_table.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/database/migrations/0066-x-community-sendcoins-transactions_table.ts b/database/migrations/0066-x-community-sendcoins-transactions_table.ts index 65c21e0b5..2a3b3973a 100644 --- a/database/migrations/0066-x-community-sendcoins-transactions_table.ts +++ b/database/migrations/0066-x-community-sendcoins-transactions_table.ts @@ -68,11 +68,6 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis await queryFn( 'ALTER TABLE `transactions` MODIFY COLUMN `user_gradido_id` char(36) NOT NULL AFTER `user_id`;', ) - /* - await queryFn( - 'ALTER TABLE `transactions` MODIFY COLUMN `user_name` varchar(512) COLLATE utf8mb4_unicode_ci NOT NULL AFTER `user_community_uuid`;', - ) - */ await queryFn( `UPDATE transactions t, users u SET t.linked_user_gradido_id = u.gradido_id, t.linked_user_name = concat(u.first_name, ' ', u.last_name) WHERE t.linked_user_id = u.id and t.linked_user_gradido_id is null;`, ) From 3c0dbe02f60860d0a240c83d4b4c9a984cea9392 Mon Sep 17 00:00:00 2001 From: clauspeterhuebner <86960882+clauspeterhuebner@users.noreply.github.com> Date: Thu, 11 May 2023 22:21:24 +0200 Subject: [PATCH 19/20] Update backend/src/util/utilities.ts Co-authored-by: Ulf Gebhardt --- backend/src/util/utilities.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/backend/src/util/utilities.ts b/backend/src/util/utilities.ts index 6bd70b941..64d92e981 100644 --- a/backend/src/util/utilities.ts +++ b/backend/src/util/utilities.ts @@ -15,6 +15,5 @@ export const decimalSeparatorByLanguage = (a: Decimal, language: string): string return result } -export const fullName = (firstName: string, lastName: string): string => { - return [firstName, lastName].filter(Boolean).join(' ') -} +export const fullName = (firstName: string, lastName: string): string => + [firstName, lastName].filter(Boolean).join(' ') From a380f385bdcefe22540a02e2caf15fff0f5c1592 Mon Sep 17 00:00:00 2001 From: Claus-Peter Huebner Date: Thu, 11 May 2023 22:52:21 +0200 Subject: [PATCH 20/20] remove community_uuids --- backend/src/util/virtualTransactions.ts | 4 ---- .../Transaction.ts | 18 ------------------ ...x-community-sendcoins-transactions_table.ts | 13 ++----------- 3 files changed, 2 insertions(+), 33 deletions(-) diff --git a/backend/src/util/virtualTransactions.ts b/backend/src/util/virtualTransactions.ts index 2bc2a591e..a10e566d1 100644 --- a/backend/src/util/virtualTransactions.ts +++ b/backend/src/util/virtualTransactions.ts @@ -55,10 +55,8 @@ const virtualLinkTransaction = ( contribution: null, ...defaultModelFunctions, userGradidoID: '', - userCommunityUuid: null, userName: null, linkedUserGradidoID: null, - linkedUserCommunityUuid: null, linkedUserName: null, } return new Transaction(linkDbTransaction, user) @@ -91,10 +89,8 @@ const virtualDecayTransaction = ( contribution: null, ...defaultModelFunctions, userGradidoID: '', - userCommunityUuid: null, userName: null, linkedUserGradidoID: null, - linkedUserCommunityUuid: null, linkedUserName: null, } return new Transaction(decayDbTransaction, user) diff --git a/database/entity/0066-x-community-sendcoins-transactions_table/Transaction.ts b/database/entity/0066-x-community-sendcoins-transactions_table/Transaction.ts index 9202f9fd3..4220cfadc 100644 --- a/database/entity/0066-x-community-sendcoins-transactions_table/Transaction.ts +++ b/database/entity/0066-x-community-sendcoins-transactions_table/Transaction.ts @@ -84,15 +84,6 @@ export class Transaction extends BaseEntity { }) userGradidoID: string - @Column({ - name: 'user_community_uuid', - type: 'varchar', - length: 36, - nullable: true, - collation: 'utf8mb4_unicode_ci', - }) - userCommunityUuid: string | null - @Column({ name: 'user_name', type: 'varchar', @@ -120,15 +111,6 @@ export class Transaction extends BaseEntity { }) linkedUserGradidoID: string | null - @Column({ - name: 'linked_user_community_uuid', - type: 'varchar', - length: 36, - nullable: true, - collation: 'utf8mb4_unicode_ci', - }) - linkedUserCommunityUuid: string | null - @Column({ name: 'linked_user_name', type: 'varchar', diff --git a/database/migrations/0066-x-community-sendcoins-transactions_table.ts b/database/migrations/0066-x-community-sendcoins-transactions_table.ts index 2a3b3973a..2a90f297a 100644 --- a/database/migrations/0066-x-community-sendcoins-transactions_table.ts +++ b/database/migrations/0066-x-community-sendcoins-transactions_table.ts @@ -41,10 +41,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis 'ALTER TABLE `transactions` ADD COLUMN `user_gradido_id` char(36) DEFAULT NULL NULL AFTER `user_id`;', ) await queryFn( - 'ALTER TABLE `transactions` ADD COLUMN `user_community_uuid` char(36) DEFAULT NULL NULL AFTER `user_gradido_id`;', - ) - await queryFn( - 'ALTER TABLE `transactions` ADD COLUMN `user_name` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL NULL AFTER `user_community_uuid`;', + 'ALTER TABLE `transactions` ADD COLUMN `user_name` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL NULL AFTER `user_gradido_id`;', ) await queryFn( 'ALTER TABLE `transactions` MODIFY COLUMN `linked_user_id` int(10) unsigned DEFAULT NULL NULL AFTER `user_name`;', @@ -53,15 +50,11 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis 'ALTER TABLE `transactions` ADD COLUMN `linked_user_gradido_id` char(36) DEFAULT NULL NULL AFTER `linked_user_id`;', ) await queryFn( - 'ALTER TABLE `transactions` ADD COLUMN `linked_user_community_uuid` char(36) DEFAULT NULL NULL AFTER `linked_user_gradido_id`;', - ) - await queryFn( - 'ALTER TABLE `transactions` ADD COLUMN `linked_user_name` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL NULL AFTER `linked_user_community_uuid`;', + 'ALTER TABLE `transactions` ADD COLUMN `linked_user_name` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL NULL AFTER `linked_user_gradido_id`;', ) await queryFn( 'ALTER TABLE `transactions` MODIFY COLUMN `linked_transaction_id` int(10) DEFAULT NULL NULL AFTER `linked_user_name`;', ) - await queryFn( `UPDATE transactions t, users u SET t.user_gradido_id = u.gradido_id, t.user_name = concat(u.first_name, ' ', u.last_name) WHERE t.user_id = u.id and t.user_gradido_id is null;`, ) @@ -77,9 +70,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis /* eslint-disable-next-line @typescript-eslint/no-unused-vars */ export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { await queryFn('ALTER TABLE `transactions` DROP COLUMN `user_gradido_id`;') - await queryFn('ALTER TABLE `transactions` DROP COLUMN `user_community_uuid`;') await queryFn('ALTER TABLE `transactions` DROP COLUMN `user_name`;') await queryFn('ALTER TABLE `transactions` DROP COLUMN `linked_user_gradido_id`;') - await queryFn('ALTER TABLE `transactions` DROP COLUMN `linked_user_community_uuid`;') await queryFn('ALTER TABLE `transactions` DROP COLUMN `linked_user_name`;') }