create event protocol tables, entities and enums

This commit is contained in:
Claus-Peter Hübner 2022-06-21 04:30:31 +02:00
parent f33cd9ed89
commit 0dd17da89b
8 changed files with 192 additions and 1 deletions

View File

@ -0,0 +1,31 @@
import { registerEnumType } from 'type-graphql'
export enum EventProtocolType {
BASIC = '0',
VISIT_GRADIDO = '10',
REGISTER = '20',
REDEEM_REGISTER = '21',
INACTIVE_ACCOUNT = '22',
SEND_CONFIRMATION_EMAIL = '23',
CONFIRM_EMAIL = '24',
REGISTER_EMAIL_KLICKTIPP = '25',
LOGIN = '30',
REDEEM_LOGIN = '31',
ACTIVATE_ACCOUNT = '32',
PASSWORD_CHANGE = '33',
TRANSACTION_SEND = '40',
TRANSACTION_SEND_REDEEM = '41',
TRANSACTION_REPEATE_REDEEM = '42',
TRANSACTION_CREATION = '50',
TRANSACTION_RECEIVE = '51',
TRANSACTION_RECEIVE_REDEEM = '52',
CONTRIBUTION_CREATE = '60',
CONTRIBUTION_CONFIRM = '61',
CONTRIBUTION_LINK_DEFINE = '70',
CONTRIBUTION_LINK_ACTIVATE_REDEEM = '71',
}
registerEnumType(EventProtocolType, {
name: 'EventProtocolType', // this one is mandatory
description: 'Name of the Type of the EventProtocol', // this one is optional
})

View File

@ -0,0 +1,13 @@
import { BaseEntity, Entity, Column, PrimaryColumn } from 'typeorm'
@Entity('enum_event_type')
export class EnumEventType extends BaseEntity {
@PrimaryColumn({ name: 'key', length: 100, nullable: false, collation: 'utf8mb4_unicode_ci' })
key: string
@Column({ name: 'value', unsigned: true, nullable: false })
value: number
@Column({ length: 200, nullable: false, collation: 'utf8mb4_unicode_ci' })
description: string
}

View File

@ -0,0 +1,39 @@
import Decimal from 'decimal.js-light'
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, DeleteDateColumn } from 'typeorm'
import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer'
@Entity('event_protocol')
export class EventProtocol extends BaseEntity {
@PrimaryGeneratedColumn('increment', { unsigned: true })
id: number
@Column({ length: 100, nullable: false, collation: 'utf8mb4_unicode_ci' })
type: string
@Column({ name: 'created_at', type: 'datetime', default: () => 'CURRENT_TIMESTAMP' })
createdAt: Date
@Column({ name: 'user_id', unsigned: true, nullable: false })
userId: number
@Column({ name: 'x_user_id', unsigned: true, nullable: true })
xUserId: number
@Column({ name: 'x_community_id', unsigned: true, nullable: true })
xCommunityId: number
@Column({ name: 'transaction_id', unsigned: true, nullable: true })
transactionId: number
@Column({ name: 'contribution_id', unsigned: true, nullable: true })
contributionId: number
@Column({
type: 'decimal',
precision: 40,
scale: 20,
nullable: true,
transformer: DecimalTransformer,
})
amount: Decimal
}

View File

@ -0,0 +1 @@
export { EnumEventType } from './0041-add_event_protocol_table/EnumEventType'

View File

@ -0,0 +1 @@
export { EventProtocol } from './0041-add_event_protocol_table/EventProtocol'

View File

