mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
delete contribution link mutation
This commit is contained in:
parent
8ba0a4af7c
commit
fa30b871b7
@ -39,4 +39,5 @@ export enum RIGHTS {
|
|||||||
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',
|
LIST_CONTRIBUTION_LINKS = 'LIST_CONTRIBUTION_LINKS',
|
||||||
|
DELETE_CONTRIBUTION_LINK = 'DELETE_CONTRIBUTION_LINK',
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import {
|
|||||||
deletePendingCreation,
|
deletePendingCreation,
|
||||||
confirmPendingCreation,
|
confirmPendingCreation,
|
||||||
createContributionLink,
|
createContributionLink,
|
||||||
|
deleteContributionLink,
|
||||||
} from '@/seeds/graphql/mutations'
|
} from '@/seeds/graphql/mutations'
|
||||||
import {
|
import {
|
||||||
getPendingCreations,
|
getPendingCreations,
|
||||||
@ -1629,6 +1630,18 @@ describe('AdminResolver', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('deleteContributionLink', () => {
|
||||||
|
it('returns an error', async () => {
|
||||||
|
await expect(
|
||||||
|
mutate({ mutation: deleteContributionLink, variables: { id: -1 } }),
|
||||||
|
).resolves.toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
errors: [new GraphQLError('401 Unauthorized')],
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('authenticated', () => {
|
describe('authenticated', () => {
|
||||||
@ -1665,6 +1678,18 @@ describe('AdminResolver', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('deleteContributionLink', () => {
|
||||||
|
it('returns an error', async () => {
|
||||||
|
await expect(
|
||||||
|
mutate({ mutation: deleteContributionLink, variables: { id: -1 } }),
|
||||||
|
).resolves.toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
errors: [new GraphQLError('401 Unauthorized')],
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('with admin rights', () => {
|
describe('with admin rights', () => {
|
||||||
@ -1760,6 +1785,53 @@ describe('AdminResolver', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('deleteContributionLink', () => {
|
||||||
|
describe('no valid id', () => {
|
||||||
|
it('returns an error', async () => {
|
||||||
|
await expect(
|
||||||
|
mutate({ mutation: deleteContributionLink, variables: { id: -1 } }),
|
||||||
|
).resolves.toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
errors: [new GraphQLError('Contribution Link not found to given id.')],
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('valid id', () => {
|
||||||
|
let linkId: number
|
||||||
|
beforeAll(async () => {
|
||||||
|
const links = await query({ query: listContributionLinks })
|
||||||
|
linkId = links.data.listContributionLinks.links[0].id
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns a date string', async () => {
|
||||||
|
await expect(
|
||||||
|
mutate({ mutation: deleteContributionLink, variables: { id: linkId } }),
|
||||||
|
).resolves.toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
data: {
|
||||||
|
deleteContributionLink: expect.any(String),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('does not list this contribution link anymore', async () => {
|
||||||
|
await expect(query({ query: listContributionLinks })).resolves.toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
data: {
|
||||||
|
listContributionLinks: {
|
||||||
|
links: [],
|
||||||
|
count: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { Context, getUser } from '@/server/context'
|
import { Context, getUser } from '@/server/context'
|
||||||
|
import { backendLogger as logger } from '@/server/logger'
|
||||||
import { Resolver, Query, Arg, Args, Authorized, Mutation, Ctx, Int } from 'type-graphql'
|
import { Resolver, Query, Arg, Args, Authorized, Mutation, Ctx, Int } from 'type-graphql'
|
||||||
import {
|
import {
|
||||||
getCustomRepository,
|
getCustomRepository,
|
||||||
@ -492,7 +493,7 @@ export class AdminResolver {
|
|||||||
if (validTo) dbContributionLink.validTo = new Date(validTo)
|
if (validTo) dbContributionLink.validTo = new Date(validTo)
|
||||||
dbContributionLink.maxAmountPerMonth = maxAmountPerMonth
|
dbContributionLink.maxAmountPerMonth = maxAmountPerMonth
|
||||||
dbContributionLink.maxPerCycle = maxPerCycle
|
dbContributionLink.maxPerCycle = maxPerCycle
|
||||||
dbContributionLink.save()
|
await dbContributionLink.save()
|
||||||
return new ContributionLink(dbContributionLink)
|
return new ContributionLink(dbContributionLink)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -512,6 +513,19 @@ export class AdminResolver {
|
|||||||
count,
|
count,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Authorized([RIGHTS.DELETE_CONTRIBUTION_LINK])
|
||||||
|
@Mutation(() => Date, { nullable: true })
|
||||||
|
async deleteContributionLink(@Arg('id', () => Int) id: number): Promise<Date | null> {
|
||||||
|
const contributionLink = await DbContributionLink.findOne(id)
|
||||||
|
if (!contributionLink) {
|
||||||
|
logger.error(`Contribution Link not found to given id: ${id}`)
|
||||||
|
throw new Error('Contribution Link not found to given id.')
|
||||||
|
}
|
||||||
|
await contributionLink.softRemove()
|
||||||
|
const newContributionLink = await DbContributionLink.findOne({ id }, { withDeleted: true })
|
||||||
|
return newContributionLink ? newContributionLink.deletedAt : null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CreationMap {
|
interface CreationMap {
|
||||||
|
|||||||
@ -173,3 +173,9 @@ export const createContributionLink = gql`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
export const deleteContributionLink = gql`
|
||||||
|
mutation ($id: Int!) {
|
||||||
|
deleteContributionLink(id: $id)
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user