Merge branch 'master' into virtual-link-transaction

This commit is contained in:
Moriz Wahl 2022-03-11 11:59:43 +01:00 committed by GitHub
commit d62862fab8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 107 additions and 13 deletions

View File

@ -19,8 +19,8 @@ export enum RIGHTS {
UPDATE_USER_INFOS = 'UPDATE_USER_INFOS', UPDATE_USER_INFOS = 'UPDATE_USER_INFOS',
HAS_ELOPAGE = 'HAS_ELOPAGE', HAS_ELOPAGE = 'HAS_ELOPAGE',
CREATE_TRANSACTION_LINK = 'CREATE_TRANSACTION_LINK', CREATE_TRANSACTION_LINK = 'CREATE_TRANSACTION_LINK',
DELETE_TRANSACTION_LINK = 'DELETE_TRANSACTION_LINK',
QUERY_TRANSACTION_LINK = 'QUERY_TRANSACTION_LINK', QUERY_TRANSACTION_LINK = 'QUERY_TRANSACTION_LINK',
// Admin // Admin
SEARCH_USERS = 'SEARCH_USERS', SEARCH_USERS = 'SEARCH_USERS',
CREATE_PENDING_CREATION = 'CREATE_PENDING_CREATION', CREATE_PENDING_CREATION = 'CREATE_PENDING_CREATION',

View File

@ -19,6 +19,7 @@ export const ROLE_USER = new Role('user', [
RIGHTS.UPDATE_USER_INFOS, RIGHTS.UPDATE_USER_INFOS,
RIGHTS.HAS_ELOPAGE, RIGHTS.HAS_ELOPAGE,
RIGHTS.CREATE_TRANSACTION_LINK, RIGHTS.CREATE_TRANSACTION_LINK,
RIGHTS.DELETE_TRANSACTION_LINK,
]) ])
export const ROLE_ADMIN = new Role('admin', Object.values(RIGHTS)) // all rights export const ROLE_ADMIN = new Role('admin', Object.values(RIGHTS)) // all rights

View File

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

View File

@ -8,7 +8,4 @@ export default class TransactionLinkArgs {
@Field(() => String) @Field(() => String)
memo: string memo: string
@Field(() => Boolean, { nullable: true })
showEmail?: boolean
} }

View File

@ -14,7 +14,6 @@ export class TransactionLink {
this.code = transactionLink.code this.code = transactionLink.code
this.createdAt = transactionLink.createdAt this.createdAt = transactionLink.createdAt
this.validUntil = transactionLink.validUntil this.validUntil = transactionLink.validUntil
this.showEmail = transactionLink.showEmail
this.deletedAt = transactionLink.deletedAt this.deletedAt = transactionLink.deletedAt
this.redeemedAt = transactionLink.redeemedAt this.redeemedAt = transactionLink.redeemedAt
this.redeemedBy = redeemedBy this.redeemedBy = redeemedBy
@ -47,9 +46,6 @@ export class TransactionLink {
@Field(() => Date) @Field(() => Date)
validUntil: Date validUntil: Date
@Field(() => Boolean)
showEmail: boolean
@Field(() => Date, { nullable: true }) @Field(() => Date, { nullable: true })
redeemedAt: Date | null redeemedAt: Date | null

View File

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Resolver, Args, Authorized, Ctx, Mutation, Query } from 'type-graphql' import { Resolver, Args, Arg, Authorized, Ctx, Mutation, Query } from 'type-graphql'
import { getCustomRepository } from '@dbTools/typeorm' import { getCustomRepository } from '@dbTools/typeorm'
import { TransactionLink } from '@model/TransactionLink' import { TransactionLink } from '@model/TransactionLink'
import { TransactionLink as dbTransactionLink } from '@entity/TransactionLink' import { TransactionLink as dbTransactionLink } from '@entity/TransactionLink'
@ -36,7 +36,7 @@ export class TransactionLinkResolver {
@Authorized([RIGHTS.CREATE_TRANSACTION_LINK]) @Authorized([RIGHTS.CREATE_TRANSACTION_LINK])
@Mutation(() => TransactionLink) @Mutation(() => TransactionLink)
async createTransactionLink( async createTransactionLink(
@Args() { amount, memo, showEmail = false }: TransactionLinkArgs, @Args() { amount, memo }: TransactionLinkArgs,
@Ctx() context: any, @Ctx() context: any,
): Promise<TransactionLink> { ): Promise<TransactionLink> {
const userRepository = getCustomRepository(UserRepository) const userRepository = getCustomRepository(UserRepository)
@ -61,7 +61,6 @@ export class TransactionLinkResolver {
transactionLink.code = transactionLinkCode(createdDate) transactionLink.code = transactionLinkCode(createdDate)
transactionLink.createdAt = createdDate transactionLink.createdAt = createdDate
transactionLink.validUntil = validUntil transactionLink.validUntil = validUntil
transactionLink.showEmail = showEmail
await dbTransactionLink.save(transactionLink).catch(() => { await dbTransactionLink.save(transactionLink).catch(() => {
throw new Error('Unable to save transaction link') throw new Error('Unable to save transaction link')
}) })
@ -69,6 +68,32 @@ export class TransactionLinkResolver {
return new TransactionLink(transactionLink, new User(user)) return new TransactionLink(transactionLink, new User(user))
} }
@Authorized([RIGHTS.DELETE_TRANSACTION_LINK])
@Mutation(() => Boolean)
async deleteTransactionLink(@Arg('id') id: number, @Ctx() context: any): Promise<boolean> {
const userRepository = getCustomRepository(UserRepository)
const user = await userRepository.findByPubkeyHex(context.pubKey)
const transactionLink = await dbTransactionLink.findOne({ id })
if (!transactionLink) {
throw new Error('Transaction Link not found!')
}
if (transactionLink.userId !== user.id) {
throw new Error('Transaction Link cannot be deleted!')
}
if (transactionLink.redeemedBy) {
throw new Error('Transaction Link already redeemed!')
}
await transactionLink.softRemove().catch(() => {
throw new Error('Transaction Link could not be deleted!')
})
return true
}
@Authorized([RIGHTS.QUERY_TRANSACTION_LINK]) @Authorized([RIGHTS.QUERY_TRANSACTION_LINK])
@Query(() => TransactionLink) @Query(() => TransactionLink)
async queryTransactionLink( async queryTransactionLink(

View File

@ -0,0 +1,61 @@
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: 'datetime',
nullable: true,
})
redeemedAt: Date | null
@Column({ type: 'int', unsigned: true, nullable: true })
redeemedBy: number | null
}

View File

@ -1 +1 @@
export { TransactionLink } from './0030-transaction_link/TransactionLink' export { TransactionLink } from './0031-remove_sendEmail_from_transaction_link/TransactionLink'

View File

@ -0,0 +1,14 @@
/* MIGRATION TO REMOVE sendEmail FIELD FROM 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('ALTER TABLE `transaction_links` DROP COLUMN `showEmail`;')
}
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
await queryFn(
'ALTER TABLE `transaction_links` ADD COLUMN `showEmail` boolean NOT NULL DEFAULT false AFTER `validUntil`;',
)
}