@ -6,6 +6,8 @@ import { Transaction } from './Transaction'
import { TransactionLink } from './TransactionLink'
import { User } from './User'
import { Contribution } from './Contribution'
import { EventProtocol } from './EventProtocol'
import { EnumEventType } from './EnumEventType'
export const entities = [
Contribution,
@ -16,4 +18,6 @@ export const entities = [
Transaction,
TransactionLink,
User,
EventProtocol,
EnumEventType,
]

View File

@ -0,0 +1,102 @@
/* MIGRATION TO ADD EVENT_PROTOCOL
*
* This migration adds the table `event_protocol` in order to store all sorts of business event data
*/
/* 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(`
CREATE TABLE IF NOT EXISTS \`event_protocol\` (
\`id\` int(10) unsigned NOT NULL AUTO_INCREMENT,
\`type\` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
\`created_at\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
\`user_id\` int(10) unsigned NOT NULL,
\`x_user_id\` int(10) unsigned NULL DEFAULT NULL,
\`x_community_id\` int(10) unsigned NULL DEFAULT NULL,
\`transaction_id\` int(10) unsigned NULL DEFAULT NULL,
\`contribution_id\` int(10) unsigned NULL DEFAULT NULL,
\`amount\` bigint(20) NULL DEFAULT NULL,
PRIMARY KEY (\`id\`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`)
await queryFn(`
CREATE TABLE IF NOT EXISTS \`enum_event_type\` (
\`key\` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
\`value\` int(10) unsigned NOT NULL,
\`description\` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (\`key\`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('BASIC', 0, 'BasicEvent: the basic event is the root of all further extending event types');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('VISIT_GRADIDO', 10, 'VisitGradidoEvent: if a user visits a gradido page without login or register');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('REGISTER', 20, 'RegisterEvent: the user presses the register button');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('REDEEM_REGISTER', 21, 'RedeemRegisterEvent: the user presses the register button initiated by the redeem link');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('INACTIVE_ACCOUNT', 22, 'InActiveAccountEvent: the systems create an inactive account during the register process');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('SEND_CONFIRMATION_EMAIL', 23, 'SendConfirmEmailEvent: the system send a confirmation email to the user during the register process');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('CONFIRM_EMAIL', 24, 'ConfirmEmailEvent: the user confirms his email during the register process');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('REGISTER_EMAIL_KLICKTIPP', 25, 'RegisterEmailKlickTippEvent: the system registers the confirmed email at klicktipp');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('LOGIN', 30, 'LoginEvent: the user presses the login button');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('REDEEM_LOGIN', 31, 'RedeemLoginEvent: the user presses the login button initiated by the redeem link');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('ACTIVATE_ACCOUNT', 32, 'ActivateAccountEvent: the system activates the users account during the first login process');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('PASSWORD_CHANGE', 33, 'PasswordChangeEvent: the user changes his password');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('TRANSACTION_SEND', 40, 'TransactionSendEvent: the user creates a transaction and sends it online');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('TRANSACTION_SEND_REDEEM', 41, 'TransactionSendRedeemEvent: the user creates a transaction and sends it per redeem link');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('TRANSACTION_REPEATE_REDEEM', 42, 'TransactionRepeateRedeemEvent: the user recreates a redeem link of a still open transaction');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('TRANSACTION_CREATION', 50, 'TransactionCreationEvent: the user receives a creation transaction for his confirmed contribution');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('TRANSACTION_RECEIVE', 51, 'TransactionReceiveEvent: the user receives a transaction from an other user and posts the amount on his account');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('TRANSACTION_RECEIVE_REDEEM', 52, 'TransactionReceiveRedeemEvent: the user activates the redeem link and receives the transaction and posts the amount on his account');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('CONTRIBUTION_CREATE', 60, 'ContributionCreateEvent: the user enters his contribution and asks for confirmation');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('CONTRIBUTION_CONFIRM', 61, 'ContributionConfirmEvent: the user confirms a contribution of an other user (for future multi confirmation from several users)');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('CONTRIBUTION_LINK_DEFINE', 70, 'ContributionLinkDefineEvent: the admin user defines a contributionLink, which could be send per Link/QR-Code on an other medium');`,
)
await queryFn(
`INSERT INTO \`enum_event_type\` (\`key\`, \`value\`, \`description\`) VALUES ('CONTRIBUTION_LINK_ACTIVATE_REDEEM', 71, 'ContributionLinkActivateRedeemEvent: the user activates a received contributionLink to create a contribution entry for the contributionLink');`,
)
}
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
// write downgrade logic as parameter of queryFn
await queryFn(`DROP TABLE IF EXISTS \`event_protocol\`;`)
await queryFn(`DROP TABLE IF EXISTS \`enum_event_type\`;`)
}

View File

@ -6,7 +6,7 @@ dotenv.config()
const constants = {
CONFIG_VERSION: {
DEFAULT: 'DEFAULT',
EXPECTED: 'v1.2022-03-18',
EXPECTED: 'v7.2022-06-15',
CURRENT: '',
},
}