diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 8b8834b59..ee24c768b 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -22,7 +22,7 @@ export class EventBasicCt extends EventBasicUserId { amount: decimal } -export class EventBasicCtX extends EventBasicUserId { +export class EventBasicCtX extends EventBasicCt { xUserId: number xCommunityId: number contributionId: number @@ -74,10 +74,7 @@ export class EventAdminCreateContributionMessage extends EventBasicCtMsg { } export class EventContributionDelete extends EventBasicCt {} export class EventContributionUpdate extends EventBasicCt {} -export class EventContributionConfirm extends EventBasicCt { - xUserId: number - xCommunityId: number -} +export class EventContributionConfirm extends EventBasicCtX {} export class EventContributionDeny extends EventBasicCtX {} export class EventContributionLinkDefine extends EventBasicCt {} export class EventContributionLinkActivateRedeem extends EventBasicCt {} @@ -164,50 +161,37 @@ export class Event { } public setEventSendTransactionSendEmail(ev: EventSendTransactionSendEmail): Event { - this.setByBasicUser(ev.userId) - if (ev.transactionId) this.transactionId = ev.transactionId - if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId - if (ev.xUserId) this.xUserId = ev.xUserId - if (ev.amount) this.amount = ev.amount + this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) this.type = EventProtocolType.SEND_TRANSACTION_SEND_EMAIL return this } public setEventSendTransactionReceiveEmail(ev: EventSendTransactionReceiveEmail): Event { - this.setByBasicUser(ev.userId) - if (ev.transactionId) this.transactionId = ev.transactionId - if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId - if (ev.xUserId) this.xUserId = ev.xUserId - if (ev.amount) this.amount = ev.amount + this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) this.type = EventProtocolType.SEND_TRANSACTION_RECEIVE_EMAIL return this } public setEventSendTransactionLinkRedeemEmail(ev: EventSendTransactionLinkRedeemEmail): Event { - this.setByBasicUser(ev.userId) - if (ev.transactionId) this.transactionId = ev.transactionId - if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId - if (ev.xUserId) this.xUserId = ev.xUserId - if (ev.amount) this.amount = ev.amount + this.setByBasicTx(ev.userId, ev.xUserId, ev.xCommunityId, ev.transactionId, ev.amount) this.type = EventProtocolType.SEND_TRANSACTION_LINK_REDEEM_EMAIL return this } public setEventSendAddedContributionEmail(ev: EventSendAddedContributionEmail): Event { - this.setByBasicUser(ev.userId) - if (ev.contributionId) this.contributionId = ev.contributionId + this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) this.type = EventProtocolType.SEND_ADDED_CONTRIBUTION_EMAIL return this } public setEventSendContributionConfirmEmail(ev: EventSendContributionConfirmEmail): Event { - this.setByBasicUser(ev.userId) - if (ev.contributionId) this.contributionId = ev.contributionId + this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) this.type = EventProtocolType.SEND_CONTRIBUTION_CONFIRM_EMAIL + return this } @@ -312,16 +296,16 @@ export class Event { } public setEventUserCreateContributionMessage(ev: EventUserCreateContributionMessage): Event { - this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) + this.setByBasicCtMsg(ev.userId, ev.contributionId, ev.amount, ev.message) this.type = EventProtocolType.USER_CREATE_CONTRIBUTION_MESSAGE - this.message = ev.message + return this } public setEventAdminCreateContributionMessage(ev: EventAdminCreateContributionMessage): Event { - this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) + this.setByBasicCtMsg(ev.userId, ev.contributionId, ev.amount, ev.message) this.type = EventProtocolType.ADMIN_CREATE_CONTRIBUTION_MESSAGE - this.message = ev.message + return this } @@ -340,20 +324,14 @@ export class Event { } public setEventContributionConfirm(ev: EventContributionConfirm): Event { - this.setByBasicCt(ev.userId, ev.contributionId, ev.amount) - if (ev.xUserId) this.xUserId = ev.xUserId - if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId + this.setByBasicCtX(ev.userId, ev.xUserId, ev.xCommunityId, ev.contributionId, ev.amount) this.type = EventProtocolType.CONTRIBUTION_CONFIRM return this } public setEventContributionDeny(ev: EventContributionDeny): Event { - this.setByBasicTx(ev.userId) - if (ev.contributionId) this.contributionId = ev.contributionId - if (ev.xCommunityId) this.xCommunityId = ev.xCommunityId - if (ev.xUserId) this.xUserId = ev.xUserId - if (ev.amount) this.amount = ev.amount + this.setByBasicCtX(ev.userId, ev.xUserId, ev.xCommunityId, ev.contributionId, ev.amount) this.type = EventProtocolType.CONTRIBUTION_DENY return this @@ -404,6 +382,34 @@ export class Event { return this } + setByBasicCtMsg( + userId: number, + contributionId: number, + amount?: decimal, + message?: string, + ): Event { + this.setByBasicCt(userId, contributionId, amount) + if (message) this.message = message + + return this + } + + setByBasicCtX( + userId: number, + xUserId?: number, + xCommunityId?: number, + contributionId?: number, + amount?: decimal, + ): Event { + this.setByBasicUser(userId) + if (xUserId) this.xUserId = xUserId + if (xCommunityId) this.xCommunityId = xCommunityId + if (contributionId) this.contributionId = contributionId + if (amount) this.amount = amount + + return this + } + setByBasicRedeem(userId: number, transactionId?: number, contributionId?: number): Event { this.setByBasicUser(userId) if (transactionId) this.transactionId = transactionId diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index b8bbebbd9..199fb6c76 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -137,7 +137,7 @@ describe('ContributionResolver', () => { it('logs the error found', () => { expect(logger.error).toBeCalledWith( 'No information for available creations with the given creationDate=', - new Date('non-valid').toDateString, + 'Invalid Date', ) }) @@ -162,10 +162,9 @@ describe('ContributionResolver', () => { }) it('logs the error found', () => { - const date = new Date() expect(logger.error).toBeCalledWith( 'No information for available creations with the given creationDate=', - new Date(date.setMonth(date.getMonth() - 3).toString()).toDateString, + 'Invalid Date', ) }) }) @@ -560,10 +559,9 @@ describe('ContributionResolver', () => { }) it('logs the error found', () => { - const date = new Date() expect(logger.error).toBeCalledWith( 'No information for available creations with the given creationDate=', - new Date(date.setMonth(date.getMonth() - 3).toString()).toDateString, + 'Invalid Date', ) }) }) diff --git a/backend/src/graphql/resolver/util/creations.ts b/backend/src/graphql/resolver/util/creations.ts index b390e197d..9987dfae6 100644 --- a/backend/src/graphql/resolver/util/creations.ts +++ b/backend/src/graphql/resolver/util/creations.ts @@ -21,7 +21,7 @@ export const validateContribution = ( if (index < 0) { logger.error( 'No information for available creations with the given creationDate=', - creationDate.toDateString, + creationDate.toString(), ) throw new Error('No information for available creations for the given date') }