mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
updated entity & decimal transformer
This commit is contained in:
parent
4cfee1ce38
commit
eb7a9299fd
146
database/entity/0027-decimal_types/Transaction.ts
Normal file
146
database/entity/0027-decimal_types/Transaction.ts
Normal file
@ -0,0 +1,146 @@
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column } from 'typeorm'
|
||||
import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer'
|
||||
|
||||
@Entity('transactions')
|
||||
export class Transaction extends BaseEntity {
|
||||
@PrimaryGeneratedColumn('increment', { unsigned: true })
|
||||
id: number
|
||||
|
||||
@Column({ name: 'user_id', unsigned: true, nullable: false })
|
||||
userId: number
|
||||
|
||||
@Column({ unsigned: true, nullable: true, default: null })
|
||||
previous: number
|
||||
|
||||
@Column({ name: 'type_id', unsigned: true, nullable: false })
|
||||
typeId: number
|
||||
|
||||
@Column({
|
||||
name: 'dec_amount',
|
||||
type: 'decimal',
|
||||
precision: 40,
|
||||
scale: 20,
|
||||
nullable: false,
|
||||
transformer: DecimalTransformer,
|
||||
})
|
||||
decAmount: Decimal
|
||||
|
||||
@Column({
|
||||
name: 'dec_balance',
|
||||
type: 'decimal',
|
||||
precision: 40,
|
||||
scale: 20,
|
||||
nullable: false,
|
||||
transformer: DecimalTransformer,
|
||||
})
|
||||
decBalance: Decimal
|
||||
|
||||
@Column({
|
||||
name: 'balance_date',
|
||||
type: 'datetime',
|
||||
default: () => 'CURRENT_TIMESTAMP',
|
||||
nullable: false,
|
||||
})
|
||||
balanceDate: Date
|
||||
|
||||
@Column({
|
||||
name: 'dec_decay',
|
||||
type: 'decimal',
|
||||
precision: 40,
|
||||
scale: 20,
|
||||
nullable: false,
|
||||
transformer: DecimalTransformer,
|
||||
})
|
||||
decDecay: Decimal
|
||||
|
||||
@Column({
|
||||
name: 'decay_start',
|
||||
type: 'datetime',
|
||||
nullable: true,
|
||||
default: null,
|
||||
})
|
||||
decayStart: Date | null
|
||||
|
||||
@Column({ type: 'bigint', nullable: false })
|
||||
amount: BigInt
|
||||
|
||||
@Column({ length: 255, nullable: false, collation: 'utf8mb4_unicode_ci' })
|
||||
memo: string
|
||||
|
||||
@Column({
|
||||
name: 'send_sender_final_balance',
|
||||
type: 'bigint',
|
||||
nullable: true,
|
||||
default: null,
|
||||
})
|
||||
sendSenderFinalBalance: BigInt | null
|
||||
|
||||
@Column({ name: 'balance', type: 'bigint', default: 0 })
|
||||
balance: BigInt
|
||||
|
||||
@Column({ name: 'creation_date', type: 'timestamp', nullable: true, default: null })
|
||||
creationDate: Date
|
||||
|
||||
@Column({
|
||||
name: 'linked_user_id',
|
||||
type: 'int',
|
||||
unsigned: true,
|
||||
nullable: true,
|
||||
default: null,
|
||||
})
|
||||
linkedUserId?: number | null
|
||||
|
||||
@Column({
|
||||
name: 'linked_transaction_id',
|
||||
type: 'int',
|
||||
unsigned: true,
|
||||
nullable: true,
|
||||
default: null,
|
||||
})
|
||||
linkedTransactionId?: number | null
|
||||
|
||||
@Column({
|
||||
name: 'temp_dec_send_sender_final_balance',
|
||||
type: 'decimal',
|
||||
precision: 40,
|
||||
scale: 20,
|
||||
nullable: true,
|
||||
default: null,
|
||||
transformer: DecimalTransformer,
|
||||
})
|
||||
tempDecSendSenderFinalBalance: Decimal
|
||||
|
||||
@Column({
|
||||
name: 'temp_dec_diff_send_sender_final_balance',
|
||||
type: 'decimal',
|
||||
precision: 40,
|
||||
scale: 20,
|
||||
nullable: true,
|
||||
default: null,
|
||||
transformer: DecimalTransformer,
|
||||
})
|
||||
tempDecDiffSendSenderFinalBalance: Decimal
|
||||
|
||||
@Column({
|
||||
name: 'temp_dec_old_balance',
|
||||
type: 'decimal',
|
||||
precision: 40,
|
||||
scale: 20,
|
||||
nullable: true,
|
||||
default: null,
|
||||
transformer: DecimalTransformer,
|
||||
})
|
||||
tempDecOldBalance: Decimal
|
||||
|
||||
@Column({
|
||||
name: 'temp_dec_diff_balance',
|
||||
type: 'decimal',
|
||||
precision: 40,
|
||||
scale: 20,
|
||||
nullable: true,
|
||||
default: null,
|
||||
transformer: DecimalTransformer,
|
||||
})
|
||||
tempDecDiffBalance: Decimal
|
||||
}
|
||||
@ -1 +1 @@
|
||||
export { Transaction } from './0026-clean_transaction_table/Transaction'
|
||||
export { Transaction } from './0027-decimal_types/Transaction'
|
||||
|
||||
14
database/src/typeorm/DecimalTransformer.ts
Normal file
14
database/src/typeorm/DecimalTransformer.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { ValueTransformer } from 'typeorm'
|
||||
|
||||
export const DecimalTransformer: ValueTransformer = {
|
||||
/**
|
||||
* Used to marshal Decimal when writing to the database.
|
||||
*/
|
||||
to: (decimal: Decimal | null): string | null => (decimal ? decimal.toString() : null),
|
||||
|
||||
/**
|
||||
* Used to unmarshal Decimal when reading from the database.
|
||||
*/
|
||||
from: (decimal: string | null): Decimal | null => (decimal ? new Decimal(decimal) : null),
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user