lsit contribution links query

This commit is contained in:
Moriz Wahl 2022-06-14 12:10:16 +02:00
parent e1a84eb52e
commit fd2f6a16b7
5 changed files with 104 additions and 0 deletions

View File

@ -38,4 +38,5 @@ export enum RIGHTS {
CREATION_TRANSACTION_LIST = 'CREATION_TRANSACTION_LIST', CREATION_TRANSACTION_LIST = 'CREATION_TRANSACTION_LIST',
LIST_TRANSACTION_LINKS_ADMIN = 'LIST_TRANSACTION_LINKS_ADMIN', LIST_TRANSACTION_LINKS_ADMIN = 'LIST_TRANSACTION_LINKS_ADMIN',
CREATE_CONTRIBUTION_LINK = 'CREATE_CONTRIBUTION_LINK', CREATE_CONTRIBUTION_LINK = 'CREATE_CONTRIBUTION_LINK',
LIST_CONTRIBUTION_LINKS = 'LIST_CONTRIBUTION_LINKS',
} }

View File

@ -0,0 +1,11 @@
import { ObjectType, Field } from 'type-graphql'
import { ContributionLink } from '@model/ContributionLink'
@ObjectType()
export class ContributionLinkList {
@Field(() => [ContributionLink])
links: ContributionLink[]
@Field(() => Number)
count: number
}

View File

@ -27,6 +27,7 @@ import {
login, login,
searchUsers, searchUsers,
listTransactionLinksAdmin, listTransactionLinksAdmin,
listContributionLinks,
} from '@/seeds/graphql/queries' } from '@/seeds/graphql/queries'
import { GraphQLError } from 'graphql' import { GraphQLError } from 'graphql'
import { User } from '@entity/User' import { User } from '@entity/User'
@ -1618,6 +1619,16 @@ describe('AdminResolver', () => {
) )
}) })
}) })
describe('listContributionLinks', () => {
it.only('returns an error', async () => {
await expect(query({ query: listContributionLinks })).resolves.toEqual(
expect.objectContaining({
errors: [new GraphQLError('401 Unauthorized')],
}),
)
})
})
}) })
describe('authenticated', () => { describe('authenticated', () => {
@ -1644,6 +1655,16 @@ describe('AdminResolver', () => {
) )
}) })
}) })
describe('listContributionLinks', () => {
it.only('returns an error', async () => {
await expect(query({ query: listContributionLinks })).resolves.toEqual(
expect.objectContaining({
errors: [new GraphQLError('401 Unauthorized')],
}),
)
})
})
}) })
describe('with admin rights', () => { describe('with admin rights', () => {
@ -1708,6 +1729,37 @@ describe('AdminResolver', () => {
) )
}) })
}) })
describe('listContributionLinks', () => {
describe('one link in DB', () => {
it.only('returns the link and count 1', async () => {
await expect(query({ query: listContributionLinks })).resolves.toEqual(
expect.objectContaining({
data: {
listContributionLinks: {
links: expect.arrayContaining([
expect.objectContaining({
amount: '200',
code: expect.stringMatching(/^CL-[0-9a-f]{24,24}$/),
link: expect.any(String),
createdAt: expect.any(String),
name: 'Dokumenta 2022',
memo: 'Danke für deine Teilnahme an der Dokumenta 2022',
validFrom: expect.any(String),
validTo: expect.any(String),
maxAmountPerMonth: '200',
cycle: 'once',
maxPerCycle: 1,
}),
]),
count: 1,
},
},
}),
)
})
})
})
}) })
}) })
}) })

View File

@ -15,6 +15,7 @@ import { PendingCreation } from '@model/PendingCreation'
import { CreatePendingCreations } from '@model/CreatePendingCreations' import { CreatePendingCreations } from '@model/CreatePendingCreations'
import { UpdatePendingCreation } from '@model/UpdatePendingCreation' import { UpdatePendingCreation } from '@model/UpdatePendingCreation'
import { ContributionLink } from '@model/ContributionLink' import { ContributionLink } from '@model/ContributionLink'
import { ContributionLinkList } from '@model/ContributionLinkList'
import { RIGHTS } from '@/auth/RIGHTS' import { RIGHTS } from '@/auth/RIGHTS'
import { UserRepository } from '@repository/User' import { UserRepository } from '@repository/User'
import CreatePendingCreationArgs from '@arg/CreatePendingCreationArgs' import CreatePendingCreationArgs from '@arg/CreatePendingCreationArgs'
@ -494,6 +495,23 @@ export class AdminResolver {
dbContributionLink.save() dbContributionLink.save()
return new ContributionLink(dbContributionLink) return new ContributionLink(dbContributionLink)
} }
@Authorized([RIGHTS.LIST_CONTRIBUTION_LINKS])
@Query(() => ContributionLinkList)
async listContributionLinks(
@Args()
{ currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated,
): Promise<ContributionLinkList> {
const [links, count] = await DbContributionLink.findAndCount({
order: { createdAt: order },
skip: (currentPage - 1) * pageSize,
take: pageSize,
})
return {
links: links.map((link: DbContributionLink) => new ContributionLink(link)),
count,
}
}
} }
interface CreationMap { interface CreationMap {

View File

@ -217,3 +217,25 @@ export const listTransactionLinksAdmin = gql`
} }
} }
` `
export const listContributionLinks = gql`
query ($pageSize: Int = 25, $currentPage: Int = 1, $order: Order) {
listContributionLinks(pageSize: $pageSize, currentPage: $currentPage, order: $order) {
links {
id
amount
name
memo
code
link
createdAt
validFrom
validTo
maxAmountPerMonth
cycle
maxPerCycle
}
count
}
}
`