transform event data

This commit is contained in:
Ulf Gebhardt 2023-03-04 00:30:56 +01:00
parent 76cbcc2393
commit 08c379b46f
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
2 changed files with 32 additions and 14 deletions

View File

@ -76,8 +76,6 @@ export const EVENT_CONTRIBUTION_UPDATE = async (
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 (
user: DbUser,
moderator: DbUser,
@ -95,7 +93,6 @@ export const EVENT_ADMIN_CONTRIBUTION_CREATE = async (
amount,
).save()
// TODO await EVENT_ADMIN_CONTRIBUTION_UPDATE(emailContact.user.id, contributionToUpdate.id, amount)
export const EVENT_ADMIN_CONTRIBUTION_UPDATE = async (
user: DbUser,
moderator: DbUser,
@ -113,7 +110,6 @@ export const EVENT_ADMIN_CONTRIBUTION_UPDATE = async (
amount,
).save()
// TODO await EVENT_ADMIN_CONTRIBUTION_DELETE(contribution.userId, contribution.id, contribution.amount)
export const EVENT_ADMIN_CONTRIBUTION_DELETE = async (
user: DbUser,
moderator: DbUser,
@ -131,7 +127,6 @@ export const EVENT_ADMIN_CONTRIBUTION_DELETE = async (
amount,
).save()
// TODO await EVENT_CONTRIBUTION_CONFIRM(user.id, contribution.id, contribution.amount)
export const EVENT_CONTRIBUTION_CONFIRM = async (
user: DbUser,
moderator: DbUser,
@ -149,13 +144,6 @@ export const EVENT_CONTRIBUTION_CONFIRM = async (
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 (
user: DbUser,
moderator: DbUser,
@ -190,7 +178,6 @@ export const EVENT_TRANSACTION_SEND = async (
amount,
).save()
// TODO acting user = involved user
export const EVENT_TRANSACTION_RECEIVE = async (
user: DbUser,
involvedUser: DbUser,

View File

@ -32,10 +32,41 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
'ALTER TABLE `events` RENAME COLUMN `message_id` TO `involved_contribution_message_id`;',
)
// TODO insert data based on event type
// TODO this is untested
// TODO transform back?
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
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";',
)
}
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
await queryFn(
'UPDATE `events` involved_user_id=acting_user_id WHERE type = "ADMIN_CONTRIBUTION_DENY";',
)
await queryFn(
'UPDATE `events` 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`;',
)