mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
TransactionTypeId to TypeId changed, *10000 removed, graphql refactor
This commit is contained in:
parent
289ca9115a
commit
38d53e61c0
@ -59,6 +59,7 @@ export default {
|
||||
},
|
||||
})
|
||||
.then((result) => {
|
||||
console.log('getTransactions', result.data)
|
||||
this.items = result.data.transactionList.transactions.filter((t) => t.type === 'creation')
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
@ -15,28 +15,25 @@ export const transactionList = gql`
|
||||
onlyCreations: $onlyCreations
|
||||
userId: $userId
|
||||
) {
|
||||
gdtSum
|
||||
balanceGDT
|
||||
count
|
||||
balance
|
||||
decay
|
||||
decayDate
|
||||
decayStartBlock
|
||||
transactions {
|
||||
type
|
||||
balance
|
||||
decayStart
|
||||
decayEnd
|
||||
decayDuration
|
||||
id
|
||||
typeId
|
||||
amount
|
||||
balanceDate
|
||||
memo
|
||||
transactionId
|
||||
name
|
||||
email
|
||||
date
|
||||
linkedUser {
|
||||
firstName
|
||||
lastName
|
||||
}
|
||||
decay {
|
||||
balance
|
||||
decayStart
|
||||
decayEnd
|
||||
decayDuration
|
||||
decayStartBlock
|
||||
decay
|
||||
start
|
||||
end
|
||||
duration
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { registerEnumType } from 'type-graphql'
|
||||
|
||||
export enum TransactionTypeId {
|
||||
export enum TypeId {
|
||||
CREATION = 1,
|
||||
SEND = 2,
|
||||
RECEIVE = 3,
|
||||
@ -8,7 +8,7 @@ export enum TransactionTypeId {
|
||||
DECAY = 4,
|
||||
}
|
||||
|
||||
registerEnumType(TransactionTypeId, {
|
||||
name: 'TransactionTypeId', // this one is mandatory
|
||||
registerEnumType(TypeId, {
|
||||
name: 'TypeId', // this one is mandatory
|
||||
description: 'Type of the transaction', // this one is optional
|
||||
})
|
||||
@ -4,7 +4,7 @@ import { ObjectType, Field } from 'type-graphql'
|
||||
import { Decay } from './Decay'
|
||||
import { Transaction as dbTransaction } from '@entity/Transaction'
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { TransactionTypeId } from '../enum/TransactionTypeId'
|
||||
import { TypeId } from '../enum/TypeId'
|
||||
import { User } from './User'
|
||||
|
||||
@ObjectType()
|
||||
@ -43,8 +43,8 @@ export class Transaction {
|
||||
@Field(() => Number, { nullable: true })
|
||||
previous: number | null
|
||||
|
||||
@Field(() => TransactionTypeId)
|
||||
typeId: TransactionTypeId
|
||||
@Field(() => TypeId)
|
||||
typeId: TypeId
|
||||
|
||||
@Field(() => Decimal)
|
||||
amount: Decimal
|
||||
|
||||
@ -26,7 +26,7 @@ import { AdminPendingCreation } from '@entity/AdminPendingCreation'
|
||||
import { hasElopageBuys } from '../../util/hasElopageBuys'
|
||||
import { LoginEmailOptIn } from '@entity/LoginEmailOptIn'
|
||||
import { User } from '@entity/User'
|
||||
import { TransactionTypeId } from '../enum/TransactionTypeId'
|
||||
import { TypeId } from '../enum/TypeId'
|
||||
import Decimal from 'decimal.js-light'
|
||||
|
||||
// const EMAIL_OPT_IN_REGISTER = 1
|
||||
@ -170,7 +170,7 @@ export class AdminResolver {
|
||||
if (isCreationValid(creations, amount, creationDateObj)) {
|
||||
const adminPendingCreation = AdminPendingCreation.create()
|
||||
adminPendingCreation.userId = user.id
|
||||
adminPendingCreation.amount = BigInt(amount * 10000)
|
||||
adminPendingCreation.amount = BigInt(amount)
|
||||
adminPendingCreation.created = new Date()
|
||||
adminPendingCreation.date = creationDateObj
|
||||
adminPendingCreation.memo = memo
|
||||
@ -235,7 +235,7 @@ export class AdminResolver {
|
||||
if (!isCreationValid(creations, amount, creationDateObj)) {
|
||||
throw new Error('Creation is not valid')
|
||||
}
|
||||
pendingCreationToUpdate.amount = BigInt(amount * 10000)
|
||||
pendingCreationToUpdate.amount = BigInt(amount)
|
||||
pendingCreationToUpdate.memo = memo
|
||||
pendingCreationToUpdate.date = new Date(creationDate)
|
||||
pendingCreationToUpdate.moderator = moderator
|
||||
@ -321,7 +321,7 @@ export class AdminResolver {
|
||||
newBalance = newBalance.add(new Decimal(Number(pendingCreation.amount)))
|
||||
|
||||
const transaction = new Transaction()
|
||||
transaction.typeId = TransactionTypeId.CREATION
|
||||
transaction.typeId = TypeId.CREATION
|
||||
transaction.memo = pendingCreation.memo
|
||||
transaction.userId = pendingCreation.userId
|
||||
// TODO pending creations decimal
|
||||
@ -367,7 +367,7 @@ async function getUserCreations(ids: number[], includePending = true): Promise<C
|
||||
SELECT MONTH(date) AS month, sum(amount) AS sum, userId AS id FROM
|
||||
(SELECT creation_date AS date, amount AS amount, user_id AS userId FROM transactions
|
||||
WHERE user_id IN (${ids.toString()})
|
||||
AND transaction_type_id = ${TransactionTypeId.CREATION}
|
||||
AND type_id = ${TypeId.CREATION}
|
||||
AND creation_date >= ${dateFilter}
|
||||
${unionString}) AS result
|
||||
GROUP BY month, userId
|
||||
|
||||
@ -24,7 +24,7 @@ import { User as dbUser } from '@entity/User'
|
||||
import { Transaction as dbTransaction } from '@entity/Transaction'
|
||||
|
||||
import { apiPost } from '../../apis/HttpRequest'
|
||||
import { TransactionTypeId } from '../enum/TransactionTypeId'
|
||||
import { TypeId } from '../enum/TypeId'
|
||||
import { calculateBalance, isHexPublicKey } from '../../util/validate'
|
||||
import { RIGHTS } from '../../auth/RIGHTS'
|
||||
import { User } from '../model/User'
|
||||
@ -111,7 +111,7 @@ export class TransactionResolver {
|
||||
for (let i = 0; i < userTransactions.length; i++) {
|
||||
const userTransaction = userTransactions[i]
|
||||
let linkedUser = null
|
||||
if (userTransaction.typeId === TransactionTypeId.CREATION) {
|
||||
if (userTransaction.typeId === TypeId.CREATION) {
|
||||
linkedUser = communityUser
|
||||
} else {
|
||||
linkedUser = involvedUsers.find((u) => u.id === userTransaction.linkedUserId)
|
||||
@ -180,7 +180,7 @@ export class TransactionResolver {
|
||||
try {
|
||||
// transaction
|
||||
const transactionSend = new dbTransaction()
|
||||
transactionSend.typeId = TransactionTypeId.SEND
|
||||
transactionSend.typeId = TypeId.SEND
|
||||
transactionSend.memo = memo
|
||||
transactionSend.userId = senderUser.id
|
||||
transactionSend.linkedUserId = recipientUser.id
|
||||
@ -193,7 +193,7 @@ export class TransactionResolver {
|
||||
await queryRunner.manager.insert(dbTransaction, transactionSend)
|
||||
|
||||
const transactionReceive = new dbTransaction()
|
||||
transactionReceive.typeId = TransactionTypeId.RECEIVE
|
||||
transactionReceive.typeId = TypeId.RECEIVE
|
||||
transactionReceive.memo = memo
|
||||
transactionReceive.userId = recipientUser.id
|
||||
transactionReceive.linkedUserId = senderUser.id
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { EntityRepository, Repository } from '@dbTools/typeorm'
|
||||
import { Transaction } from '@entity/Transaction'
|
||||
import { Order } from '../../graphql/enum/Order'
|
||||
import { TransactionTypeId } from '../../graphql/enum/TransactionTypeId'
|
||||
import { TypeId } from '../../graphql/enum/TypeId'
|
||||
|
||||
@EntityRepository(Transaction)
|
||||
export class TransactionRepository extends Repository<Transaction> {
|
||||
@ -15,8 +15,8 @@ export class TransactionRepository extends Repository<Transaction> {
|
||||
if (onlyCreation) {
|
||||
return this.createQueryBuilder('userTransaction')
|
||||
.where('userTransaction.userId = :userId', { userId })
|
||||
.andWhere('userTransaction.transactionTypeId = :transactionTypeId', {
|
||||
transactionTypeId: TransactionTypeId.CREATION,
|
||||
.andWhere('userTransaction.typeId = :typeId', {
|
||||
typeId: TypeId.CREATION,
|
||||
})
|
||||
.orderBy('userTransaction.balanceDate', order)
|
||||
.limit(limit)
|
||||
|
||||
@ -3,7 +3,7 @@ import Decimal from 'decimal.js-light'
|
||||
import { SaveOptions, RemoveOptions } from '@dbTools/typeorm'
|
||||
import { Transaction as dbTransaction } from '@entity/Transaction'
|
||||
import { calculateDecay } from './decay'
|
||||
import { TransactionTypeId } from '../graphql/enum/TransactionTypeId'
|
||||
import { TypeId } from '../graphql/enum/TypeId'
|
||||
import { Transaction } from '../graphql/model/Transaction'
|
||||
import { User } from '../graphql/model/User'
|
||||
|
||||
@ -19,7 +19,7 @@ const virtualDecayTransaction = (
|
||||
id: -1,
|
||||
userId: -1,
|
||||
previous: -1,
|
||||
typeId: TransactionTypeId.DECAY,
|
||||
typeId: TypeId.DECAY,
|
||||
amount: decay.decay ? decay.decay : new Decimal(0), // new Decimal(0), // this kinda is wrong, but helps with the frontend query
|
||||
balance: decay.balance,
|
||||
balanceDate: time,
|
||||
|
||||
@ -10,8 +10,8 @@ export class Transaction extends BaseEntity {
|
||||
@Column({ name: 'state_group_id', unsigned: true, default: null })
|
||||
stateGroupId: number
|
||||
|
||||
@Column({ name: 'transaction_type_id', unsigned: true, nullable: false })
|
||||
transactionTypeId: number
|
||||
@Column({ name: 'type_id', unsigned: true, nullable: false })
|
||||
typeId: number
|
||||
|
||||
@Column({ name: 'tx_hash', type: 'binary', length: 48, default: null })
|
||||
txHash: Buffer
|
||||
|
||||
@ -11,8 +11,8 @@ export class UserTransaction extends BaseEntity {
|
||||
@Column({ name: 'transaction_id' })
|
||||
transactionId: number
|
||||
|
||||
@Column({ name: 'transaction_type_id' })
|
||||
transactionTypeId: number
|
||||
@Column({ name: 'type_id' })
|
||||
typeId: number
|
||||
|
||||
@Column({ name: 'balance', type: 'bigint' })
|
||||
balance: number
|
||||
|
||||
@ -8,8 +8,8 @@ export class Transaction extends BaseEntity {
|
||||
@PrimaryGeneratedColumn('increment', { unsigned: true })
|
||||
id: number
|
||||
|
||||
@Column({ name: 'transaction_type_id', unsigned: true, nullable: false })
|
||||
transactionTypeId: number
|
||||
@Column({ name: 'type_id', unsigned: true, nullable: false })
|
||||
typeId: number
|
||||
|
||||
@Column({ name: 'tx_hash', type: 'binary', length: 48, default: null })
|
||||
txHash: Buffer
|
||||
|
||||
@ -6,8 +6,8 @@ export class Transaction extends BaseEntity {
|
||||
@PrimaryGeneratedColumn('increment', { unsigned: true })
|
||||
id: number
|
||||
|
||||
@Column({ name: 'transaction_type_id', unsigned: true, nullable: false })
|
||||
transactionTypeId: number
|
||||
@Column({ name: 'type_id', unsigned: true, nullable: false })
|
||||
typeId: number
|
||||
|
||||
@Column({ name: 'user_id', unsigned: true, nullable: false })
|
||||
userId: number
|
||||
|
||||
@ -11,8 +11,8 @@ export class Transaction extends BaseEntity {
|
||||
@Column({ name: 'transaction_id', unsigned: true, nullable: false })
|
||||
transactionId: number
|
||||
|
||||
@Column({ name: 'transaction_type_id', unsigned: true, nullable: false })
|
||||
transactionTypeId: number
|
||||
@Column({ name: 'type_id', unsigned: true, nullable: false })
|
||||
typeId: number
|
||||
|
||||
@Column({ type: 'bigint', nullable: false })
|
||||
amount: BigInt
|
||||
|
||||
@ -140,7 +140,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
CREATE TABLE IF NOT EXISTS \`state_errors\` (
|
||||
\`id\` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`state_user_id\` int(10) unsigned NOT NULL,
|
||||
\`transaction_type_id\` int(10) unsigned NOT NULL,
|
||||
\`type_id\` int(10) unsigned NOT NULL,
|
||||
\`created\` datetime NOT NULL,
|
||||
\`message_json\` text COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
PRIMARY KEY (\`id\`)
|
||||
@ -196,7 +196,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
\`id\` int UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
\`state_user_id\` int UNSIGNED NOT NULL,
|
||||
\`transaction_id\` int UNSIGNED NOT NULL,
|
||||
\`transaction_type_id\` int UNSIGNED NOT NULL,
|
||||
\`type_id\` int UNSIGNED NOT NULL,
|
||||
\`balance\` bigint(20) DEFAULT 0,
|
||||
\`balance_date\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (\`id\`)
|
||||
@ -304,7 +304,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
CREATE TABLE IF NOT EXISTS \`transactions\` (
|
||||
\`id\` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`state_group_id\` int(10) unsigned DEFAULT NULL,
|
||||
\`transaction_type_id\` int(10) unsigned NOT NULL,
|
||||
\`type_id\` int(10) unsigned NOT NULL,
|
||||
\`tx_hash\` binary(48) DEFAULT NULL,
|
||||
\`memo\` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
\`received\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
@ -292,7 +292,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
||||
CREATE TABLE \`state_errors\` (
|
||||
\`id\` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`state_user_id\` int(10) unsigned NOT NULL,
|
||||
\`transaction_type_id\` int(10) unsigned NOT NULL,
|
||||
\`type_id\` int(10) unsigned NOT NULL,
|
||||
\`created\` datetime NOT NULL,
|
||||
\`message_json\` text COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
PRIMARY KEY (\`id\`)
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
// Remove transactions with type 9 (start decay block). This should affect exactly 1 row
|
||||
await queryFn(`DELETE FROM transactions WHERE transaction_type_id = 9;`)
|
||||
await queryFn(`DELETE FROM transactions WHERE type_id = 9;`)
|
||||
}
|
||||
|
||||
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
// Create new `user_id` column (former `state_user_id`), with a temporary default of null
|
||||
await queryFn(
|
||||
'ALTER TABLE `transactions` ADD COLUMN `user_id` int(10) unsigned DEFAULT NULL AFTER `transaction_type_id`;',
|
||||
'ALTER TABLE `transactions` ADD COLUMN `user_id` int(10) unsigned DEFAULT NULL AFTER `type_id`;',
|
||||
)
|
||||
// Create new `amount` column, with a temporary default of null
|
||||
await queryFn(
|
||||
@ -105,7 +105,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
||||
send_receiver_public_key AS receiver_public_key, send_receiver_user_id AS receiver_user_id,
|
||||
amount, send_sender_final_balance AS sender_final_balance
|
||||
FROM transactions
|
||||
WHERE transaction_type_id = 2 );
|
||||
WHERE type_id = 2 );
|
||||
`)
|
||||
|
||||
await queryFn(`
|
||||
@ -115,7 +115,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
||||
( SELECT id AS transaction_id, user_id AS state_user_id,
|
||||
amount, creation_ident_hash AS ident_hash, creation_date AS target_date
|
||||
FROM transactions
|
||||
WHERE transaction_type_id = 1 );
|
||||
WHERE type_id = 1 );
|
||||
`)
|
||||
|
||||
await queryFn('ALTER TABLE `transactions` DROP COLUMN `send_sender_final_balance`;')
|
||||
|
||||
@ -31,7 +31,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
await queryFn('ALTER TABLE `state_user_transactions` RENAME COLUMN state_user_id TO user_id;')
|
||||
// Create new `amount` column, with a temporary default of null
|
||||
await queryFn(
|
||||
'ALTER TABLE `state_user_transactions` ADD COLUMN `amount` bigint(20) DEFAULT NULL AFTER `transaction_type_id`;',
|
||||
'ALTER TABLE `state_user_transactions` ADD COLUMN `amount` bigint(20) DEFAULT NULL AFTER `type_id`;',
|
||||
)
|
||||
// Create new `send_sender_final_balance`
|
||||
await queryFn(
|
||||
@ -89,7 +89,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
state_user_transactions.signature = transactions.signature,
|
||||
state_user_transactions.pubkey = transactions.pubkey,
|
||||
state_user_transactions.creation_ident_hash = transactions.creation_ident_hash
|
||||
WHERE state_user_transactions.transaction_type_id = 1;
|
||||
WHERE state_user_transactions.type_id = 1;
|
||||
`)
|
||||
|
||||
// Insert Data from `transactions` for sendCoin sender
|
||||
@ -104,7 +104,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
state_user_transactions.linked_user_id = transactions.send_receiver_user_id,
|
||||
state_user_transactions.linked_state_user_transaction_id = (
|
||||
SELECT id FROM state_user_transactions AS sut
|
||||
WHERE sut.transaction_type_id = 2
|
||||
WHERE sut.type_id = 2
|
||||
AND sut.transaction_id = state_user_transactions.transaction_id
|
||||
AND sut.user_id = transactions.send_receiver_user_id
|
||||
),
|
||||
@ -112,7 +112,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
state_user_transactions.signature = transactions.signature,
|
||||
state_user_transactions.pubkey = transactions.pubkey,
|
||||
state_user_transactions.creation_ident_hash = transactions.creation_ident_hash
|
||||
WHERE state_user_transactions.transaction_type_id = 2
|
||||
WHERE state_user_transactions.type_id = 2
|
||||
AND state_user_transactions.user_id = transactions.user_id;
|
||||
`)
|
||||
|
||||
@ -128,7 +128,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
state_user_transactions.linked_user_id = transactions.user_id,
|
||||
state_user_transactions.linked_state_user_transaction_id = (
|
||||
SELECT id FROM state_user_transactions AS sut
|
||||
WHERE sut.transaction_type_id = 2
|
||||
WHERE sut.type_id = 2
|
||||
AND sut.transaction_id = state_user_transactions.transaction_id
|
||||
AND sut.user_id = transactions.user_id
|
||||
),
|
||||
@ -136,8 +136,8 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
state_user_transactions.signature = transactions.signature,
|
||||
state_user_transactions.pubkey = transactions.send_receiver_public_key,
|
||||
state_user_transactions.creation_ident_hash = transactions.creation_ident_hash,
|
||||
state_user_transactions.transaction_type_id = 3
|
||||
WHERE state_user_transactions.transaction_type_id = 2
|
||||
state_user_transactions.type_id = 3
|
||||
WHERE state_user_transactions.type_id = 2
|
||||
AND state_user_transactions.user_id = transactions.send_receiver_user_id;
|
||||
`)
|
||||
|
||||
@ -161,7 +161,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
||||
await queryFn('RENAME TABLE `transactions` TO `state_user_transactions`;')
|
||||
await queryFn(`CREATE TABLE \`transactions\` (
|
||||
\`id\` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`transaction_type_id\` int(10) unsigned NOT NULL,
|
||||
\`type_id\` int(10) unsigned NOT NULL,
|
||||
\`user_id\` int(10) unsigned NOT NULL,
|
||||
\`amount\` bigint(20) NOT NULL,
|
||||
\`tx_hash\` binary(48) DEFAULT NULL,
|
||||
@ -179,13 +179,13 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
||||
`)
|
||||
await queryFn(`
|
||||
INSERT INTO transactions (
|
||||
id, transaction_type_id, user_id, amount,
|
||||
id, type_id, user_id, amount,
|
||||
tx_hash, memo, received, signature, pubkey,
|
||||
creation_ident_hash, creation_date,
|
||||
send_receiver_public_key, send_receiver_user_id,
|
||||
send_sender_final_balance
|
||||
)
|
||||
SELECT transaction_id AS id, transaction_type_id,
|
||||
SELECT transaction_id AS id, type_id,
|
||||
user_id, amount, tx_hash, memo, received,
|
||||
signature, pubkey, creation_ident_hash,
|
||||
creation_date, send_receiver_public_key,
|
||||
@ -194,12 +194,12 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
||||
FROM state_user_transactions LEFT JOIN (
|
||||
SELECT id, pubkey AS send_receiver_public_key
|
||||
FROM state_user_transactions AS sut
|
||||
WHERE sut.transaction_type_id = 3
|
||||
WHERE sut.type_id = 3
|
||||
) AS sutj ON sutj.id = state_user_transactions.id
|
||||
WHERE transaction_type_id IN (1,2)
|
||||
WHERE type_id IN (1,2)
|
||||
`)
|
||||
await queryFn(
|
||||
'UPDATE state_user_transactions SET transaction_type_id = 2 WHERE transaction_type_id = 3;',
|
||||
'UPDATE state_user_transactions SET type_id = 2 WHERE type_id = 3;',
|
||||
)
|
||||
await queryFn('ALTER TABLE `state_user_transactions` DROP COLUMN `creation_ident_hash`;')
|
||||
await queryFn('ALTER TABLE `state_user_transactions` DROP COLUMN `pubkey`;')
|
||||
|
||||
@ -23,8 +23,8 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
// drop column `creation_ident_hash`, it is not needed
|
||||
await queryFn('ALTER TABLE `transactions` DROP COLUMN `creation_ident_hash`;')
|
||||
|
||||
// rename `transaction_type_id` to `type_id`
|
||||
await queryFn('ALTER TABLE `transactions` RENAME COLUMN transaction_type_id TO type_id;')
|
||||
// rename `type_id` to `type_id`
|
||||
await queryFn('ALTER TABLE `transactions` RENAME COLUMN type_id TO type_id;')
|
||||
// rename `linked_state_user_transaction_id` to `linked_transaction_id`
|
||||
await queryFn(
|
||||
'ALTER TABLE `transactions` RENAME COLUMN linked_state_user_transaction_id TO linked_transaction_id;',
|
||||
@ -43,7 +43,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
||||
await queryFn(
|
||||
'ALTER TABLE `transactions` RENAME COLUMN linked_transaction_id TO linked_state_user_transaction_id;',
|
||||
)
|
||||
await queryFn('ALTER TABLE `transactions` RENAME COLUMN type_id TO transaction_type_id;')
|
||||
await queryFn('ALTER TABLE `transactions` RENAME COLUMN type_id TO type_id;')
|
||||
await queryFn(
|
||||
'ALTER TABLE `transactions` ADD COLUMN `creation_ident_hash` binary(32) DEFAULT NULL AFTER `linked_state_user_transaction_id`;',
|
||||
)
|
||||
|
||||
@ -40,7 +40,7 @@ interface Decay {
|
||||
duration: number | null
|
||||
}
|
||||
|
||||
export enum TransactionTypeId {
|
||||
export enum TypeId {
|
||||
CREATION = 1,
|
||||
SEND = 2,
|
||||
RECEIVE = 3,
|
||||
@ -162,7 +162,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
|
||||
// This should also fix the rounding error on amount
|
||||
let decAmount = new Decimal(transaction.amount).dividedBy(10000).toDecimalPlaces(2)
|
||||
if (transaction.type_id === TransactionTypeId.SEND) {
|
||||
if (transaction.type_id === TypeId.SEND) {
|
||||
decAmount = decAmount.mul(-1)
|
||||
}
|
||||
const decayStartDate = previous ? previous.balance_date : transaction.balance_date
|
||||
|
||||
@ -61,7 +61,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
||||
await queryFn(`
|
||||
INSERT INTO \`state_balances\`
|
||||
(state_user_id, modified, record_date, amount)
|
||||
SELECT user_id as state_user_id, balance_date as modified, balance_date as record_date, amount * 10000 as amount FROM
|
||||
SELECT user_id as state_user_id, balance_date as modified, balance_date as record_date, amount as amount FROM
|
||||
(SELECT user_id as uid, MAX(balance_date) AS date FROM transactions GROUP BY uid) AS t
|
||||
LEFT JOIN transactions ON t.uid = transactions.user_id AND t.date = transactions.balance_date;
|
||||
`)
|
||||
@ -96,9 +96,9 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
||||
temp_dec_old_balance = dec_balance,
|
||||
temp_dec_diff_send_sender_final_balance = 0,
|
||||
temp_dec_send_sender_final_balance = dec_balance,
|
||||
balance = dec_balance * 10000,
|
||||
send_sender_final_balance = dec_balance * 10000,
|
||||
amount = dec_amount * 10000;
|
||||
balance = dec_balance,
|
||||
send_sender_final_balance = dec_balance,
|
||||
amount = dec_amount;
|
||||
`)
|
||||
|
||||
await queryFn('ALTER TABLE `transactions` MODIFY COLUMN `amount` bigint(20) NOT NULL;')
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -126,7 +126,7 @@ CREATE TABLE `state_created` (
|
||||
CREATE TABLE `state_errors` (
|
||||
`id` int(11) NOT NULL,
|
||||
`state_user_id` int(11) NOT NULL,
|
||||
`transaction_type_id` int(11) NOT NULL,
|
||||
`type_id` int(11) NOT NULL,
|
||||
`created` datetime NOT NULL,
|
||||
`message_json` text NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
@ -194,7 +194,7 @@ CREATE TABLE `state_users` (
|
||||
CREATE TABLE `transactions` (
|
||||
`id` bigint(20) NOT NULL,
|
||||
`group_id` int(11) NOT NULL,
|
||||
`transaction_type_id` int(11) NOT NULL,
|
||||
`type_id` int(11) NOT NULL,
|
||||
`tx_hash` binary(32) NOT NULL,
|
||||
`memo` varchar(255) COLLATE utf8_bin NOT NULL,
|
||||
`received` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
|
||||
@ -126,7 +126,7 @@ CREATE TABLE `state_created` (
|
||||
CREATE TABLE `state_errors` (
|
||||
`id` int(11) NOT NULL,
|
||||
`state_user_id` int(11) NOT NULL,
|
||||
`transaction_type_id` int(11) NOT NULL,
|
||||
`type_id` int(11) NOT NULL,
|
||||
`created` datetime NOT NULL,
|
||||
`message_json` text NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
@ -194,7 +194,7 @@ CREATE TABLE `state_users` (
|
||||
CREATE TABLE `transactions` (
|
||||
`id` bigint(20) NOT NULL,
|
||||
`group_id` int(11) NOT NULL,
|
||||
`transaction_type_id` int(11) NOT NULL,
|
||||
`type_id` int(11) NOT NULL,
|
||||
`tx_hash` binary(32) NOT NULL,
|
||||
`memo` varchar(255) COLLATE utf8_bin NOT NULL,
|
||||
`received` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
|
||||
@ -27,7 +27,7 @@ state_users
|
||||
id index group_id public_key email first_name last_name
|
||||
|
||||
state_errors
|
||||
id state_user_id transaction_type_id created message_json
|
||||
id state_user_id type_id created message_json
|
||||
|
||||
state_balances
|
||||
id state_user_id modified amount
|
||||
@ -48,7 +48,7 @@ id transaction_id signature pubkey
|
||||
|
||||
transactions
|
||||
int64
|
||||
id state_group_id transaction_type_id tx_hash received
|
||||
id state_group_id type_id tx_hash received
|
||||
|
||||
transaction_send_coins
|
||||
id transaction_id state_user_id receiver_public receiver_user_id amount sender_final_balance
|
||||
|
||||
@ -8,7 +8,7 @@ id transaction_id signature pubkey
|
||||
|
||||
transactions
|
||||
int64
|
||||
id group_id timestamp transaction_type_id hash received
|
||||
id group_id timestamp type_id hash received
|
||||
|
||||
transaction_bins
|
||||
id transaction_id filename start size
|
||||
@ -16,5 +16,5 @@ id transaction_id filename start size
|
||||
state_created
|
||||
id transaction_id month year short_ident_hash
|
||||
|
||||
Für mehr Performance, jeweils eine transactions, transaction_bins und transaction_signatures
|
||||
F<EFBFBD>r mehr Performance, jeweils eine transactions, transaction_bins und transaction_signatures
|
||||
Tabelle pro Gruppe
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
CREATE TABLE `transactions` (
|
||||
`id` bigint(20) NOT NULL,
|
||||
`state_group_id` int(11) NOT NULL,
|
||||
`transaction_type_id` int(11) NOT NULL,
|
||||
`type_id` int(11) NOT NULL,
|
||||
`tx_hash` binary(32) NOT NULL,
|
||||
`received` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`)
|
||||
|
||||
@ -122,7 +122,7 @@ export default {
|
||||
},
|
||||
computed: {
|
||||
duration() {
|
||||
return this.$moment.duration((this.decay.end - this.decay.start) * 1000)._data
|
||||
return this.$moment.duration(this.decay.end - this.decay.start)._data
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user