diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 82fb9ff2b..4cd428153 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -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 } diff --git a/backend/src/graphql/model/TransactionLink.ts b/backend/src/graphql/model/TransactionLink.ts new file mode 100644 index 000000000..0f19df466 --- /dev/null +++ b/backend/src/graphql/model/TransactionLink.ts @@ -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 +} diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index 9f3d7265f..05ff2b302 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -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 { diff --git a/database/entity/0030-transaction_link/TransactionLink.ts b/database/entity/0030-transaction_link/TransactionLink.ts new file mode 100644 index 000000000..6ea708547 --- /dev/null +++ b/database/entity/0030-transaction_link/TransactionLink.ts @@ -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 +} diff --git a/database/entity/TransactionLink.ts b/database/entity/TransactionLink.ts new file mode 100644 index 000000000..fde2ba9e0 --- /dev/null +++ b/database/entity/TransactionLink.ts @@ -0,0 +1 @@ +export { TransactionLink } from './0030-transaction_link/TransactionLink' diff --git a/database/entity/index.ts b/database/entity/index.ts index bee4e2b77..cb6f56ab0 100644 --- a/database/entity/index.ts +++ b/database/entity/index.ts @@ -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, ] diff --git a/database/migrations/0030-transaction_link.ts b/database/migrations/0030-transaction_link.ts new file mode 100644 index 000000000..ee76c980d --- /dev/null +++ b/database/migrations/0030-transaction_link.ts @@ -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>) { + 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>) { + await queryFn(`DROP TABLE \`transaction_links\`;`) +}