Merge pull request #2720 from gradido/event_refactor_database

refactor(database): event table
This commit is contained in:
Ulf Gebhardt 2023-03-14 22:29:19 +01:00 committed by GitHub
commit d3e7b68652
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 405 additions and 181 deletions

View File

@ -10,7 +10,7 @@ Decimal.set({
}) })
const constants = { 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 DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0
LOG4JS_CONFIG: 'log4js-config.json', LOG4JS_CONFIG: 'log4js-config.json',
// default log level on production should be info // default log level on production should be info

View File

@ -1,212 +1,217 @@
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 Decimal from 'decimal.js-light'
import { EventProtocolType } from './EventProtocolType' import { EventProtocolType } from './EventProtocolType'
export const Event = ( export const Event = (
type: EventProtocolType, type: EventProtocolType,
userId: number, affectedUser: DbUser,
xUserId: number | null = null, actingUser: DbUser,
xCommunityId: number | null = null, involvedUser: DbUser | null = null,
transactionId: number | null = null, involvedTransaction: DbTransaction | null = null,
contributionId: number | null = null, involvedContribution: DbContribution | null = null,
involvedContributionMessage: DbContributionMessage | null = null,
amount: Decimal | null = null, amount: Decimal | null = null,
messageId: number | null = null,
): DbEvent => { ): DbEvent => {
const event = new DbEvent() const event = new DbEvent()
event.type = type event.type = type
event.userId = userId event.affectedUser = affectedUser
event.xUserId = xUserId event.actingUser = actingUser
event.xCommunityId = xCommunityId event.involvedUser = involvedUser
event.transactionId = transactionId event.involvedTransaction = involvedTransaction
event.contributionId = contributionId event.involvedContribution = involvedContribution
event.involvedContributionMessage = involvedContributionMessage
event.amount = amount event.amount = amount
event.messageId = messageId
return event return event
} }
export const EVENT_CONTRIBUTION_CREATE = async ( export const EVENT_CONTRIBUTION_CREATE = async (
userId: number, user: DbUser,
contributionId: number, contribution: DbContribution,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
Event( Event(
EventProtocolType.CONTRIBUTION_CREATE, EventProtocolType.CONTRIBUTION_CREATE,
userId, user,
user,
null, null,
null, null,
contribution,
null, null,
contributionId,
amount, amount,
).save() ).save()
export const EVENT_CONTRIBUTION_DELETE = async ( export const EVENT_CONTRIBUTION_DELETE = async (
userId: number, user: DbUser,
contributionId: number, contribution: DbContribution,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
Event( Event(
EventProtocolType.CONTRIBUTION_DELETE, EventProtocolType.CONTRIBUTION_DELETE,
userId, user,
user,
null, null,
null, null,
contribution,
null, null,
contributionId,
amount, amount,
).save() ).save()
export const EVENT_CONTRIBUTION_UPDATE = async ( export const EVENT_CONTRIBUTION_UPDATE = async (
userId: number, user: DbUser,
contributionId: number, contribution: DbContribution,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
Event( Event(
EventProtocolType.CONTRIBUTION_UPDATE, EventProtocolType.CONTRIBUTION_UPDATE,
userId, user,
user,
null, null,
null, null,
contribution,
null, null,
contributionId,
amount, amount,
).save() ).save()
export const EVENT_ADMIN_CONTRIBUTION_CREATE = async ( export const EVENT_ADMIN_CONTRIBUTION_CREATE = async (
userId: number, user: DbUser,
contributionId: number, moderator: DbUser,
contribution: DbContribution,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
Event( Event(
EventProtocolType.ADMIN_CONTRIBUTION_CREATE, EventProtocolType.ADMIN_CONTRIBUTION_CREATE,
userId, user,
moderator,
null, null,
null, null,
contribution,
null, null,
contributionId,
amount, amount,
).save() ).save()
export const EVENT_ADMIN_CONTRIBUTION_UPDATE = async ( export const EVENT_ADMIN_CONTRIBUTION_UPDATE = async (
userId: number, user: DbUser,
contributionId: number, moderator: DbUser,
contribution: DbContribution,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
Event( Event(
EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, EventProtocolType.ADMIN_CONTRIBUTION_UPDATE,
userId, user,
moderator,
null, null,
null, null,
contribution,
null, null,
contributionId,
amount, amount,
).save() ).save()
export const EVENT_ADMIN_CONTRIBUTION_DELETE = async ( export const EVENT_ADMIN_CONTRIBUTION_DELETE = async (
userId: number, user: DbUser,
contributionId: number, moderator: DbUser,
contribution: DbContribution,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
Event( Event(
EventProtocolType.ADMIN_CONTRIBUTION_DELETE, EventProtocolType.ADMIN_CONTRIBUTION_DELETE,
userId, user,
moderator,
null, null,
null, null,
contribution,
null, null,
contributionId,
amount, amount,
).save() ).save()
export const EVENT_CONTRIBUTION_CONFIRM = async ( export const EVENT_CONTRIBUTION_CONFIRM = async (
userId: number, user: DbUser,
contributionId: number, moderator: DbUser,
contribution: DbContribution,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
Event( Event(
EventProtocolType.CONTRIBUTION_CONFIRM, EventProtocolType.CONTRIBUTION_CONFIRM,
userId, user,
moderator,
null, null,
null, null,
contribution,
null, null,
contributionId,
amount, amount,
).save() ).save()
export const EVENT_ADMIN_CONTRIBUTION_DENY = async ( export const EVENT_ADMIN_CONTRIBUTION_DENY = async (
userId: number, user: DbUser,
xUserId: number, moderator: DbUser,
contributionId: number, contribution: DbContribution,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
Event( Event(
EventProtocolType.ADMIN_CONTRIBUTION_DENY, EventProtocolType.ADMIN_CONTRIBUTION_DENY,
userId, user,
xUserId, moderator,
null, null,
null, null,
contributionId, contribution,
null,
amount, amount,
).save() ).save()
export const EVENT_TRANSACTION_SEND = async ( export const EVENT_TRANSACTION_SEND = async (
userId: number, user: DbUser,
xUserId: number, involvedUser: DbUser,
transactionId: number, transaction: DbTransaction,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
Event( Event(
EventProtocolType.TRANSACTION_SEND, EventProtocolType.TRANSACTION_SEND,
userId, user,
xUserId, user,
involvedUser,
transaction,
null, null,
transactionId,
null, null,
amount, amount,
).save() ).save()
export const EVENT_TRANSACTION_RECEIVE = async ( export const EVENT_TRANSACTION_RECEIVE = async (
userId: number, user: DbUser,
xUserId: number, involvedUser: DbUser,
transactionId: number, transaction: DbTransaction,
amount: Decimal, amount: Decimal,
): Promise<DbEvent> => ): Promise<DbEvent> =>
Event( Event(
EventProtocolType.TRANSACTION_RECEIVE, EventProtocolType.TRANSACTION_RECEIVE,
userId, user,
xUserId, involvedUser,
involvedUser,
transaction,
null, null,
transactionId,
null, null,
amount, amount,
).save() ).save()
export const EVENT_LOGIN = async (userId: number): Promise<DbEvent> => export const EVENT_LOGIN = async (user: DbUser): Promise<DbEvent> =>
Event(EventProtocolType.LOGIN, userId, null, null, null, null, null, null).save() Event(EventProtocolType.LOGIN, user, user).save()
export const EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = async ( export const EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = async (user: DbUser): Promise<DbEvent> =>
userId: number, Event(EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, user, { id: 0 } as DbUser).save()
): Promise<DbEvent> => Event(EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, userId).save()
export const EVENT_SEND_CONFIRMATION_EMAIL = async (userId: number): Promise<DbEvent> => export const EVENT_SEND_CONFIRMATION_EMAIL = async (user: DbUser): Promise<DbEvent> =>
Event(EventProtocolType.SEND_CONFIRMATION_EMAIL, userId).save() Event(EventProtocolType.SEND_CONFIRMATION_EMAIL, user, user).save()
export const EVENT_ADMIN_SEND_CONFIRMATION_EMAIL = async (userId: number): Promise<DbEvent> => export const EVENT_ADMIN_SEND_CONFIRMATION_EMAIL = async (
Event(EventProtocolType.ADMIN_SEND_CONFIRMATION_EMAIL, userId).save() user: DbUser,
moderator: DbUser,
): Promise<DbEvent> =>
Event(EventProtocolType.ADMIN_SEND_CONFIRMATION_EMAIL, user, moderator).save()
/* export const EVENT_REDEEM_REGISTER = async ( export const EVENT_REGISTER = async (user: DbUser): Promise<DbEvent> =>
userId: number, Event(EventProtocolType.REGISTER, user, user).save()
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 (userId: number): Promise<DbEvent> => export const EVENT_ACTIVATE_ACCOUNT = async (user: DbUser): Promise<DbEvent> =>
Event(EventProtocolType.REGISTER, userId).save() Event(EventProtocolType.ACTIVATE_ACCOUNT, user, user).save()
export const EVENT_ACTIVATE_ACCOUNT = async (userId: number): Promise<DbEvent> =>
Event(EventProtocolType.ACTIVATE_ACCOUNT, userId).save()

View File

@ -46,7 +46,7 @@ import { userFactory } from '@/seeds/factory/user'
import { creationFactory } from '@/seeds/factory/creation' import { creationFactory } from '@/seeds/factory/creation'
import { creations } from '@/seeds/creation/index' import { creations } from '@/seeds/creation/index'
import { peterLustig } from '@/seeds/users/peter-lustig' 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 { Contribution } from '@entity/Contribution'
import { Transaction as DbTransaction } from '@entity/Transaction' import { Transaction as DbTransaction } from '@entity/Transaction'
import { User } from '@entity/User' import { User } from '@entity/User'
@ -279,12 +279,13 @@ describe('ContributionResolver', () => {
}) })
it('stores the CONTRIBUTION_CREATE event in the database', async () => { it('stores the CONTRIBUTION_CREATE event in the database', async () => {
await expect(EventProtocol.find()).resolves.toContainEqual( await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({ expect.objectContaining({
type: EventProtocolType.CONTRIBUTION_CREATE, type: EventProtocolType.CONTRIBUTION_CREATE,
affectedUserId: bibi.id,
actingUserId: bibi.id,
involvedContributionId: pendingContribution.data.createContribution.id,
amount: expect.decimalEqual(100), amount: expect.decimalEqual(100),
contributionId: pendingContribution.data.createContribution.id,
userId: bibi.id,
}), }),
) )
}) })
@ -584,12 +585,13 @@ describe('ContributionResolver', () => {
variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' },
}) })
await expect(EventProtocol.find()).resolves.toContainEqual( await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({ expect.objectContaining({
type: EventProtocolType.CONTRIBUTION_UPDATE, type: EventProtocolType.CONTRIBUTION_UPDATE,
affectedUserId: bibi.id,
actingUserId: bibi.id,
involvedContributionId: pendingContribution.data.createContribution.id,
amount: expect.decimalEqual(10), amount: expect.decimalEqual(10),
contributionId: pendingContribution.data.createContribution.id,
userId: bibi.id,
}), }),
) )
}) })
@ -814,12 +816,12 @@ describe('ContributionResolver', () => {
}) })
it('stores the ADMIN_CONTRIBUTION_DENY event in the database', async () => { 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({ expect.objectContaining({
type: EventProtocolType.ADMIN_CONTRIBUTION_DENY, type: EventProtocolType.ADMIN_CONTRIBUTION_DENY,
userId: bibi.id, affectedUserId: bibi.id,
xUserId: admin.id, actingUserId: admin.id,
contributionId: contributionToDeny.data.createContribution.id, involvedContributionId: contributionToDeny.data.createContribution.id,
amount: expect.decimalEqual(100), amount: expect.decimalEqual(100),
}), }),
) )
@ -942,12 +944,13 @@ describe('ContributionResolver', () => {
}) })
it('stores the CONTRIBUTION_DELETE event in the database', async () => { it('stores the CONTRIBUTION_DELETE event in the database', async () => {
await expect(EventProtocol.find()).resolves.toContainEqual( await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({ expect.objectContaining({
type: EventProtocolType.CONTRIBUTION_DELETE, type: EventProtocolType.CONTRIBUTION_DELETE,
contributionId: contributionToDelete.data.createContribution.id, affectedUserId: bibi.id,
actingUserId: bibi.id,
involvedContributionId: contributionToDelete.data.createContribution.id,
amount: expect.decimalEqual(100), amount: expect.decimalEqual(100),
userId: bibi.id,
}), }),
) )
}) })
@ -2031,10 +2034,11 @@ describe('ContributionResolver', () => {
}) })
it('stores the ADMIN_CONTRIBUTION_CREATE event in the database', async () => { 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({ expect.objectContaining({
type: EventProtocolType.ADMIN_CONTRIBUTION_CREATE, type: EventProtocolType.ADMIN_CONTRIBUTION_CREATE,
userId: admin.id, affectedUserId: bibi.id,
actingUserId: admin.id,
amount: expect.decimalEqual(200), amount: expect.decimalEqual(200),
}), }),
) )
@ -2232,7 +2236,7 @@ describe('ContributionResolver', () => {
mutate({ mutate({
mutation: adminUpdateContribution, mutation: adminUpdateContribution,
variables: { variables: {
id: creation ? creation.id : -1, id: creation?.id,
email: 'peter@lustig.de', email: 'peter@lustig.de',
amount: new Decimal(300), amount: new Decimal(300),
memo: 'Danke Peter!', memo: 'Danke Peter!',
@ -2256,10 +2260,11 @@ describe('ContributionResolver', () => {
}) })
it('stores the ADMIN_CONTRIBUTION_UPDATE event in the database', async () => { 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({ expect.objectContaining({
type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE,
userId: admin.id, affectedUserId: creation?.userId,
actingUserId: admin.id,
amount: 300, amount: 300,
}), }),
) )
@ -2273,7 +2278,7 @@ describe('ContributionResolver', () => {
mutate({ mutate({
mutation: adminUpdateContribution, mutation: adminUpdateContribution,
variables: { variables: {
id: creation ? creation.id : -1, id: creation?.id,
email: 'peter@lustig.de', email: 'peter@lustig.de',
amount: new Decimal(200), amount: new Decimal(200),
memo: 'Das war leider zu Viel!', memo: 'Das war leider zu Viel!',
@ -2297,10 +2302,11 @@ describe('ContributionResolver', () => {
}) })
it('stores the ADMIN_CONTRIBUTION_UPDATE event in the database', async () => { 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({ expect.objectContaining({
type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE,
userId: admin.id, affectedUserId: creation?.userId,
actingUserId: admin.id,
amount: expect.decimalEqual(200), amount: expect.decimalEqual(200),
}), }),
) )
@ -2371,7 +2377,7 @@ describe('ContributionResolver', () => {
mutate({ mutate({
mutation: adminDeleteContribution, mutation: adminDeleteContribution,
variables: { variables: {
id: creation ? creation.id : -1, id: creation?.id,
}, },
}), }),
).resolves.toEqual( ).resolves.toEqual(
@ -2382,10 +2388,12 @@ describe('ContributionResolver', () => {
}) })
it('stores the ADMIN_CONTRIBUTION_DELETE event in the database', async () => { 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({ expect.objectContaining({
type: EventProtocolType.ADMIN_CONTRIBUTION_DELETE, type: EventProtocolType.ADMIN_CONTRIBUTION_DELETE,
userId: admin.id, affectedUserId: creation?.userId,
actingUserId: admin.id,
involvedContributionId: creation?.id,
amount: expect.decimalEqual(200), amount: expect.decimalEqual(200),
}), }),
) )
@ -2538,7 +2546,7 @@ describe('ContributionResolver', () => {
}) })
it('stores the CONTRIBUTION_CONFIRM event in the database', async () => { it('stores the CONTRIBUTION_CONFIRM event in the database', async () => {
await expect(EventProtocol.find()).resolves.toContainEqual( await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({ expect.objectContaining({
type: EventProtocolType.CONTRIBUTION_CONFIRM, type: EventProtocolType.CONTRIBUTION_CONFIRM,
}), }),
@ -2570,7 +2578,7 @@ describe('ContributionResolver', () => {
}) })
it('stores the SEND_CONFIRMATION_EMAIL event in the database', async () => { 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({ expect.objectContaining({
type: EventProtocolType.SEND_CONFIRMATION_EMAIL, type: EventProtocolType.SEND_CONFIRMATION_EMAIL,
}), }),

View File

@ -91,7 +91,7 @@ export class ContributionResolver {
logger.trace('contribution to save', contribution) logger.trace('contribution to save', contribution)
await DbContribution.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) return new UnconfirmedContribution(contribution, user, creations)
} }
@ -119,7 +119,7 @@ export class ContributionResolver {
contribution.deletedAt = new Date() contribution.deletedAt = new Date()
await contribution.save() 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() const res = await contribution.softRemove()
return !!res return !!res
@ -249,7 +249,7 @@ export class ContributionResolver {
contributionToUpdate.updatedAt = new Date() contributionToUpdate.updatedAt = new Date()
await DbContribution.save(contributionToUpdate) await DbContribution.save(contributionToUpdate)
await EVENT_CONTRIBUTION_UPDATE(user.id, contributionId, amount) await EVENT_CONTRIBUTION_UPDATE(user, contributionToUpdate, amount)
return new UnconfirmedContribution(contributionToUpdate, user, creations) return new UnconfirmedContribution(contributionToUpdate, user, creations)
} }
@ -306,7 +306,7 @@ export class ContributionResolver {
await DbContribution.save(contribution) 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) return getUserCreation(emailContact.userId, clientTimezoneOffset)
} }
@ -374,7 +374,12 @@ export class ContributionResolver {
result.creation = await getUserCreation(emailContact.user.id, clientTimezoneOffset) 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 return result
} }
@ -432,7 +437,12 @@ export class ContributionResolver {
await contribution.save() await contribution.save()
const res = await contribution.softRemove() const res = await contribution.softRemove()
await EVENT_ADMIN_CONTRIBUTION_DELETE(contribution.userId, contribution.id, contribution.amount) await EVENT_ADMIN_CONTRIBUTION_DELETE(
{ id: contribution.userId } as DbUser,
moderator,
contribution,
contribution.amount,
)
void sendContributionDeletedEmail({ void sendContributionDeletedEmail({
firstName: user.firstName, firstName: user.firstName,
@ -545,7 +555,7 @@ export class ContributionResolver {
await queryRunner.release() await queryRunner.release()
} }
await EVENT_CONTRIBUTION_CONFIRM(user.id, contribution.id, contribution.amount) await EVENT_CONTRIBUTION_CONFIRM(user, moderatorUser, contribution, contribution.amount)
} finally { } finally {
releaseLock() releaseLock()
} }
@ -632,9 +642,9 @@ export class ContributionResolver {
const res = await contributionToUpdate.save() const res = await contributionToUpdate.save()
await EVENT_ADMIN_CONTRIBUTION_DENY( await EVENT_ADMIN_CONTRIBUTION_DENY(
contributionToUpdate.userId, user,
moderator.id, moderator,
contributionToUpdate.id, contributionToUpdate,
contributionToUpdate.amount, contributionToUpdate.amount,
) )

View File

@ -18,7 +18,7 @@ import { bobBaumeister } from '@/seeds/users/bob-baumeister'
import { garrickOllivander } from '@/seeds/users/garrick-ollivander' import { garrickOllivander } from '@/seeds/users/garrick-ollivander'
import { peterLustig } from '@/seeds/users/peter-lustig' import { peterLustig } from '@/seeds/users/peter-lustig'
import { stephenHawking } from '@/seeds/users/stephen-hawking' 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 { Transaction } from '@entity/Transaction'
import { User } from '@entity/User' import { User } from '@entity/User'
import { cleanDB, testEnvironment } from '@test/helpers' import { cleanDB, testEnvironment } from '@test/helpers'
@ -341,12 +341,13 @@ describe('send coins', () => {
memo: 'unrepeatable memo', memo: 'unrepeatable memo',
}) })
await expect(EventProtocol.find()).resolves.toContainEqual( await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({ expect.objectContaining({
type: EventProtocolType.TRANSACTION_SEND, type: EventProtocolType.TRANSACTION_SEND,
userId: user[1].id, affectedUserId: user[1].id,
transactionId: transaction[0].id, actingUserId: user[1].id,
xUserId: user[0].id, involvedUserId: user[0].id,
involvedTransactionId: transaction[0].id,
}), }),
) )
}) })
@ -358,12 +359,13 @@ describe('send coins', () => {
memo: 'unrepeatable memo', memo: 'unrepeatable memo',
}) })
await expect(EventProtocol.find()).resolves.toContainEqual( await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({ expect.objectContaining({
type: EventProtocolType.TRANSACTION_RECEIVE, type: EventProtocolType.TRANSACTION_RECEIVE,
userId: user[0].id, affectedUserId: user[0].id,
transactionId: transaction[0].id, actingUserId: user[1].id,
xUserId: user[1].id, involvedUserId: user[1].id,
involvedTransactionId: transaction[0].id,
}), }),
) )
}) })

View File

@ -138,17 +138,12 @@ export const executeTransaction = async (
await queryRunner.commitTransaction() await queryRunner.commitTransaction()
logger.info(`commit Transaction successful...`) logger.info(`commit Transaction successful...`)
await EVENT_TRANSACTION_SEND( await EVENT_TRANSACTION_SEND(sender, recipient, transactionSend, transactionSend.amount)
transactionSend.userId,
transactionSend.linkedUserId,
transactionSend.id,
transactionSend.amount.mul(-1),
)
await EVENT_TRANSACTION_RECEIVE( await EVENT_TRANSACTION_RECEIVE(
transactionReceive.userId, recipient,
transactionReceive.linkedUserId, sender,
transactionReceive.id, transactionReceive,
transactionReceive.amount, transactionReceive.amount,
) )
} catch (e) { } catch (e) {

View File

@ -40,7 +40,7 @@ import { transactionLinkFactory } from '@/seeds/factory/transactionLink'
import { ContributionLink } from '@model/ContributionLink' import { ContributionLink } from '@model/ContributionLink'
import { TransactionLink } from '@entity/TransactionLink' import { TransactionLink } from '@entity/TransactionLink'
import { EventProtocolType } from '@/event/EventProtocolType' 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 { validate as validateUUID, version as versionUUID } from 'uuid'
import { peterLustig } from '@/seeds/users/peter-lustig' import { peterLustig } from '@/seeds/users/peter-lustig'
import { UserContact } from '@entity/UserContact' import { UserContact } from '@entity/UserContact'
@ -187,10 +187,11 @@ describe('UserResolver', () => {
{ email: 'peter@lustig.de' }, { email: 'peter@lustig.de' },
{ relations: ['user'] }, { relations: ['user'] },
) )
await expect(EventProtocol.find()).resolves.toContainEqual( await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({ expect.objectContaining({
type: EventProtocolType.REGISTER, type: EventProtocolType.REGISTER,
userId: userConatct.user.id, affectedUserId: userConatct.user.id,
actingUserId: userConatct.user.id,
}), }),
) )
}) })
@ -216,10 +217,11 @@ describe('UserResolver', () => {
}) })
it('stores the SEND_CONFIRMATION_EMAIL event in the database', async () => { 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({ expect.objectContaining({
type: EventProtocolType.SEND_CONFIRMATION_EMAIL, type: EventProtocolType.SEND_CONFIRMATION_EMAIL,
userId: user[0].id, affectedUserId: user[0].id,
actingUserId: user[0].id,
}), }),
) )
}) })
@ -261,10 +263,11 @@ describe('UserResolver', () => {
{ email: 'peter@lustig.de' }, { email: 'peter@lustig.de' },
{ relations: ['user'] }, { relations: ['user'] },
) )
await expect(EventProtocol.find()).resolves.toContainEqual( await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({ expect.objectContaining({
type: EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, type: EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL,
userId: userConatct.user.id, affectedUserId: userConatct.user.id,
actingUserId: 0,
}), }),
) )
}) })
@ -361,20 +364,22 @@ describe('UserResolver', () => {
}) })
it('stores the ACTIVATE_ACCOUNT event in the database', async () => { it('stores the ACTIVATE_ACCOUNT event in the database', async () => {
await expect(EventProtocol.find()).resolves.toContainEqual( await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({ expect.objectContaining({
type: EventProtocolType.ACTIVATE_ACCOUNT, type: EventProtocolType.ACTIVATE_ACCOUNT,
userId: user[0].id, affectedUserId: user[0].id,
actingUserId: user[0].id,
}), }),
) )
}) })
it('stores the REDEEM_REGISTER event in the database', async () => { it('stores the REDEEM_REGISTER event in the database', async () => {
await expect(EventProtocol.find()).resolves.toContainEqual( await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({ expect.objectContaining({
type: EventProtocolType.REDEEM_REGISTER, type: EventProtocolType.REDEEM_REGISTER,
userId: result.data.createUser.id, affectedUserId: result.data.createUser.id,
contributionId: link.id, actingUserId: result.data.createUser.id,
involvedContributionId: link.id,
}), }),
) )
}) })
@ -454,10 +459,12 @@ describe('UserResolver', () => {
}) })
it('stores the REDEEM_REGISTER event in the database', async () => { it('stores the REDEEM_REGISTER event in the database', async () => {
await expect(EventProtocol.find()).resolves.toContainEqual( await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({ expect.objectContaining({
type: EventProtocolType.REDEEM_REGISTER, type: EventProtocolType.REDEEM_REGISTER,
userId: newUser.data.createUser.id, affectedUserId: newUser.data.createUser.id,
actingUserId: newUser.data.createUser.id,
involvedTransactionId: transactionLink.id,
}), }),
) )
}) })
@ -685,10 +692,11 @@ describe('UserResolver', () => {
{ email: 'bibi@bloxberg.de' }, { email: 'bibi@bloxberg.de' },
{ relations: ['user'] }, { relations: ['user'] },
) )
await expect(EventProtocol.find()).resolves.toContainEqual( await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({ expect.objectContaining({
type: EventProtocolType.LOGIN, type: EventProtocolType.LOGIN,
userId: userConatct.user.id, affectedUserId: userConatct.user.id,
actingUserId: userConatct.user.id,
}), }),
) )
}) })
@ -933,10 +941,11 @@ describe('UserResolver', () => {
}) })
it('stores the LOGIN event in the database', async () => { it('stores the LOGIN event in the database', async () => {
await expect(EventProtocol.find()).resolves.toContainEqual( await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({ expect.objectContaining({
type: EventProtocolType.LOGIN, type: EventProtocolType.LOGIN,
userId: user[0].id, affectedUserId: user[0].id,
actingUserId: user[0].id,
}), }),
) )
}) })
@ -1852,10 +1861,11 @@ describe('UserResolver', () => {
{ email: 'bibi@bloxberg.de' }, { email: 'bibi@bloxberg.de' },
{ relations: ['user'] }, { relations: ['user'] },
) )
await expect(EventProtocol.find()).resolves.toContainEqual( await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({ expect.objectContaining({
type: EventProtocolType.ADMIN_SEND_CONFIRMATION_EMAIL, type: EventProtocolType.ADMIN_SEND_CONFIRMATION_EMAIL,
userId: userConatct.user.id, affectedUserId: userConatct.user.id,
actingUserId: admin.id,
}), }),
) )
}) })

View File

@ -20,7 +20,9 @@ import { getConnection, getCustomRepository, IsNull, Not } from '@dbTools/typeor
import { User as DbUser } from '@entity/User' import { User as DbUser } from '@entity/User'
import { UserContact as DbUserContact } from '@entity/UserContact' import { UserContact as DbUserContact } from '@entity/UserContact'
import { TransactionLink as DbTransactionLink } from '@entity/TransactionLink' import { TransactionLink as DbTransactionLink } from '@entity/TransactionLink'
import { Transaction as DbTransaction } from '@entity/Transaction'
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink' import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
import { Contribution as DbContribution } from '@entity/Contribution'
import { UserRepository } from '@repository/User' import { UserRepository } from '@repository/User'
import { User } from '@model/User' import { User } from '@model/User'
@ -182,7 +184,7 @@ export class UserResolver {
value: encode(dbUser.gradidoID), value: encode(dbUser.gradidoID),
}) })
await EVENT_LOGIN(user.id) await EVENT_LOGIN(dbUser)
logger.info(`successful Login: ${JSON.stringify(user, null, 2)}`) logger.info(`successful Login: ${JSON.stringify(user, null, 2)}`)
return user return user
} }
@ -252,7 +254,7 @@ export class UserResolver {
language: foundUser.language, // use language of the emails owner for sending 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( logger.info(
`sendAccountMultiRegistrationEmail by ${firstName} ${lastName} to ${foundUser.firstName} ${foundUser.lastName} <${email}>`, `sendAccountMultiRegistrationEmail by ${firstName} ${lastName} to ${foundUser.firstName} ${foundUser.lastName} <${email}>`,
@ -270,7 +272,11 @@ export class UserResolver {
const gradidoID = await newGradidoID() 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() let dbUser = new DbUser()
dbUser.gradidoID = gradidoID dbUser.gradidoID = gradidoID
dbUser.firstName = firstName dbUser.firstName = firstName
@ -287,14 +293,16 @@ export class UserResolver {
logger.info('redeemCode found contributionLink', contributionLink) logger.info('redeemCode found contributionLink', contributionLink)
if (contributionLink) { if (contributionLink) {
dbUser.contributionLinkId = contributionLink.id dbUser.contributionLinkId = contributionLink.id
eventRegisterRedeem.contributionId = contributionLink.id // TODO this is so wrong
eventRegisterRedeem.involvedContribution = { id: contributionLink.id } as DbContribution
} }
} else { } else {
const transactionLink = await DbTransactionLink.findOne({ code: redeemCode }) const transactionLink = await DbTransactionLink.findOne({ code: redeemCode })
logger.info('redeemCode found transactionLink', transactionLink) logger.info('redeemCode found transactionLink', transactionLink)
if (transactionLink) { if (transactionLink) {
dbUser.referrerId = transactionLink.userId dbUser.referrerId = transactionLink.userId
eventRegisterRedeem.transactionId = transactionLink.id // TODO this is so wrong
eventRegisterRedeem.involvedTransaction = { id: transactionLink.id } as DbTransaction
} }
} }
} }
@ -333,7 +341,7 @@ export class UserResolver {
}) })
logger.info(`sendAccountActivationEmail of ${firstName}.${lastName} to ${email}`) logger.info(`sendAccountActivationEmail of ${firstName}.${lastName} to ${email}`)
await EVENT_SEND_CONFIRMATION_EMAIL(dbUser.id) await EVENT_SEND_CONFIRMATION_EMAIL(dbUser)
if (!emailSent) { if (!emailSent) {
logger.debug(`Account confirmation link: ${activationLink}`) logger.debug(`Account confirmation link: ${activationLink}`)
@ -350,10 +358,11 @@ export class UserResolver {
logger.info('createUser() successful...') logger.info('createUser() successful...')
if (redeemCode) { if (redeemCode) {
eventRegisterRedeem.userId = dbUser.id eventRegisterRedeem.affectedUser = dbUser
eventRegisterRedeem.actingUser = dbUser
await eventRegisterRedeem.save() await eventRegisterRedeem.save()
} else { } else {
await EVENT_REGISTER(dbUser.id) await EVENT_REGISTER(dbUser)
} }
return new User(dbUser) return new User(dbUser)
@ -469,7 +478,7 @@ export class UserResolver {
await queryRunner.commitTransaction() await queryRunner.commitTransaction()
logger.info('User and UserContact data written successfully...') logger.info('User and UserContact data written successfully...')
await EVENT_ACTIVATE_ACCOUNT(user.id) await EVENT_ACTIVATE_ACCOUNT(user)
} catch (e) { } catch (e) {
await queryRunner.rollbackTransaction() await queryRunner.rollbackTransaction()
throw new LogError('Error on writing User and User Contact data', e) throw new LogError('Error on writing User and User Contact data', e)
@ -779,9 +788,13 @@ export class UserResolver {
return null return null
} }
// TODO this is an admin function - needs refactor
@Authorized([RIGHTS.SEND_ACTIVATION_EMAIL]) @Authorized([RIGHTS.SEND_ACTIVATION_EMAIL])
@Mutation(() => Boolean) @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() email = email.trim().toLowerCase()
// const user = await dbUser.findOne({ id: emailContact.userId }) // const user = await dbUser.findOne({ id: emailContact.userId })
const user = await findUserByEmail(email) const user = await findUserByEmail(email)
@ -806,7 +819,7 @@ export class UserResolver {
if (!emailSent) { if (!emailSent) {
logger.info(`Account confirmation link: ${activationLink}`) logger.info(`Account confirmation link: ${activationLink}`)
} else { } else {
await EVENT_ADMIN_SEND_CONFIRMATION_EMAIL(user.id) await EVENT_ADMIN_SEND_CONFIRMATION_EMAIL(user, getUser(context))
} }
return true return true

View File

@ -0,0 +1,83 @@
import { Contribution } from '../Contribution'
import { ContributionMessage } from '../ContributionMessage'
import { User } from '../User'
import { Transaction } from '../Transaction'
import Decimal from 'decimal.js-light'
import {
BaseEntity,
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
ManyToOne,
JoinColumn,
} from 'typeorm'
import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer'
@Entity('events')
export class Event extends BaseEntity {
@PrimaryGeneratedColumn('increment', { unsigned: true })
id: number
@Column({ length: 100, nullable: false, collation: 'utf8mb4_unicode_ci' })
type: string
@CreateDateColumn({
name: 'created_at',
type: 'datetime',
default: () => 'CURRENT_TIMESTAMP(3)',
nullable: false,
})
createdAt: Date
@Column({ name: 'affected_user_id', unsigned: true, nullable: false })
affectedUserId: number
@ManyToOne(() => User)
@JoinColumn({ name: 'affected_user_id', referencedColumnName: 'id' })
affectedUser: User
@Column({ name: 'acting_user_id', unsigned: true, nullable: false })
actingUserId: number
@ManyToOne(() => User)
@JoinColumn({ name: 'acting_user_id', referencedColumnName: 'id' })
actingUser: User
@Column({ name: 'involved_user_id', type: 'int', unsigned: true, nullable: true })
involvedUserId: number | null
@ManyToOne(() => User)
@JoinColumn({ name: 'involved_user_id', referencedColumnName: 'id' })
involvedUser: User | null
@Column({ name: 'involved_transaction_id', type: 'int', unsigned: true, nullable: true })
involvedTransactionId: number | null
@ManyToOne(() => Transaction)
@JoinColumn({ name: 'involved_transaction_id', referencedColumnName: 'id' })
involvedTransaction: Transaction | null
@Column({ name: 'involved_contribution_id', type: 'int', unsigned: true, nullable: true })
involvedContributionId: number | null
@ManyToOne(() => Contribution)
@JoinColumn({ name: 'involved_contribution_id', referencedColumnName: 'id' })
involvedContribution: Contribution | null
@Column({ name: 'involved_contribution_message_id', type: 'int', unsigned: true, nullable: true })
involvedContributionMessageId: number | null
@ManyToOne(() => ContributionMessage)
@JoinColumn({ name: 'involved_contribution_message_id', referencedColumnName: 'id' })
involvedContributionMessage: ContributionMessage | null
@Column({
type: 'decimal',
precision: 40,
scale: 20,
nullable: true,
transformer: DecimalTransformer,
})
amount: Decimal | null
}

1
database/entity/Event.ts Normal file
View File

@ -0,0 +1 @@
export { Event } from './0061-event_refactoring/Event'

View File

@ -1 +0,0 @@
export { EventProtocol } from './0050-add_messageId_to_event_protocol/EventProtocol'

View File

@ -7,21 +7,21 @@ import { TransactionLink } from './TransactionLink'
import { User } from './User' import { User } from './User'
import { UserContact } from './UserContact' import { UserContact } from './UserContact'
import { Contribution } from './Contribution' import { Contribution } from './Contribution'
import { EventProtocol } from './EventProtocol' import { Event } from './Event'
import { ContributionMessage } from './ContributionMessage' import { ContributionMessage } from './ContributionMessage'
import { Community } from './Community' import { Community } from './Community'
export const entities = [ export const entities = [
Community,
Contribution, Contribution,
ContributionLink, ContributionLink,
ContributionMessage,
Event,
LoginElopageBuys, LoginElopageBuys,
LoginEmailOptIn, LoginEmailOptIn,
Migration, Migration,
Transaction, Transaction,
TransactionLink, TransactionLink,
User, User,
EventProtocol,
ContributionMessage,
UserContact, UserContact,
Community,
] ]

View File

@ -0,0 +1,98 @@
/* MIGRATION TO REFACTOR THE EVENT_PROTOCOL TABLE
*
* This migration refactors the `event_protocol` table.
* It renames the table to `event`, introduces new fields and renames others.
*/
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable @typescript-eslint/no-explicit-any */
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
await queryFn('RENAME TABLE `event_protocol` TO `events`;')
await queryFn('ALTER TABLE `events` RENAME COLUMN `user_id` TO `affected_user_id`;')
await queryFn(
'ALTER TABLE `events` ADD COLUMN `acting_user_id` int(10) unsigned DEFAULT NULL AFTER `affected_user_id`;',
)
await queryFn('UPDATE `events` SET `acting_user_id` = `affected_user_id`;')
await queryFn(
'ALTER TABLE `events` MODIFY COLUMN `acting_user_id` int(10) unsigned NOT NULL AFTER `affected_user_id`;',
)
await queryFn('ALTER TABLE `events` RENAME COLUMN `x_user_id` TO `involved_user_id`;')
await queryFn('ALTER TABLE `events` DROP COLUMN `x_community_id`;')
await queryFn('ALTER TABLE `events` RENAME COLUMN `transaction_id` TO `involved_transaction_id`;')
await queryFn(
'ALTER TABLE `events` RENAME COLUMN `contribution_id` TO `involved_contribution_id`;',
)
await queryFn(
'ALTER TABLE `events` MODIFY COLUMN `message_id` int(10) unsigned DEFAULT NULL AFTER `involved_contribution_id`;',
)
await queryFn(
'ALTER TABLE `events` RENAME COLUMN `message_id` TO `involved_contribution_message_id`;',
)
// Moderator id was saved in former user_id
await queryFn(
'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET affected_user_id=contributions.user_id WHERE `type` = "ADMIN_CONTRIBUTION_CREATE";',
)
// inconsistent data on this type, since not all data can be reconstructed
await queryFn(
'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET acting_user_id=0 WHERE `type` = "ADMIN_CONTRIBUTION_UPDATE";',
)
await queryFn(
'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET acting_user_id=contributions.deleted_by WHERE `type` = "ADMIN_CONTRIBUTION_DELETE";',
)
await queryFn(
'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET acting_user_id=contributions.confirmed_by WHERE `type` = "CONTRIBUTION_CONFIRM";',
)
await queryFn(
'UPDATE `events` LEFT JOIN `contributions` ON events.involved_contribution_id = contributions.id SET involved_user_id=NULL, acting_user_id=contributions.denied_by WHERE `type` = "ADMIN_CONTRIBUTION_DENY";',
)
await queryFn(
'UPDATE `events` SET acting_user_id=involved_user_id WHERE `type` = "TRANSACTION_RECEIVE";',
)
await queryFn('UPDATE `events` SET amount = amount * -1 WHERE `type` = "TRANSACTION_SEND";')
await queryFn(
'ALTER TABLE `events` MODIFY COLUMN `created_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3);',
)
}
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
await queryFn(
'ALTER TABLE `events` MODIFY COLUMN `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP();',
)
await queryFn('UPDATE `events` SET amount = amount * -1 WHERE `type` = "TRANSACTION_SEND";')
await queryFn(
'UPDATE `events` SET involved_user_id=acting_user_id WHERE `type` = "ADMIN_CONTRIBUTION_DENY";',
)
await queryFn(
'UPDATE `events` SET affected_user_id=acting_user_id WHERE `type` = "ADMIN_CONTRIBUTION_CREATE";',
)
await queryFn(
'ALTER TABLE `events` RENAME COLUMN `involved_contribution_message_id` TO `message_id`;',
)
await queryFn(
'ALTER TABLE `events` MODIFY COLUMN `message_id` int(10) unsigned DEFAULT NULL AFTER `amount`;',
)
await queryFn(
'ALTER TABLE `events` RENAME COLUMN `involved_contribution_id` TO `contribution_id`;',
)
await queryFn('ALTER TABLE `events` RENAME COLUMN `involved_transaction_id` TO `transaction_id`;')
await queryFn(
'ALTER TABLE `events` ADD COLUMN `x_community_id` int(10) unsigned DEFAULT NULL AFTER `involved_user_id`;',
)
await queryFn('ALTER TABLE `events` RENAME COLUMN `involved_user_id` TO `x_user_id`;')
await queryFn('ALTER TABLE `events` DROP COLUMN `acting_user_id`;')
await queryFn('ALTER TABLE `events` RENAME COLUMN `affected_user_id` TO `user_id`;')
await queryFn('RENAME TABLE `events` TO `event_protocol`;')
}

View File

@ -3,7 +3,7 @@ import dotenv from 'dotenv'
dotenv.config() dotenv.config()
const constants = { const constants = {
DB_VERSION: '0060-update_communities_table', DB_VERSION: '0061-event_refactoring',
LOG4JS_CONFIG: 'log4js-config.json', LOG4JS_CONFIG: 'log4js-config.json',
// default log level on production should be info // default log level on production should be info
LOG_LEVEL: process.env.LOG_LEVEL || 'info', LOG_LEVEL: process.env.LOG_LEVEL || 'info',

View File

@ -11,7 +11,7 @@ Decimal.set({
*/ */
const constants = { 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 // DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0
LOG4JS_CONFIG: 'log4js-config.json', LOG4JS_CONFIG: 'log4js-config.json',
// default log level on production should be info // default log level on production should be info