mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
delete transaction link mutation
This commit is contained in:
parent
b23cb8915c
commit
4784fc23ab
@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
|
||||
import { Resolver, Args, Authorized, Ctx, Mutation } from 'type-graphql'
|
||||
import { Resolver, Args, Arg, Authorized, Ctx, Mutation } from 'type-graphql'
|
||||
import { getCustomRepository } from '@dbTools/typeorm'
|
||||
import { TransactionLink } from '@model/TransactionLink'
|
||||
import { TransactionLink as dbTransactionLink } from '@entity/TransactionLink'
|
||||
@ -67,4 +67,32 @@ export class TransactionLinkResolver {
|
||||
|
||||
return new TransactionLink(transactionLink, new User(user))
|
||||
}
|
||||
|
||||
@Authorized([RIGHTS.DELETE_TRANSACTION_LINK])
|
||||
@Mutation(() => Date, { nullable: true })
|
||||
async deleteTransactionLink(
|
||||
@Arg('id') id: number,
|
||||
@Ctx() context: any,
|
||||
): Promise<Date | null | undefined> {
|
||||
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!')
|
||||
}
|
||||
|
||||
// TODO: admin can delete links?
|
||||
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()
|
||||
const newLink = await dbTransactionLink.findOne({ id }, { withDeleted: true })
|
||||
return newLink ? newLink.deletedAt : null
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user