feat: List Transaction Links Query

This commit is contained in:
Moriz Wahl 2022-03-11 12:29:10 +01:00
parent 80201c6fb1
commit 6880fb628e
3 changed files with 27 additions and 1 deletions

View File

@ -21,6 +21,7 @@ export enum RIGHTS {
CREATE_TRANSACTION_LINK = 'CREATE_TRANSACTION_LINK',
DELETE_TRANSACTION_LINK = 'DELETE_TRANSACTION_LINK',
QUERY_TRANSACTION_LINK = 'QUERY_TRANSACTION_LINK',
LIST_TRANSACTION_LINKS = 'LIST_TRANSACTION_LINKS',
// Admin
SEARCH_USERS = 'SEARCH_USERS',
CREATE_PENDING_CREATION = 'CREATE_PENDING_CREATION',

View File

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

View File

@ -2,7 +2,7 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Resolver, Args, Arg, Authorized, Ctx, Mutation, Query } from 'type-graphql'
import { getCustomRepository } from '@dbTools/typeorm'
import { getCustomRepository, MoreThan } from '@dbTools/typeorm'
import { TransactionLink } from '@model/TransactionLink'
import { TransactionLink as dbTransactionLink } from '@entity/TransactionLink'
import TransactionLinkArgs from '@arg/TransactionLinkArgs'
@ -122,4 +122,28 @@ export class TransactionLinkResolver {
}
return new TransactionLink(transactionLink, new User(user), userRedeem)
}
@Authorized([RIGHTS.LIST_TRANSACTION_LINKS])
@Query(() => [TransactionLink])
async listTransactionLinks(
@Arg('offset', { nullable: true }) offset = 0,
@Ctx() context: any,
): Promise<TransactionLink[]> {
const userRepository = getCustomRepository(UserRepository)
const user = await userRepository.findByPubkeyHex(context.pubKey)
const now = new Date()
const transactionLinks = await dbTransactionLink.find({
where: {
userId: user.id,
redeemedBy: null,
validUntil: MoreThan(now),
},
order: {
createdAt: 'DESC',
},
skip: offset,
take: 5,
})
return transactionLinks.map((tl) => new TransactionLink(tl, new User(user)))
}
}