mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
refactor events - first step to get backend working
This commit is contained in:
parent
fde67c2c32
commit
41569ad0f1
@ -10,7 +10,7 @@ Decimal.set({
|
||||
})
|
||||
|
||||
const constants = {
|
||||
DB_VERSION: '0060-update_communities_table',
|
||||
DB_VERSION: '0061-event_refactoring',
|
||||
DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0
|
||||
LOG4JS_CONFIG: 'log4js-config.json',
|
||||
// default log level on production should be info
|
||||
|
||||
@ -1,212 +1,230 @@
|
||||
import { EventProtocol as DbEvent } from '@entity/EventProtocol'
|
||||
import { Event as DbEvent } from '@entity/Event'
|
||||
import { User as DbUser } from '@entity/User'
|
||||
import { ContributionMessage as DbContributionMessage } from '@entity/ContributionMessage'
|
||||
import { Contribution as DbContribution } from '@entity/Contribution'
|
||||
import { Transaction as DbTransaction } from '@entity/Transaction'
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { EventProtocolType } from './EventProtocolType'
|
||||
|
||||
export const Event = (
|
||||
type: EventProtocolType,
|
||||
userId: number,
|
||||
xUserId: number | null = null,
|
||||
xCommunityId: number | null = null,
|
||||
transactionId: number | null = null,
|
||||
contributionId: number | null = null,
|
||||
affectedUser: DbUser,
|
||||
actingUser: DbUser,
|
||||
involvedUser: DbUser | null = null,
|
||||
involvedTransaction: DbTransaction | null = null,
|
||||
involvedContribution: DbContribution | null = null,
|
||||
involvedContributionMessage: DbContributionMessage | null = null,
|
||||
amount: Decimal | null = null,
|
||||
messageId: number | null = null,
|
||||
): DbEvent => {
|
||||
const event = new DbEvent()
|
||||
event.type = type
|
||||
event.userId = userId
|
||||
event.xUserId = xUserId
|
||||
event.xCommunityId = xCommunityId
|
||||
event.transactionId = transactionId
|
||||
event.contributionId = contributionId
|
||||
event.affectedUser = affectedUser
|
||||
event.actingUser = actingUser
|
||||
event.involvedUser = involvedUser
|
||||
event.involvedTransaction = involvedTransaction
|
||||
event.involvedContribution = involvedContribution
|
||||
event.involvedContributionMessage = involvedContributionMessage
|
||||
event.amount = amount
|
||||
event.messageId = messageId
|
||||
return event
|
||||
}
|
||||
|
||||
export const EVENT_CONTRIBUTION_CREATE = async (
|
||||
userId: number,
|
||||
contributionId: number,
|
||||
user: DbUser,
|
||||
contribution: DbContribution,
|
||||
amount: Decimal,
|
||||
): Promise<DbEvent> =>
|
||||
Event(
|
||||
EventProtocolType.CONTRIBUTION_CREATE,
|
||||
userId,
|
||||
user,
|
||||
user,
|
||||
null,
|
||||
null,
|
||||
contribution,
|
||||
null,
|
||||
contributionId,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
export const EVENT_CONTRIBUTION_DELETE = async (
|
||||
userId: number,
|
||||
contributionId: number,
|
||||
user: DbUser,
|
||||
contribution: DbContribution,
|
||||
amount: Decimal,
|
||||
): Promise<DbEvent> =>
|
||||
Event(
|
||||
EventProtocolType.CONTRIBUTION_DELETE,
|
||||
userId,
|
||||
user,
|
||||
user,
|
||||
null,
|
||||
null,
|
||||
contribution,
|
||||
null,
|
||||
contributionId,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
export const EVENT_CONTRIBUTION_UPDATE = async (
|
||||
userId: number,
|
||||
contributionId: number,
|
||||
user: DbUser,
|
||||
contribution: DbContribution,
|
||||
amount: Decimal,
|
||||
): Promise<DbEvent> =>
|
||||
Event(
|
||||
EventProtocolType.CONTRIBUTION_UPDATE,
|
||||
userId,
|
||||
user,
|
||||
user,
|
||||
null,
|
||||
null,
|
||||
contribution,
|
||||
null,
|
||||
contributionId,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
// TODO what was user_id? affected or moderator user?
|
||||
// await EVENT_ADMIN_CONTRIBUTION_CREATE(moderator.id, contribution.id, amount)
|
||||
export const EVENT_ADMIN_CONTRIBUTION_CREATE = async (
|
||||
userId: number,
|
||||
contributionId: number,
|
||||
user: DbUser,
|
||||
moderator: DbUser,
|
||||
contribution: DbContribution,
|
||||
amount: Decimal,
|
||||
): Promise<DbEvent> =>
|
||||
Event(
|
||||
EventProtocolType.ADMIN_CONTRIBUTION_CREATE,
|
||||
userId,
|
||||
user,
|
||||
moderator,
|
||||
null,
|
||||
null,
|
||||
contribution,
|
||||
null,
|
||||
contributionId,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
// TODO await EVENT_ADMIN_CONTRIBUTION_UPDATE(emailContact.user.id, contributionToUpdate.id, amount)
|
||||
export const EVENT_ADMIN_CONTRIBUTION_UPDATE = async (
|
||||
userId: number,
|
||||
contributionId: number,
|
||||
user: DbUser,
|
||||
moderator: DbUser,
|
||||
contribution: DbContribution,
|
||||
amount: Decimal,
|
||||
): Promise<DbEvent> =>
|
||||
Event(
|
||||
EventProtocolType.ADMIN_CONTRIBUTION_UPDATE,
|
||||
userId,
|
||||
user,
|
||||
moderator,
|
||||
null,
|
||||
null,
|
||||
contribution,
|
||||
null,
|
||||
contributionId,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
// TODO await EVENT_ADMIN_CONTRIBUTION_DELETE(contribution.userId, contribution.id, contribution.amount)
|
||||
export const EVENT_ADMIN_CONTRIBUTION_DELETE = async (
|
||||
userId: number,
|
||||
contributionId: number,
|
||||
user: DbUser,
|
||||
moderator: DbUser,
|
||||
contribution: DbContribution,
|
||||
amount: Decimal,
|
||||
): Promise<DbEvent> =>
|
||||
Event(
|
||||
EventProtocolType.ADMIN_CONTRIBUTION_DELETE,
|
||||
userId,
|
||||
user,
|
||||
moderator,
|
||||
null,
|
||||
null,
|
||||
contribution,
|
||||
null,
|
||||
contributionId,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
// TODO await EVENT_CONTRIBUTION_CONFIRM(user.id, contribution.id, contribution.amount)
|
||||
export const EVENT_CONTRIBUTION_CONFIRM = async (
|
||||
userId: number,
|
||||
contributionId: number,
|
||||
user: DbUser,
|
||||
moderator: DbUser,
|
||||
contribution: DbContribution,
|
||||
amount: Decimal,
|
||||
): Promise<DbEvent> =>
|
||||
Event(
|
||||
EventProtocolType.CONTRIBUTION_CONFIRM,
|
||||
userId,
|
||||
user,
|
||||
moderator,
|
||||
null,
|
||||
null,
|
||||
contribution,
|
||||
null,
|
||||
contributionId,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
// TODO await EVENT_ADMIN_CONTRIBUTION_DENY(
|
||||
// contributionToUpdate.userId,
|
||||
// moderator.id,
|
||||
// contributionToUpdate.id,
|
||||
// contributionToUpdate.amount,
|
||||
// )
|
||||
// x User = moderator
|
||||
export const EVENT_ADMIN_CONTRIBUTION_DENY = async (
|
||||
userId: number,
|
||||
xUserId: number,
|
||||
contributionId: number,
|
||||
user: DbUser,
|
||||
moderator: DbUser,
|
||||
contribution: DbContribution,
|
||||
amount: Decimal,
|
||||
): Promise<DbEvent> =>
|
||||
Event(
|
||||
EventProtocolType.ADMIN_CONTRIBUTION_DENY,
|
||||
userId,
|
||||
xUserId,
|
||||
user,
|
||||
moderator,
|
||||
null,
|
||||
null,
|
||||
contributionId,
|
||||
contribution,
|
||||
null,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
export const EVENT_TRANSACTION_SEND = async (
|
||||
userId: number,
|
||||
xUserId: number,
|
||||
transactionId: number,
|
||||
user: DbUser,
|
||||
involvedUser: DbUser,
|
||||
transaction: DbTransaction,
|
||||
amount: Decimal,
|
||||
): Promise<DbEvent> =>
|
||||
Event(
|
||||
EventProtocolType.TRANSACTION_SEND,
|
||||
userId,
|
||||
xUserId,
|
||||
user,
|
||||
user,
|
||||
involvedUser,
|
||||
transaction,
|
||||
null,
|
||||
transactionId,
|
||||
null,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
// TODO acting user = involved user
|
||||
export const EVENT_TRANSACTION_RECEIVE = async (
|
||||
userId: number,
|
||||
xUserId: number,
|
||||
transactionId: number,
|
||||
user: DbUser,
|
||||
involvedUser: DbUser,
|
||||
transaction: DbTransaction,
|
||||
amount: Decimal,
|
||||
): Promise<DbEvent> =>
|
||||
Event(
|
||||
EventProtocolType.TRANSACTION_RECEIVE,
|
||||
userId,
|
||||
xUserId,
|
||||
user,
|
||||
involvedUser,
|
||||
involvedUser,
|
||||
transaction,
|
||||
null,
|
||||
transactionId,
|
||||
null,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
export const EVENT_LOGIN = async (userId: number): Promise<DbEvent> =>
|
||||
Event(EventProtocolType.LOGIN, userId, null, null, null, null, null, null).save()
|
||||
export const EVENT_LOGIN = async (user: DbUser): Promise<DbEvent> =>
|
||||
Event(EventProtocolType.LOGIN, user, user).save()
|
||||
|
||||
export const EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = async (
|
||||
userId: number,
|
||||
): Promise<DbEvent> => Event(EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, userId).save()
|
||||
export const EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = async (user: DbUser): Promise<DbEvent> =>
|
||||
Event(EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, user, { id: 0 } as DbUser).save()
|
||||
|
||||
export const EVENT_SEND_CONFIRMATION_EMAIL = async (userId: number): Promise<DbEvent> =>
|
||||
Event(EventProtocolType.SEND_CONFIRMATION_EMAIL, userId).save()
|
||||
export const EVENT_SEND_CONFIRMATION_EMAIL = async (user: DbUser): Promise<DbEvent> =>
|
||||
Event(EventProtocolType.SEND_CONFIRMATION_EMAIL, user, user).save()
|
||||
|
||||
export const EVENT_ADMIN_SEND_CONFIRMATION_EMAIL = async (userId: number): Promise<DbEvent> =>
|
||||
Event(EventProtocolType.ADMIN_SEND_CONFIRMATION_EMAIL, userId).save()
|
||||
export const EVENT_ADMIN_SEND_CONFIRMATION_EMAIL = async (
|
||||
user: DbUser,
|
||||
moderator: DbUser,
|
||||
): Promise<DbEvent> =>
|
||||
Event(EventProtocolType.ADMIN_SEND_CONFIRMATION_EMAIL, user, moderator).save()
|
||||
|
||||
/* export const EVENT_REDEEM_REGISTER = async (
|
||||
userId: number,
|
||||
transactionId: number | null = null,
|
||||
contributionId: number | null = null,
|
||||
): Promise<Event> =>
|
||||
Event(
|
||||
EventProtocolType.REDEEM_REGISTER,
|
||||
userId,
|
||||
null,
|
||||
null,
|
||||
transactionId,
|
||||
contributionId,
|
||||
).save()
|
||||
*/
|
||||
export const EVENT_REGISTER = async (user: DbUser): Promise<DbEvent> =>
|
||||
Event(EventProtocolType.REGISTER, user, user).save()
|
||||
|
||||
export const EVENT_REGISTER = async (userId: number): Promise<DbEvent> =>
|
||||
Event(EventProtocolType.REGISTER, userId).save()
|
||||
|
||||
export const EVENT_ACTIVATE_ACCOUNT = async (userId: number): Promise<DbEvent> =>
|
||||
Event(EventProtocolType.ACTIVATE_ACCOUNT, userId).save()
|
||||
export const EVENT_ACTIVATE_ACCOUNT = async (user: DbUser): Promise<DbEvent> =>
|
||||
Event(EventProtocolType.ACTIVATE_ACCOUNT, user, user).save()
|
||||
|
||||
@ -38,7 +38,7 @@ import { userFactory } from '@/seeds/factory/user'
|
||||
import { creationFactory } from '@/seeds/factory/creation'
|
||||
import { creations } from '@/seeds/creation/index'
|
||||
import { peterLustig } from '@/seeds/users/peter-lustig'
|
||||
import { EventProtocol } from '@entity/EventProtocol'
|
||||
import { Event as DbEvent } from '@entity/Event'
|
||||
import { Contribution } from '@entity/Contribution'
|
||||
import { Transaction as DbTransaction } from '@entity/Transaction'
|
||||
import { User } from '@entity/User'
|
||||
@ -284,7 +284,7 @@ describe('ContributionResolver', () => {
|
||||
})
|
||||
|
||||
it('stores the CONTRIBUTION_CREATE event in the database', async () => {
|
||||
await expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
await expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.CONTRIBUTION_CREATE,
|
||||
amount: expect.decimalEqual(100),
|
||||
@ -589,7 +589,7 @@ describe('ContributionResolver', () => {
|
||||
variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' },
|
||||
})
|
||||
|
||||
await expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
await expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.CONTRIBUTION_UPDATE,
|
||||
amount: expect.decimalEqual(10),
|
||||
@ -819,7 +819,7 @@ describe('ContributionResolver', () => {
|
||||
})
|
||||
|
||||
it('stores the ADMIN_CONTRIBUTION_DENY event in the database', async () => {
|
||||
await expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
await expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.ADMIN_CONTRIBUTION_DENY,
|
||||
userId: bibi.id,
|
||||
@ -934,7 +934,7 @@ describe('ContributionResolver', () => {
|
||||
})
|
||||
|
||||
it('stores the CONTRIBUTION_DELETE event in the database', async () => {
|
||||
await expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
await expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.CONTRIBUTION_DELETE,
|
||||
contributionId: contributionToDelete.data.createContribution.id,
|
||||
@ -2082,7 +2082,7 @@ describe('ContributionResolver', () => {
|
||||
})
|
||||
|
||||
it('stores the ADMIN_CONTRIBUTION_CREATE event in the database', async () => {
|
||||
await expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
await expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.ADMIN_CONTRIBUTION_CREATE,
|
||||
userId: admin.id,
|
||||
@ -2353,7 +2353,7 @@ describe('ContributionResolver', () => {
|
||||
})
|
||||
|
||||
it('stores the ADMIN_CONTRIBUTION_UPDATE event in the database', async () => {
|
||||
await expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
await expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE,
|
||||
userId: admin.id,
|
||||
@ -2394,7 +2394,7 @@ describe('ContributionResolver', () => {
|
||||
})
|
||||
|
||||
it('stores the ADMIN_CONTRIBUTION_UPDATE event in the database', async () => {
|
||||
await expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
await expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE,
|
||||
userId: admin.id,
|
||||
@ -2573,7 +2573,7 @@ describe('ContributionResolver', () => {
|
||||
})
|
||||
|
||||
it('stores the ADMIN_CONTRIBUTION_DELETE event in the database', async () => {
|
||||
await expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
await expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.ADMIN_CONTRIBUTION_DELETE,
|
||||
userId: admin.id,
|
||||
@ -2717,7 +2717,7 @@ describe('ContributionResolver', () => {
|
||||
})
|
||||
|
||||
it('stores the CONTRIBUTION_CONFIRM event in the database', async () => {
|
||||
await expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
await expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.CONTRIBUTION_CONFIRM,
|
||||
}),
|
||||
@ -2749,7 +2749,7 @@ describe('ContributionResolver', () => {
|
||||
})
|
||||
|
||||
it('stores the SEND_CONFIRMATION_EMAIL event in the database', async () => {
|
||||
await expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
await expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.SEND_CONFIRMATION_EMAIL,
|
||||
}),
|
||||
|
||||
@ -91,7 +91,7 @@ export class ContributionResolver {
|
||||
logger.trace('contribution to save', contribution)
|
||||
await DbContribution.save(contribution)
|
||||
|
||||
await EVENT_CONTRIBUTION_CREATE(user.id, contribution.id, amount)
|
||||
await EVENT_CONTRIBUTION_CREATE(user, contribution, amount)
|
||||
|
||||
return new UnconfirmedContribution(contribution, user, creations)
|
||||
}
|
||||
@ -119,7 +119,7 @@ export class ContributionResolver {
|
||||
contribution.deletedAt = new Date()
|
||||
await contribution.save()
|
||||
|
||||
await EVENT_CONTRIBUTION_DELETE(user.id, contribution.id, contribution.amount)
|
||||
await EVENT_CONTRIBUTION_DELETE(user, contribution, contribution.amount)
|
||||
|
||||
const res = await contribution.softRemove()
|
||||
return !!res
|
||||
@ -267,7 +267,7 @@ export class ContributionResolver {
|
||||
contributionToUpdate.updatedAt = new Date()
|
||||
DbContribution.save(contributionToUpdate)
|
||||
|
||||
await EVENT_CONTRIBUTION_UPDATE(user.id, contributionId, amount)
|
||||
await EVENT_CONTRIBUTION_UPDATE(user, contributionToUpdate, amount)
|
||||
|
||||
return new UnconfirmedContribution(contributionToUpdate, user, creations)
|
||||
}
|
||||
@ -324,7 +324,7 @@ export class ContributionResolver {
|
||||
|
||||
await DbContribution.save(contribution)
|
||||
|
||||
await EVENT_ADMIN_CONTRIBUTION_CREATE(moderator.id, contribution.id, amount)
|
||||
await EVENT_ADMIN_CONTRIBUTION_CREATE(emailContact.user, moderator, contribution, amount)
|
||||
|
||||
return getUserCreation(emailContact.userId, clientTimezoneOffset)
|
||||
}
|
||||
@ -419,7 +419,12 @@ export class ContributionResolver {
|
||||
|
||||
result.creation = await getUserCreation(emailContact.user.id, clientTimezoneOffset)
|
||||
|
||||
await EVENT_ADMIN_CONTRIBUTION_UPDATE(emailContact.user.id, contributionToUpdate.id, amount)
|
||||
await EVENT_ADMIN_CONTRIBUTION_UPDATE(
|
||||
emailContact.user,
|
||||
moderator,
|
||||
contributionToUpdate,
|
||||
amount,
|
||||
)
|
||||
|
||||
return result
|
||||
}
|
||||
@ -490,7 +495,13 @@ export class ContributionResolver {
|
||||
await contribution.save()
|
||||
const res = await contribution.softRemove()
|
||||
|
||||
await EVENT_ADMIN_CONTRIBUTION_DELETE(contribution.userId, contribution.id, contribution.amount)
|
||||
// TODO allow to query the user with relation
|
||||
await EVENT_ADMIN_CONTRIBUTION_DELETE(
|
||||
{ id: contribution.userId } as DbUser,
|
||||
moderator,
|
||||
contribution,
|
||||
contribution.amount,
|
||||
)
|
||||
|
||||
sendContributionDeletedEmail({
|
||||
firstName: user.firstName,
|
||||
@ -603,7 +614,7 @@ export class ContributionResolver {
|
||||
await queryRunner.release()
|
||||
}
|
||||
|
||||
await EVENT_CONTRIBUTION_CONFIRM(user.id, contribution.id, contribution.amount)
|
||||
await EVENT_CONTRIBUTION_CONFIRM(user, moderatorUser, contribution, contribution.amount)
|
||||
} finally {
|
||||
releaseLock()
|
||||
}
|
||||
@ -694,9 +705,9 @@ export class ContributionResolver {
|
||||
const res = await contributionToUpdate.save()
|
||||
|
||||
await EVENT_ADMIN_CONTRIBUTION_DENY(
|
||||
contributionToUpdate.userId,
|
||||
moderator.id,
|
||||
contributionToUpdate.id,
|
||||
user,
|
||||
moderator,
|
||||
contributionToUpdate,
|
||||
contributionToUpdate.amount,
|
||||
)
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ import { bobBaumeister } from '@/seeds/users/bob-baumeister'
|
||||
import { garrickOllivander } from '@/seeds/users/garrick-ollivander'
|
||||
import { peterLustig } from '@/seeds/users/peter-lustig'
|
||||
import { stephenHawking } from '@/seeds/users/stephen-hawking'
|
||||
import { EventProtocol } from '@entity/EventProtocol'
|
||||
import { Event as DbEvent } from '@entity/Event'
|
||||
import { Transaction } from '@entity/Transaction'
|
||||
import { User } from '@entity/User'
|
||||
import { cleanDB, testEnvironment } from '@test/helpers'
|
||||
@ -337,7 +337,7 @@ describe('send coins', () => {
|
||||
memo: 'unrepeatable memo',
|
||||
})
|
||||
|
||||
expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.TRANSACTION_SEND,
|
||||
userId: user[1].id,
|
||||
@ -354,7 +354,7 @@ describe('send coins', () => {
|
||||
memo: 'unrepeatable memo',
|
||||
})
|
||||
|
||||
expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.TRANSACTION_RECEIVE,
|
||||
userId: user[0].id,
|
||||
|
||||
@ -138,16 +138,17 @@ export const executeTransaction = async (
|
||||
logger.info(`commit Transaction successful...`)
|
||||
|
||||
await EVENT_TRANSACTION_SEND(
|
||||
transactionSend.userId,
|
||||
transactionSend.linkedUserId,
|
||||
transactionSend.id,
|
||||
sender,
|
||||
recipient,
|
||||
transactionSend,
|
||||
// TODO why mul -1?
|
||||
transactionSend.amount.mul(-1),
|
||||
)
|
||||
|
||||
await EVENT_TRANSACTION_RECEIVE(
|
||||
transactionReceive.userId,
|
||||
transactionReceive.linkedUserId,
|
||||
transactionReceive.id,
|
||||
recipient,
|
||||
sender,
|
||||
transactionReceive,
|
||||
transactionReceive.amount,
|
||||
)
|
||||
} catch (e) {
|
||||
|
||||
@ -35,7 +35,7 @@ import { transactionLinkFactory } from '@/seeds/factory/transactionLink'
|
||||
import { ContributionLink } from '@model/ContributionLink'
|
||||
import { TransactionLink } from '@entity/TransactionLink'
|
||||
import { EventProtocolType } from '@/event/EventProtocolType'
|
||||
import { EventProtocol } from '@entity/EventProtocol'
|
||||
import { Event as DbEvent } from '@entity/Event'
|
||||
import { validate as validateUUID, version as versionUUID } from 'uuid'
|
||||
import { peterLustig } from '@/seeds/users/peter-lustig'
|
||||
import { UserContact } from '@entity/UserContact'
|
||||
@ -182,7 +182,7 @@ describe('UserResolver', () => {
|
||||
{ email: 'peter@lustig.de' },
|
||||
{ relations: ['user'] },
|
||||
)
|
||||
expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.REGISTER,
|
||||
userId: userConatct.user.id,
|
||||
@ -211,7 +211,7 @@ describe('UserResolver', () => {
|
||||
})
|
||||
|
||||
it('stores the SEND_CONFIRMATION_EMAIL event in the database', () => {
|
||||
expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.SEND_CONFIRMATION_EMAIL,
|
||||
userId: user[0].id,
|
||||
@ -256,7 +256,7 @@ describe('UserResolver', () => {
|
||||
{ email: 'peter@lustig.de' },
|
||||
{ relations: ['user'] },
|
||||
)
|
||||
expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL,
|
||||
userId: userConatct.user.id,
|
||||
@ -356,7 +356,7 @@ describe('UserResolver', () => {
|
||||
})
|
||||
|
||||
it('stores the ACTIVATE_ACCOUNT event in the database', () => {
|
||||
expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.ACTIVATE_ACCOUNT,
|
||||
userId: user[0].id,
|
||||
@ -365,7 +365,7 @@ describe('UserResolver', () => {
|
||||
})
|
||||
|
||||
it('stores the REDEEM_REGISTER event in the database', () => {
|
||||
expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.REDEEM_REGISTER,
|
||||
userId: result.data.createUser.id,
|
||||
@ -449,7 +449,7 @@ describe('UserResolver', () => {
|
||||
})
|
||||
|
||||
it('stores the REDEEM_REGISTER event in the database', async () => {
|
||||
await expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
await expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.REDEEM_REGISTER,
|
||||
userId: newUser.data.createUser.id,
|
||||
@ -680,7 +680,7 @@ describe('UserResolver', () => {
|
||||
{ email: 'bibi@bloxberg.de' },
|
||||
{ relations: ['user'] },
|
||||
)
|
||||
expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.LOGIN,
|
||||
userId: userConatct.user.id,
|
||||
@ -928,7 +928,7 @@ describe('UserResolver', () => {
|
||||
})
|
||||
|
||||
it('stores the LOGIN event in the database', () => {
|
||||
expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.LOGIN,
|
||||
userId: user[0].id,
|
||||
@ -1847,7 +1847,7 @@ describe('UserResolver', () => {
|
||||
{ email: 'bibi@bloxberg.de' },
|
||||
{ relations: ['user'] },
|
||||
)
|
||||
expect(EventProtocol.find()).resolves.toContainEqual(
|
||||
expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventProtocolType.ADMIN_SEND_CONFIRMATION_EMAIL,
|
||||
userId: userConatct.user.id,
|
||||
|
||||
@ -16,7 +16,9 @@ import { getConnection, getCustomRepository, IsNull, Not } from '@dbTools/typeor
|
||||
import { User as DbUser } from '@entity/User'
|
||||
import { UserContact as DbUserContact } from '@entity/UserContact'
|
||||
import { TransactionLink as DbTransactionLink } from '@entity/TransactionLink'
|
||||
import { Transaction as DbTransaction } from '@entity/Transaction'
|
||||
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
|
||||
import { Contribution as DbContribution } from '@entity/Contribution'
|
||||
import { UserRepository } from '@repository/User'
|
||||
|
||||
import { User } from '@model/User'
|
||||
@ -178,7 +180,7 @@ export class UserResolver {
|
||||
value: encode(dbUser.gradidoID),
|
||||
})
|
||||
|
||||
await EVENT_LOGIN(user.id)
|
||||
await EVENT_LOGIN(dbUser)
|
||||
logger.info(`successful Login: ${JSON.stringify(user, null, 2)}`)
|
||||
return user
|
||||
}
|
||||
@ -248,7 +250,7 @@ export class UserResolver {
|
||||
language: foundUser.language, // use language of the emails owner for sending
|
||||
})
|
||||
|
||||
await EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL(foundUser.id)
|
||||
await EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL(foundUser)
|
||||
|
||||
logger.info(
|
||||
`sendAccountMultiRegistrationEmail by ${firstName} ${lastName} to ${foundUser.firstName} ${foundUser.lastName} <${email}>`,
|
||||
@ -266,7 +268,11 @@ export class UserResolver {
|
||||
|
||||
const gradidoID = await newGradidoID()
|
||||
|
||||
const eventRegisterRedeem = Event(EventProtocolType.REDEEM_REGISTER, 0)
|
||||
const eventRegisterRedeem = Event(
|
||||
EventProtocolType.REDEEM_REGISTER,
|
||||
{ id: 0 } as DbUser,
|
||||
{ id: 0 } as DbUser,
|
||||
)
|
||||
let dbUser = new DbUser()
|
||||
dbUser.gradidoID = gradidoID
|
||||
dbUser.firstName = firstName
|
||||
@ -283,14 +289,16 @@ export class UserResolver {
|
||||
logger.info('redeemCode found contributionLink=' + contributionLink)
|
||||
if (contributionLink) {
|
||||
dbUser.contributionLinkId = contributionLink.id
|
||||
eventRegisterRedeem.contributionId = contributionLink.id
|
||||
// TODO this is so wrong
|
||||
eventRegisterRedeem.involvedContribution = { id: contributionLink.id } as DbContribution
|
||||
}
|
||||
} else {
|
||||
const transactionLink = await DbTransactionLink.findOne({ code: redeemCode })
|
||||
logger.info('redeemCode found transactionLink=' + transactionLink)
|
||||
if (transactionLink) {
|
||||
dbUser.referrerId = transactionLink.userId
|
||||
eventRegisterRedeem.transactionId = transactionLink.id
|
||||
// TODO this is so wrong
|
||||
eventRegisterRedeem.involvedTransaction = { id: transactionLink.id } as DbTransaction
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -329,7 +337,7 @@ export class UserResolver {
|
||||
})
|
||||
logger.info(`sendAccountActivationEmail of ${firstName}.${lastName} to ${email}`)
|
||||
|
||||
await EVENT_SEND_CONFIRMATION_EMAIL(dbUser.id)
|
||||
await EVENT_SEND_CONFIRMATION_EMAIL(dbUser)
|
||||
|
||||
if (!emailSent) {
|
||||
logger.debug(`Account confirmation link: ${activationLink}`)
|
||||
@ -346,10 +354,11 @@ export class UserResolver {
|
||||
logger.info('createUser() successful...')
|
||||
|
||||
if (redeemCode) {
|
||||
eventRegisterRedeem.userId = dbUser.id
|
||||
eventRegisterRedeem.affectedUser = dbUser
|
||||
eventRegisterRedeem.actingUser = dbUser
|
||||
await eventRegisterRedeem.save()
|
||||
} else {
|
||||
await EVENT_REGISTER(dbUser.id)
|
||||
await EVENT_REGISTER(dbUser)
|
||||
}
|
||||
|
||||
return new User(dbUser)
|
||||
@ -465,7 +474,7 @@ export class UserResolver {
|
||||
await queryRunner.commitTransaction()
|
||||
logger.info('User and UserContact data written successfully...')
|
||||
|
||||
await EVENT_ACTIVATE_ACCOUNT(user.id)
|
||||
await EVENT_ACTIVATE_ACCOUNT(user)
|
||||
} catch (e) {
|
||||
await queryRunner.rollbackTransaction()
|
||||
throw new LogError('Error on writing User and User Contact data', e)
|
||||
@ -775,9 +784,13 @@ export class UserResolver {
|
||||
return null
|
||||
}
|
||||
|
||||
// TODO this is an admin function - needs refactor
|
||||
@Authorized([RIGHTS.SEND_ACTIVATION_EMAIL])
|
||||
@Mutation(() => Boolean)
|
||||
async sendActivationEmail(@Arg('email') email: string): Promise<boolean> {
|
||||
async sendActivationEmail(
|
||||
@Arg('email') email: string,
|
||||
@Ctx() context: Context,
|
||||
): Promise<boolean> {
|
||||
email = email.trim().toLowerCase()
|
||||
// const user = await dbUser.findOne({ id: emailContact.userId })
|
||||
const user = await findUserByEmail(email)
|
||||
@ -802,7 +815,7 @@ export class UserResolver {
|
||||
if (!emailSent) {
|
||||
logger.info(`Account confirmation link: ${activationLink}`)
|
||||
} else {
|
||||
await EVENT_ADMIN_SEND_CONFIRMATION_EMAIL(user.id)
|
||||
await EVENT_ADMIN_SEND_CONFIRMATION_EMAIL(user, getUser(context))
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user