mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
feat: List Transaction Links Query
This commit is contained in:
parent
80201c6fb1
commit
6880fb628e
@ -21,6 +21,7 @@ export enum RIGHTS {
|
|||||||
CREATE_TRANSACTION_LINK = 'CREATE_TRANSACTION_LINK',
|
CREATE_TRANSACTION_LINK = 'CREATE_TRANSACTION_LINK',
|
||||||
DELETE_TRANSACTION_LINK = 'DELETE_TRANSACTION_LINK',
|
DELETE_TRANSACTION_LINK = 'DELETE_TRANSACTION_LINK',
|
||||||
QUERY_TRANSACTION_LINK = 'QUERY_TRANSACTION_LINK',
|
QUERY_TRANSACTION_LINK = 'QUERY_TRANSACTION_LINK',
|
||||||
|
LIST_TRANSACTION_LINKS = 'LIST_TRANSACTION_LINKS',
|
||||||
// Admin
|
// Admin
|
||||||
SEARCH_USERS = 'SEARCH_USERS',
|
SEARCH_USERS = 'SEARCH_USERS',
|
||||||
CREATE_PENDING_CREATION = 'CREATE_PENDING_CREATION',
|
CREATE_PENDING_CREATION = 'CREATE_PENDING_CREATION',
|
||||||
|
|||||||
@ -20,6 +20,7 @@ export const ROLE_USER = new Role('user', [
|
|||||||
RIGHTS.HAS_ELOPAGE,
|
RIGHTS.HAS_ELOPAGE,
|
||||||
RIGHTS.CREATE_TRANSACTION_LINK,
|
RIGHTS.CREATE_TRANSACTION_LINK,
|
||||||
RIGHTS.DELETE_TRANSACTION_LINK,
|
RIGHTS.DELETE_TRANSACTION_LINK,
|
||||||
|
RIGHTS.LIST_TRANSACTION_LINKS,
|
||||||
])
|
])
|
||||||
export const ROLE_ADMIN = new Role('admin', Object.values(RIGHTS)) // all rights
|
export const ROLE_ADMIN = new Role('admin', Object.values(RIGHTS)) // all rights
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||||
|
|
||||||
import { Resolver, Args, Arg, 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, MoreThan } 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'
|
||||||
import TransactionLinkArgs from '@arg/TransactionLinkArgs'
|
import TransactionLinkArgs from '@arg/TransactionLinkArgs'
|
||||||
@ -122,4 +122,28 @@ export class TransactionLinkResolver {
|
|||||||
}
|
}
|
||||||
return new TransactionLink(transactionLink, new User(user), userRedeem)
|
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)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user