mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
updated event working, deletion is not working properly (deeper than the event itself)
This commit is contained in:
parent
0176131c39
commit
79f7ebce57
@ -48,6 +48,8 @@ export class EventTransactionCreation extends EventBasicUserId {
|
|||||||
export class EventTransactionReceive extends EventBasicTx {}
|
export class EventTransactionReceive extends EventBasicTx {}
|
||||||
export class EventTransactionReceiveRedeem extends EventBasicTx {}
|
export class EventTransactionReceiveRedeem extends EventBasicTx {}
|
||||||
export class EventContributionCreate extends EventBasicCt {}
|
export class EventContributionCreate extends EventBasicCt {}
|
||||||
|
export class EventContributionDelete extends EventBasicCt {}
|
||||||
|
export class EventContributionUpdate extends EventBasicCt {}
|
||||||
export class EventContributionConfirm extends EventBasicCt {
|
export class EventContributionConfirm extends EventBasicCt {
|
||||||
xUserId: number
|
xUserId: number
|
||||||
xCommunityId: number
|
xCommunityId: number
|
||||||
@ -206,6 +208,20 @@ export class Event {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setEventContributionDelete(ev: EventContributionDelete): Event {
|
||||||
|
this.setByBasicCt(ev.userId, ev.contributionId, ev.amount)
|
||||||
|
this.type = EventProtocolType.CONTRIBUTION_DELETE
|
||||||
|
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
public setEventContributionUpdate(ev: EventContributionUpdate): Event {
|
||||||
|
this.setByBasicCt(ev.userId, ev.contributionId, ev.amount)
|
||||||
|
this.type = EventProtocolType.CONTRIBUTION_UPDATE
|
||||||
|
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
public setEventContributionConfirm(ev: EventContributionConfirm): Event {
|
public setEventContributionConfirm(ev: EventContributionConfirm): Event {
|
||||||
this.setByBasicCt(ev.userId, ev.contributionId, ev.amount)
|
this.setByBasicCt(ev.userId, ev.contributionId, ev.amount)
|
||||||
if (ev.xUserId) this.xUserId = ev.xUserId
|
if (ev.xUserId) this.xUserId = ev.xUserId
|
||||||
|
|||||||
@ -21,4 +21,6 @@ export enum EventProtocolType {
|
|||||||
CONTRIBUTION_CONFIRM = 'CONTRIBUTION_CONFIRM',
|
CONTRIBUTION_CONFIRM = 'CONTRIBUTION_CONFIRM',
|
||||||
CONTRIBUTION_LINK_DEFINE = 'CONTRIBUTION_LINK_DEFINE',
|
CONTRIBUTION_LINK_DEFINE = 'CONTRIBUTION_LINK_DEFINE',
|
||||||
CONTRIBUTION_LINK_ACTIVATE_REDEEM = 'CONTRIBUTION_LINK_ACTIVATE_REDEEM',
|
CONTRIBUTION_LINK_ACTIVATE_REDEEM = 'CONTRIBUTION_LINK_ACTIVATE_REDEEM',
|
||||||
|
CONTRIBUTION_DELETE = 'CONTRIBUTION_DELETE',
|
||||||
|
CONTRIBUTION_UPDATE = 'CONTRIBUTION_UPDATE',
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import { peterLustig } from '@/seeds/users/peter-lustig'
|
|||||||
import { EventProtocol } from '@entity/EventProtocol'
|
import { EventProtocol } from '@entity/EventProtocol'
|
||||||
import { EventProtocolType } from '@/event/EventProtocolType'
|
import { EventProtocolType } from '@/event/EventProtocolType'
|
||||||
import { logger } from '@test/testSetup'
|
import { logger } from '@test/testSetup'
|
||||||
|
import { Contribution } from '@entity/Contribution'
|
||||||
|
|
||||||
let mutate: any, query: any, con: any
|
let mutate: any, query: any, con: any
|
||||||
let testEnv: any
|
let testEnv: any
|
||||||
@ -587,6 +588,15 @@ describe('ContributionResolver', () => {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('stores the update contribution event in the database', async () => {
|
||||||
|
await expect(EventProtocol.find()).resolves.toContainEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
type: EventProtocolType.CONTRIBUTION_UPDATE,
|
||||||
|
contributionId: result.data.createContribution.id,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -763,6 +773,7 @@ describe('ContributionResolver', () => {
|
|||||||
|
|
||||||
describe('User deletes own contribution', () => {
|
describe('User deletes own contribution', () => {
|
||||||
it('deletes successfully', async () => {
|
it('deletes successfully', async () => {
|
||||||
|
console.log(await Contribution.find({ id: result.data.createContribution.id }))
|
||||||
await expect(
|
await expect(
|
||||||
mutate({
|
mutate({
|
||||||
mutation: deleteContribution,
|
mutation: deleteContribution,
|
||||||
@ -772,6 +783,16 @@ describe('ContributionResolver', () => {
|
|||||||
}),
|
}),
|
||||||
).resolves.toBeTruthy()
|
).resolves.toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('stores the delete contribution event in the database', async () => {
|
||||||
|
console.log(await Contribution.find({ id: result.data.createContribution.id }))
|
||||||
|
await expect(EventProtocol.find()).resolves.toContainEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
type: EventProtocolType.CONTRIBUTION_DELETE,
|
||||||
|
// id: result.data.createContribution.id,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('User deletes already confirmed contribution', () => {
|
describe('User deletes already confirmed contribution', () => {
|
||||||
|
|||||||
@ -13,7 +13,12 @@ import { Contribution, ContributionListResult } from '@model/Contribution'
|
|||||||
import { UnconfirmedContribution } from '@model/UnconfirmedContribution'
|
import { UnconfirmedContribution } from '@model/UnconfirmedContribution'
|
||||||
import { validateContribution, getUserCreation, updateCreations } from './util/creations'
|
import { validateContribution, getUserCreation, updateCreations } from './util/creations'
|
||||||
import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const'
|
import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const'
|
||||||
import { Event, EventContributionCreate } from '@/event/Event'
|
import {
|
||||||
|
Event,
|
||||||
|
EventContributionCreate,
|
||||||
|
EventContributionDelete,
|
||||||
|
EventContributionUpdate,
|
||||||
|
} from '@/event/Event'
|
||||||
import { eventProtocol } from '@/event/EventProtocolEmitter'
|
import { eventProtocol } from '@/event/EventProtocolEmitter'
|
||||||
|
|
||||||
@Resolver()
|
@Resolver()
|
||||||
@ -56,6 +61,8 @@ export class ContributionResolver {
|
|||||||
|
|
||||||
const eventCreateContribution = new EventContributionCreate()
|
const eventCreateContribution = new EventContributionCreate()
|
||||||
eventCreateContribution.userId = user.id
|
eventCreateContribution.userId = user.id
|
||||||
|
eventCreateContribution.amount = amount
|
||||||
|
eventCreateContribution.contributionId = contribution.id
|
||||||
await eventProtocol.writeEvent(event.setEventContributionCreate(eventCreateContribution))
|
await eventProtocol.writeEvent(event.setEventContributionCreate(eventCreateContribution))
|
||||||
|
|
||||||
return new UnconfirmedContribution(contribution, user, creations)
|
return new UnconfirmedContribution(contribution, user, creations)
|
||||||
@ -67,6 +74,7 @@ export class ContributionResolver {
|
|||||||
@Arg('id', () => Int) id: number,
|
@Arg('id', () => Int) id: number,
|
||||||
@Ctx() context: Context,
|
@Ctx() context: Context,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
|
const event = new Event()
|
||||||
const user = getUser(context)
|
const user = getUser(context)
|
||||||
const contribution = await dbContribution.findOne(id)
|
const contribution = await dbContribution.findOne(id)
|
||||||
if (!contribution) {
|
if (!contribution) {
|
||||||
@ -81,8 +89,16 @@ export class ContributionResolver {
|
|||||||
logger.error('A confirmed contribution can not be deleted')
|
logger.error('A confirmed contribution can not be deleted')
|
||||||
throw new Error('A confirmed contribution can not be deleted')
|
throw new Error('A confirmed contribution can not be deleted')
|
||||||
}
|
}
|
||||||
|
|
||||||
contribution.contributionStatus = ContributionStatus.DELETED
|
contribution.contributionStatus = ContributionStatus.DELETED
|
||||||
|
contribution.deletedAt = new Date()
|
||||||
await contribution.save()
|
await contribution.save()
|
||||||
|
|
||||||
|
const eventDeleteContribution = new EventContributionDelete()
|
||||||
|
eventDeleteContribution.userId = user.id
|
||||||
|
eventDeleteContribution.contributionId = contribution.id
|
||||||
|
await eventProtocol.writeEvent(event.setEventContributionDelete(eventDeleteContribution))
|
||||||
|
|
||||||
const res = await contribution.softRemove()
|
const res = await contribution.softRemove()
|
||||||
return !!res
|
return !!res
|
||||||
}
|
}
|
||||||
@ -188,6 +204,13 @@ export class ContributionResolver {
|
|||||||
contributionToUpdate.contributionStatus = ContributionStatus.PENDING
|
contributionToUpdate.contributionStatus = ContributionStatus.PENDING
|
||||||
dbContribution.save(contributionToUpdate)
|
dbContribution.save(contributionToUpdate)
|
||||||
|
|
||||||
|
const event = new Event()
|
||||||
|
|
||||||
|
const eventUpdateContribution = new EventContributionUpdate()
|
||||||
|
eventUpdateContribution.userId = user.id
|
||||||
|
eventUpdateContribution.contributionId = contributionId
|
||||||
|
await eventProtocol.writeEvent(event.setEventContributionUpdate(eventUpdateContribution))
|
||||||
|
|
||||||
return new UnconfirmedContribution(contributionToUpdate, user, creations)
|
return new UnconfirmedContribution(contributionToUpdate, user, creations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user