Merge pull request #1584 from gradido/model-transaction-link

feat: Model Transaction Link
This commit is contained in:
Moriz Wahl 2022-03-09 17:23:26 +01:00 committed by GitHub
commit 8211538d6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 143 additions and 2 deletions

View File

@ -10,7 +10,7 @@ Decimal.set({
})
const constants = {
DB_VERSION: '0029-clean_transaction_table',
DB_VERSION: '0030-transaction_link',
DECAY_START_TIME: new Date('2021-05-13 17:46:31'), // GMT+0
}

View File

@ -0,0 +1,42 @@
import { ObjectType, Field } from 'type-graphql'
import Decimal from 'decimal.js-light'
import { User } from './User'
@ObjectType()
export class TransactionLink {
@Field(() => Number)
id: number
@Field(() => User)
user: User
@Field(() => Decimal)
amount: Decimal
@Field(() => Decimal)
holdAvailableAmount: Decimal
@Field(() => String)
memo: string
@Field(() => String)
code: string
@Field(() => Date)
createdAt: Date
@Field(() => Date, { nullable: true })
deletedAt: Date | null
@Field(() => Date)
validUntil: Date
@Field(() => Boolean)
showEmail: boolean
@Field(() => Date, { nullable: true })
redeemedAt: Date | null
@Field(() => User, { nullable: true })
redeemedBy: User | null
}

View File

@ -12,7 +12,7 @@ import CONFIG from '@/config'
import { sendAccountActivationEmail } from '@/mailer/sendAccountActivationEmail'
// import { klicktippSignIn } from '@/apis/KlicktippController'
jest.setTimeout(10000)
jest.setTimeout(1000000)
jest.mock('@/mailer/sendAccountActivationEmail', () => {
return {

View File

@ -0,0 +1,68 @@
import Decimal from 'decimal.js-light'
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, DeleteDateColumn } from 'typeorm'
import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer'
@Entity('transaction_links')
export class TransactionLink extends BaseEntity {
@PrimaryGeneratedColumn('increment', { unsigned: true })
id: number
@Column({ unsigned: true, nullable: false })
userId: number
@Column({
type: 'decimal',
precision: 40,
scale: 20,
nullable: false,
transformer: DecimalTransformer,
})
amount: Decimal
@Column({
type: 'decimal',
name: 'hold_available_amount',
precision: 40,
scale: 20,
nullable: false,
transformer: DecimalTransformer,
})
holdAvailableAmount: Decimal
@Column({ length: 255, nullable: false, collation: 'utf8mb4_unicode_ci' })
memo: string
@Column({ length: 24, nullable: false, collation: 'utf8mb4_unicode_ci' })
code: string
@Column({
type: 'datetime',
nullable: false,
})
createdAt: Date
@DeleteDateColumn()
deletedAt?: Date | null
@Column({
type: 'datetime',
nullable: false,
})
validUntil: Date
@Column({
type: 'boolean',
default: () => false,
nullable: false,
})
showEmail: boolean
@Column({
type: 'datetime',
nullable: true,
})
redeemedAt?: Date | null
@Column({ type: 'int', unsigned: true, nullable: true })
redeemedBy?: number | null
}

View File

@ -0,0 +1 @@
export { TransactionLink } from './0030-transaction_link/TransactionLink'

View File

@ -3,6 +3,7 @@ import { LoginEmailOptIn } from './LoginEmailOptIn'
import { Migration } from './Migration'
import { ServerUser } from './ServerUser'
import { Transaction } from './Transaction'
import { TransactionLink } from './TransactionLink'
import { User } from './User'
import { UserSetting } from './UserSetting'
import { AdminPendingCreation } from './AdminPendingCreation'
@ -14,6 +15,7 @@ export const entities = [
Migration,
ServerUser,
Transaction,
TransactionLink,
User,
UserSetting,
]

View File

@ -0,0 +1,28 @@
/* MIGRATION TO CREATE TRANSACTION_LINK TABLE */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable @typescript-eslint/no-explicit-any */
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
await queryFn(`
CREATE TABLE \`transaction_links\` (
\`id\` int UNSIGNED NOT NULL AUTO_INCREMENT,
\`userId\` int UNSIGNED NOT NULL,
\`amount\` DECIMAL(40,20) NOT NULL,
\`hold_available_amount\` DECIMAL(40,20) NOT NULL,
\`memo\` varchar(255) NOT NULL,
\`code\` varchar(24) NOT NULL,
\`createdAt\` datetime NOT NULL,
\`deletedAt\` datetime DEFAULT NULL,
\`validUntil\` datetime NOT NULL,
\`showEmail\` boolean NOT NULL DEFAULT false,
\`redeemedAt\` datetime,
\`redeemedBy\` int UNSIGNED,
PRIMARY KEY (\`id\`)
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
`)
}
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
await queryFn(`DROP TABLE \`transaction_links\`;`)
}