mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
combine logic for both listTransactionLinks and listTransactionLinksAdmin
This commit is contained in:
parent
9ff045fdbf
commit
66a5175dc1
@ -61,8 +61,8 @@ export class TransactionLink {
|
|||||||
@ObjectType()
|
@ObjectType()
|
||||||
export class TransactionLinkResult {
|
export class TransactionLinkResult {
|
||||||
@Field(() => Int)
|
@Field(() => Int)
|
||||||
linkCount: number
|
count: number
|
||||||
|
|
||||||
@Field(() => [TransactionLink])
|
@Field(() => [TransactionLink])
|
||||||
linkList: TransactionLink[]
|
links: TransactionLink[]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -611,8 +611,8 @@ describe('TransactionLinkResolver', () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
data: {
|
data: {
|
||||||
listTransactionLinksAdmin: {
|
listTransactionLinksAdmin: {
|
||||||
linkCount: 6,
|
count: 6,
|
||||||
linkList: expect.not.arrayContaining([
|
links: expect.not.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
memo: 'Leider wollte niemand meine Gradidos zum Neujahr haben :(',
|
memo: 'Leider wollte niemand meine Gradidos zum Neujahr haben :(',
|
||||||
createdAt: expect.any(String),
|
createdAt: expect.any(String),
|
||||||
@ -647,8 +647,8 @@ describe('TransactionLinkResolver', () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
data: {
|
data: {
|
||||||
listTransactionLinksAdmin: {
|
listTransactionLinksAdmin: {
|
||||||
linkCount: 6,
|
count: 6,
|
||||||
linkList: expect.not.arrayContaining([
|
links: expect.not.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
memo: 'Leider wollte niemand meine Gradidos zum Neujahr haben :(',
|
memo: 'Leider wollte niemand meine Gradidos zum Neujahr haben :(',
|
||||||
createdAt: expect.any(String),
|
createdAt: expect.any(String),
|
||||||
@ -681,8 +681,8 @@ describe('TransactionLinkResolver', () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
data: {
|
data: {
|
||||||
listTransactionLinksAdmin: {
|
listTransactionLinksAdmin: {
|
||||||
linkCount: 7,
|
count: 7,
|
||||||
linkList: expect.arrayContaining([
|
links: expect.arrayContaining([
|
||||||
expect.not.objectContaining({
|
expect.not.objectContaining({
|
||||||
memo: 'Leider wollte niemand meine Gradidos zum Neujahr haben :(',
|
memo: 'Leider wollte niemand meine Gradidos zum Neujahr haben :(',
|
||||||
createdAt: expect.any(String),
|
createdAt: expect.any(String),
|
||||||
@ -715,8 +715,8 @@ describe('TransactionLinkResolver', () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
data: {
|
data: {
|
||||||
listTransactionLinksAdmin: {
|
listTransactionLinksAdmin: {
|
||||||
linkCount: 7,
|
count: 7,
|
||||||
linkList: expect.arrayContaining([
|
links: expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
memo: 'Leider wollte niemand meine Gradidos zum Neujahr haben :(',
|
memo: 'Leider wollte niemand meine Gradidos zum Neujahr haben :(',
|
||||||
createdAt: expect.any(String),
|
createdAt: expect.any(String),
|
||||||
@ -752,8 +752,8 @@ describe('TransactionLinkResolver', () => {
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
data: {
|
data: {
|
||||||
listTransactionLinksAdmin: {
|
listTransactionLinksAdmin: {
|
||||||
linkCount: 6,
|
count: 6,
|
||||||
linkList: expect.arrayContaining([
|
links: expect.arrayContaining([
|
||||||
expect.not.objectContaining({
|
expect.not.objectContaining({
|
||||||
memo: 'Leider wollte niemand meine Gradidos zum Neujahr haben :(',
|
memo: 'Leider wollte niemand meine Gradidos zum Neujahr haben :(',
|
||||||
createdAt: expect.any(String),
|
createdAt: expect.any(String),
|
||||||
|
|||||||
@ -35,6 +35,7 @@ import { TRANSACTIONS_LOCK } from '@/util/TRANSACTIONS_LOCK'
|
|||||||
import LogError from '@/server/LogError'
|
import LogError from '@/server/LogError'
|
||||||
|
|
||||||
import { getLastTransaction } from './util/getLastTransaction'
|
import { getLastTransaction } from './util/getLastTransaction'
|
||||||
|
import { filter } from 'lodash'
|
||||||
|
|
||||||
// TODO: do not export, test it inside the resolver
|
// TODO: do not export, test it inside the resolver
|
||||||
export const transactionLinkCode = (date: Date): string => {
|
export const transactionLinkCode = (date: Date): string => {
|
||||||
@ -141,30 +142,6 @@ export class TransactionLinkResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Authorized([RIGHTS.LIST_TRANSACTION_LINKS])
|
|
||||||
@Query(() => [TransactionLink])
|
|
||||||
async listTransactionLinks(
|
|
||||||
@Args()
|
|
||||||
{ currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated,
|
|
||||||
@Ctx() context: Context,
|
|
||||||
): Promise<TransactionLink[]> {
|
|
||||||
const user = getUser(context)
|
|
||||||
// const now = new Date()
|
|
||||||
const transactionLinks = await DbTransactionLink.find({
|
|
||||||
where: {
|
|
||||||
userId: user.id,
|
|
||||||
redeemedBy: null,
|
|
||||||
// validUntil: MoreThan(now),
|
|
||||||
},
|
|
||||||
order: {
|
|
||||||
createdAt: order,
|
|
||||||
},
|
|
||||||
skip: (currentPage - 1) * pageSize,
|
|
||||||
take: pageSize,
|
|
||||||
})
|
|
||||||
return transactionLinks.map((tl) => new TransactionLink(tl, new User(user)))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Authorized([RIGHTS.REDEEM_TRANSACTION_LINK])
|
@Authorized([RIGHTS.REDEEM_TRANSACTION_LINK])
|
||||||
@Mutation(() => Boolean)
|
@Mutation(() => Boolean)
|
||||||
async redeemTransactionLink(
|
async redeemTransactionLink(
|
||||||
@ -338,33 +315,57 @@ export class TransactionLinkResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Authorized([RIGHTS.LIST_TRANSACTION_LINKS])
|
||||||
|
@Query(() => [TransactionLink])
|
||||||
|
async listTransactionLinks(
|
||||||
|
@Args()
|
||||||
|
paginated: Paginated,
|
||||||
|
@Ctx() context: Context,
|
||||||
|
): Promise<TransactionLinkResult> {
|
||||||
|
const user = getUser(context)
|
||||||
|
return transactionLinkList(
|
||||||
|
paginated,
|
||||||
|
{
|
||||||
|
withDeleted: false,
|
||||||
|
withExpired: true,
|
||||||
|
withRedeemed: false,
|
||||||
|
},
|
||||||
|
user.id,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Authorized([RIGHTS.LIST_TRANSACTION_LINKS_ADMIN])
|
@Authorized([RIGHTS.LIST_TRANSACTION_LINKS_ADMIN])
|
||||||
@Query(() => TransactionLinkResult)
|
@Query(() => TransactionLinkResult)
|
||||||
async listTransactionLinksAdmin(
|
async listTransactionLinksAdmin(
|
||||||
@Args()
|
@Args()
|
||||||
{ currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated,
|
paginated: Paginated,
|
||||||
@Arg('filters', () => TransactionLinkFilters, { nullable: true })
|
@Arg('filters', () => TransactionLinkFilters, { nullable: true })
|
||||||
filters: TransactionLinkFilters,
|
filters: TransactionLinkFilters | null,
|
||||||
@Arg('userId', () => Int)
|
@Arg('userId', () => Int)
|
||||||
userId: number,
|
userId: number,
|
||||||
): Promise<TransactionLinkResult> {
|
): Promise<TransactionLinkResult> {
|
||||||
const user = await DbUser.findOneOrFail({ id: userId })
|
return transactionLinkList(paginated, filters, userId)
|
||||||
const where: {
|
|
||||||
userId: number
|
|
||||||
redeemedBy?: number | null
|
|
||||||
validUntil?: FindOperator<Date> | null
|
|
||||||
} = {
|
|
||||||
userId,
|
|
||||||
redeemedBy: null,
|
|
||||||
validUntil: MoreThan(new Date()),
|
|
||||||
}
|
}
|
||||||
if (filters) {
|
}
|
||||||
if (filters.withRedeemed) delete where.redeemedBy
|
|
||||||
if (filters.withExpired) delete where.validUntil
|
const transactionLinkList = async (
|
||||||
|
{ currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated,
|
||||||
|
filters: TransactionLinkFilters | null,
|
||||||
|
userId: number,
|
||||||
|
): Promise<TransactionLinkResult> => {
|
||||||
|
const user = await DbUser.findOneOrFail({ id: userId })
|
||||||
|
const { withDeleted, withExpired, withRedeemed } = filters || {
|
||||||
|
withDeleted: false,
|
||||||
|
withExpired: false,
|
||||||
|
withRedeemed: false,
|
||||||
}
|
}
|
||||||
const [transactionLinks, count] = await DbTransactionLink.findAndCount({
|
const [transactionLinks, count] = await DbTransactionLink.findAndCount({
|
||||||
where,
|
where: {
|
||||||
withDeleted: filters ? filters.withDeleted : false,
|
userId,
|
||||||
|
...(!withRedeemed && { redeemedBy: null }),
|
||||||
|
...(!withExpired && { validUntil: MoreThan(new Date()) }),
|
||||||
|
},
|
||||||
|
withDeleted,
|
||||||
order: {
|
order: {
|
||||||
createdAt: order,
|
createdAt: order,
|
||||||
},
|
},
|
||||||
@ -373,8 +374,7 @@ export class TransactionLinkResolver {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
linkCount: count,
|
count,
|
||||||
linkList: transactionLinks.map((tl) => new TransactionLink(tl, new User(user))),
|
links: transactionLinks.map((tl) => new TransactionLink(tl, new User(user))),
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -224,8 +224,8 @@ export const listTransactionLinksAdmin = gql`
|
|||||||
currentPage: $currentPage
|
currentPage: $currentPage
|
||||||
pageSize: $pageSize
|
pageSize: $pageSize
|
||||||
) {
|
) {
|
||||||
linkCount
|
count
|
||||||
linkList {
|
links {
|
||||||
id
|
id
|
||||||
amount
|
amount
|
||||||
holdAvailableAmount
|
holdAvailableAmount
|
||||||
|
|||||||
@ -126,6 +126,7 @@ export const queryTransactionLink = gql`
|
|||||||
export const listTransactionLinks = gql`
|
export const listTransactionLinks = gql`
|
||||||
query($currentPage: Int = 1, $pageSize: Int = 5) {
|
query($currentPage: Int = 1, $pageSize: Int = 5) {
|
||||||
listTransactionLinks(currentPage: $currentPage, pageSize: $pageSize) {
|
listTransactionLinks(currentPage: $currentPage, pageSize: $pageSize) {
|
||||||
|
links {
|
||||||
id
|
id
|
||||||
amount
|
amount
|
||||||
holdAvailableAmount
|
holdAvailableAmount
|
||||||
@ -136,6 +137,7 @@ export const listTransactionLinks = gql`
|
|||||||
redeemedAt
|
redeemedAt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
export const listContributionLinks = gql`
|
export const listContributionLinks = gql`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user