mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #2780 from gradido/events-contribution-link
feat(backend): events for contribution links
This commit is contained in:
commit
22e7c64503
@ -10,7 +10,7 @@ Decimal.set({
|
||||
})
|
||||
|
||||
const constants = {
|
||||
DB_VERSION: '0062-event_contribution_confirm',
|
||||
DB_VERSION: '0063-event_link_fields',
|
||||
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
|
||||
|
||||
@ -18,5 +18,7 @@ export const EVENT_ADMIN_CONTRIBUTION_CONFIRM = async (
|
||||
null,
|
||||
contribution,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
@ -18,5 +18,7 @@ export const EVENT_ADMIN_CONTRIBUTION_CREATE = async (
|
||||
null,
|
||||
contribution,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
@ -18,5 +18,7 @@ export const EVENT_ADMIN_CONTRIBUTION_DELETE = async (
|
||||
null,
|
||||
contribution,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
@ -18,5 +18,7 @@ export const EVENT_ADMIN_CONTRIBUTION_DENY = async (
|
||||
null,
|
||||
contribution,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
23
backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_CREATE.ts
Normal file
23
backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_CREATE.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { User as DbUser } from '@entity/User'
|
||||
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
|
||||
import { Event as DbEvent } from '@entity/Event'
|
||||
import { Event, EventType } from './Event'
|
||||
|
||||
export const EVENT_ADMIN_CONTRIBUTION_LINK_CREATE = async (
|
||||
moderator: DbUser,
|
||||
contributionLink: DbContributionLink,
|
||||
amount: Decimal,
|
||||
): Promise<DbEvent> =>
|
||||
Event(
|
||||
EventType.ADMIN_CONTRIBUTION_LINK_CREATE,
|
||||
{ id: 0 } as DbUser,
|
||||
moderator,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
contributionLink,
|
||||
amount,
|
||||
).save()
|
||||
20
backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_DELETE.ts
Normal file
20
backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_DELETE.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { User as DbUser } from '@entity/User'
|
||||
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
|
||||
import { Event as DbEvent } from '@entity/Event'
|
||||
import { Event, EventType } from './Event'
|
||||
|
||||
export const EVENT_ADMIN_CONTRIBUTION_LINK_DELETE = async (
|
||||
moderator: DbUser,
|
||||
contributionLink: DbContributionLink,
|
||||
): Promise<DbEvent> =>
|
||||
Event(
|
||||
EventType.ADMIN_CONTRIBUTION_LINK_DELETE,
|
||||
{ id: 0 } as DbUser,
|
||||
moderator,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
contributionLink,
|
||||
).save()
|
||||
23
backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE.ts
Normal file
23
backend/src/event/EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { User as DbUser } from '@entity/User'
|
||||
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
|
||||
import { Event as DbEvent } from '@entity/Event'
|
||||
import { Event, EventType } from './Event'
|
||||
|
||||
export const EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE = async (
|
||||
moderator: DbUser,
|
||||
contributionLink: DbContributionLink,
|
||||
amount: Decimal,
|
||||
): Promise<DbEvent> =>
|
||||
Event(
|
||||
EventType.ADMIN_CONTRIBUTION_LINK_UPDATE,
|
||||
{ id: 0 } as DbUser,
|
||||
moderator,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
contributionLink,
|
||||
amount,
|
||||
).save()
|
||||
@ -18,5 +18,7 @@ export const EVENT_ADMIN_CONTRIBUTION_UPDATE = async (
|
||||
null,
|
||||
contribution,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
@ -9,4 +9,15 @@ export const EVENT_CONTRIBUTION_CREATE = async (
|
||||
contribution: DbContribution,
|
||||
amount: Decimal,
|
||||
): Promise<DbEvent> =>
|
||||
Event(EventType.CONTRIBUTION_CREATE, user, user, null, null, contribution, null, amount).save()
|
||||
Event(
|
||||
EventType.CONTRIBUTION_CREATE,
|
||||
user,
|
||||
user,
|
||||
null,
|
||||
null,
|
||||
contribution,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
@ -9,4 +9,15 @@ export const EVENT_CONTRIBUTION_DELETE = async (
|
||||
contribution: DbContribution,
|
||||
amount: Decimal,
|
||||
): Promise<DbEvent> =>
|
||||
Event(EventType.CONTRIBUTION_DELETE, user, user, null, null, contribution, null, amount).save()
|
||||
Event(
|
||||
EventType.CONTRIBUTION_DELETE,
|
||||
user,
|
||||
user,
|
||||
null,
|
||||
null,
|
||||
contribution,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
@ -9,4 +9,15 @@ export const EVENT_CONTRIBUTION_UPDATE = async (
|
||||
contribution: DbContribution,
|
||||
amount: Decimal,
|
||||
): Promise<DbEvent> =>
|
||||
Event(EventType.CONTRIBUTION_UPDATE, user, user, null, null, contribution, null, amount).save()
|
||||
Event(
|
||||
EventType.CONTRIBUTION_UPDATE,
|
||||
user,
|
||||
user,
|
||||
null,
|
||||
null,
|
||||
contribution,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
@ -18,5 +18,7 @@ export const EVENT_TRANSACTION_RECEIVE = async (
|
||||
transaction,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
@ -18,5 +18,7 @@ export const EVENT_TRANSACTION_SEND = async (
|
||||
transaction,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
amount,
|
||||
).save()
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
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 { TransactionLink as DbTransactionLink } from '@entity/TransactionLink'
|
||||
import { Contribution as DbContribution } from '@entity/Contribution'
|
||||
import { ContributionMessage as DbContributionMessage } from '@entity/ContributionMessage'
|
||||
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { EventType } from './Event'
|
||||
|
||||
@ -14,6 +16,8 @@ export const Event = (
|
||||
involvedTransaction: DbTransaction | null = null,
|
||||
involvedContribution: DbContribution | null = null,
|
||||
involvedContributionMessage: DbContributionMessage | null = null,
|
||||
involvedTransactionLink: DbTransactionLink | null = null,
|
||||
involvedContributionLink: DbContributionLink | null = null,
|
||||
amount: Decimal | null = null,
|
||||
): DbEvent => {
|
||||
const event = new DbEvent()
|
||||
@ -24,6 +28,8 @@ export const Event = (
|
||||
event.involvedTransaction = involvedTransaction
|
||||
event.involvedContribution = involvedContribution
|
||||
event.involvedContributionMessage = involvedContributionMessage
|
||||
event.involvedTransactionLink = involvedTransactionLink
|
||||
event.involvedContributionLink = involvedContributionLink
|
||||
event.amount = amount
|
||||
return event
|
||||
}
|
||||
@ -36,6 +42,9 @@ export { EVENT_ADMIN_CONTRIBUTION_CREATE } from './EVENT_ADMIN_CONTRIBUTION_CREA
|
||||
export { EVENT_ADMIN_CONTRIBUTION_DELETE } from './EVENT_ADMIN_CONTRIBUTION_DELETE'
|
||||
export { EVENT_ADMIN_CONTRIBUTION_DENY } from './EVENT_ADMIN_CONTRIBUTION_DENY'
|
||||
export { EVENT_ADMIN_CONTRIBUTION_UPDATE } from './EVENT_ADMIN_CONTRIBUTION_UPDATE'
|
||||
export { EVENT_ADMIN_CONTRIBUTION_LINK_CREATE } from './EVENT_ADMIN_CONTRIBUTION_LINK_CREATE'
|
||||
export { EVENT_ADMIN_CONTRIBUTION_LINK_DELETE } from './EVENT_ADMIN_CONTRIBUTION_LINK_DELETE'
|
||||
export { EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE } from './EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE'
|
||||
export { EVENT_ADMIN_SEND_CONFIRMATION_EMAIL } from './EVENT_ADMIN_SEND_CONFIRMATION_EMAIL'
|
||||
export { EVENT_CONTRIBUTION_CREATE } from './EVENT_CONTRIBUTION_CREATE'
|
||||
export { EVENT_CONTRIBUTION_DELETE } from './EVENT_CONTRIBUTION_DELETE'
|
||||
|
||||
@ -1,8 +1,3 @@
|
||||
export { EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL } from './EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL'
|
||||
export { EVENT_SEND_CONFIRMATION_EMAIL } from './EVENT_SEND_CONFIRMATION_EMAIL'
|
||||
export { EVENT_TRANSACTION_SEND } from './EVENT_TRANSACTION_SEND'
|
||||
export { EVENT_TRANSACTION_RECEIVE } from './EVENT_TRANSACTION_RECEIVE'
|
||||
|
||||
export enum EventType {
|
||||
ACTIVATE_ACCOUNT = 'ACTIVATE_ACCOUNT',
|
||||
// TODO CONTRIBUTION_CONFIRM = 'CONTRIBUTION_CONFIRM',
|
||||
@ -11,6 +6,9 @@ export enum EventType {
|
||||
ADMIN_CONTRIBUTION_DELETE = 'ADMIN_CONTRIBUTION_DELETE',
|
||||
ADMIN_CONTRIBUTION_DENY = 'ADMIN_CONTRIBUTION_DENY',
|
||||
ADMIN_CONTRIBUTION_UPDATE = 'ADMIN_CONTRIBUTION_UPDATE',
|
||||
ADMIN_CONTRIBUTION_LINK_CREATE = 'ADMIN_CONTRIBUTION_LINK_CREATE',
|
||||
ADMIN_CONTRIBUTION_LINK_DELETE = 'ADMIN_CONTRIBUTION_LINK_DELETE',
|
||||
ADMIN_CONTRIBUTION_LINK_UPDATE = 'ADMIN_CONTRIBUTION_LINK_UPDATE',
|
||||
ADMIN_SEND_CONFIRMATION_EMAIL = 'ADMIN_SEND_CONFIRMATION_EMAIL',
|
||||
CONTRIBUTION_CREATE = 'CONTRIBUTION_CREATE',
|
||||
CONTRIBUTION_DELETE = 'CONTRIBUTION_DELETE',
|
||||
@ -40,17 +38,10 @@ export enum EventType {
|
||||
// SEND_TRANSACTION_LINK_REDEEM_EMAIL = 'SEND_TRANSACTION_LINK_REDEEM_EMAIL',
|
||||
// SEND_ADDED_CONTRIBUTION_EMAIL = 'SEND_ADDED_CONTRIBUTION_EMAIL',
|
||||
// SEND_CONTRIBUTION_CONFIRM_EMAIL = 'SEND_CONTRIBUTION_CONFIRM_EMAIL',
|
||||
// CONTRIBUTION_DENY = 'CONTRIBUTION_DENY',
|
||||
// CONTRIBUTION_LINK_DEFINE = 'CONTRIBUTION_LINK_DEFINE',
|
||||
// CONTRIBUTION_LINK_ACTIVATE_REDEEM = 'CONTRIBUTION_LINK_ACTIVATE_REDEEM',
|
||||
// USER_CREATE_CONTRIBUTION_MESSAGE = 'USER_CREATE_CONTRIBUTION_MESSAGE',
|
||||
// ADMIN_CREATE_CONTRIBUTION_MESSAGE = 'ADMIN_CREATE_CONTRIBUTION_MESSAGE',
|
||||
// DELETE_USER = 'DELETE_USER',
|
||||
// UNDELETE_USER = 'UNDELETE_USER',
|
||||
// CHANGE_USER_ROLE = 'CHANGE_USER_ROLE',
|
||||
// ADMIN_UPDATE_CONTRIBUTION = 'ADMIN_UPDATE_CONTRIBUTION',
|
||||
// ADMIN_DELETE_CONTRIBUTION = 'ADMIN_DELETE_CONTRIBUTION',
|
||||
// CREATE_CONTRIBUTION_LINK = 'CREATE_CONTRIBUTION_LINK',
|
||||
// DELETE_CONTRIBUTION_LINK = 'DELETE_CONTRIBUTION_LINK',
|
||||
// UPDATE_CONTRIBUTION_LINK = 'UPDATE_CONTRIBUTION_LINK',
|
||||
}
|
||||
|
||||
@ -19,6 +19,8 @@ import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg'
|
||||
import { peterLustig } from '@/seeds/users/peter-lustig'
|
||||
import { userFactory } from '@/seeds/factory/user'
|
||||
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
|
||||
import { EventType } from '@/event/Event'
|
||||
import { Event as DbEvent } from '@entity/Event'
|
||||
|
||||
let mutate: any, query: any, con: any
|
||||
let testEnv: any
|
||||
@ -249,6 +251,18 @@ describe('Contribution Links', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('stores the ADMIN_CONTRIBUTION_LINK_CREATE event in the database', async () => {
|
||||
await expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventType.ADMIN_CONTRIBUTION_LINK_CREATE,
|
||||
affectedUserId: 0,
|
||||
actingUserId: expect.any(Number),
|
||||
involvedContributionLinkId: expect.any(Number),
|
||||
amount: expect.decimalEqual(200),
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('returns an error if missing startDate', async () => {
|
||||
jest.clearAllMocks()
|
||||
await expect(
|
||||
@ -531,6 +545,18 @@ describe('Contribution Links', () => {
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('stores the ADMIN_CONTRIBUTION_LINK_UPDATE event in the database', async () => {
|
||||
await expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventType.ADMIN_CONTRIBUTION_LINK_UPDATE,
|
||||
affectedUserId: 0,
|
||||
actingUserId: expect.any(Number),
|
||||
involvedContributionLinkId: expect.any(Number),
|
||||
amount: expect.decimalEqual(400),
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -558,18 +584,29 @@ describe('Contribution Links', () => {
|
||||
linkId = links.data.listContributionLinks.links[0].id
|
||||
})
|
||||
|
||||
it('returns a date string', async () => {
|
||||
it('returns true', async () => {
|
||||
await expect(
|
||||
mutate({ mutation: deleteContributionLink, variables: { id: linkId } }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
data: {
|
||||
deleteContributionLink: expect.any(String),
|
||||
deleteContributionLink: true,
|
||||
},
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('stores the ADMIN_CONTRIBUTION_LINK_DELETE event in the database', async () => {
|
||||
await expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventType.ADMIN_CONTRIBUTION_LINK_DELETE,
|
||||
affectedUserId: 0,
|
||||
actingUserId: expect.any(Number),
|
||||
involvedContributionLinkId: linkId,
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('does not list this contribution link anymore', async () => {
|
||||
await expect(query({ query: listContributionLinks })).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { Resolver, Args, Arg, Authorized, Mutation, Query, Int } from 'type-graphql'
|
||||
import { Resolver, Args, Arg, Authorized, Mutation, Query, Int, Ctx } from 'type-graphql'
|
||||
import { MoreThan, IsNull } from '@dbTools/typeorm'
|
||||
|
||||
import {
|
||||
@ -12,7 +12,6 @@ import { isStartEndDateValid } from './util/creations'
|
||||
import { ContributionLinkList } from '@model/ContributionLinkList'
|
||||
import { ContributionLink } from '@model/ContributionLink'
|
||||
import ContributionLinkArgs from '@arg/ContributionLinkArgs'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
import { RIGHTS } from '@/auth/RIGHTS'
|
||||
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
|
||||
import { Order } from '@enum/Order'
|
||||
@ -21,6 +20,12 @@ import Paginated from '@arg/Paginated'
|
||||
// TODO: this is a strange construct
|
||||
import { transactionLinkCode as contributionLinkCode } from './TransactionLinkResolver'
|
||||
import LogError from '@/server/LogError'
|
||||
import { Context, getUser } from '@/server/context'
|
||||
import {
|
||||
EVENT_ADMIN_CONTRIBUTION_LINK_CREATE,
|
||||
EVENT_ADMIN_CONTRIBUTION_LINK_DELETE,
|
||||
EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE,
|
||||
} from '@/event/Event'
|
||||
|
||||
@Resolver()
|
||||
export class ContributionLinkResolver {
|
||||
@ -38,6 +43,7 @@ export class ContributionLinkResolver {
|
||||
maxAmountPerMonth = null,
|
||||
maxPerCycle,
|
||||
}: ContributionLinkArgs,
|
||||
@Ctx() context: Context,
|
||||
): Promise<ContributionLink> {
|
||||
isStartEndDateValid(validFrom, validTo)
|
||||
if (name.length < CONTRIBUTIONLINK_NAME_MIN_CHARS) {
|
||||
@ -68,7 +74,8 @@ export class ContributionLinkResolver {
|
||||
dbContributionLink.maxAmountPerMonth = maxAmountPerMonth
|
||||
dbContributionLink.maxPerCycle = maxPerCycle
|
||||
await dbContributionLink.save()
|
||||
logger.debug(`createContributionLink successful!`)
|
||||
await EVENT_ADMIN_CONTRIBUTION_LINK_CREATE(getUser(context), dbContributionLink, amount)
|
||||
|
||||
return new ContributionLink(dbContributionLink)
|
||||
}
|
||||
|
||||
@ -91,16 +98,19 @@ export class ContributionLinkResolver {
|
||||
}
|
||||
|
||||
@Authorized([RIGHTS.DELETE_CONTRIBUTION_LINK])
|
||||
@Mutation(() => Date, { nullable: true })
|
||||
async deleteContributionLink(@Arg('id', () => Int) id: number): Promise<Date | null> {
|
||||
const contributionLink = await DbContributionLink.findOne(id)
|
||||
if (!contributionLink) {
|
||||
@Mutation(() => Boolean)
|
||||
async deleteContributionLink(
|
||||
@Arg('id', () => Int) id: number,
|
||||
@Ctx() context: Context,
|
||||
): Promise<boolean> {
|
||||
const dbContributionLink = await DbContributionLink.findOne(id)
|
||||
if (!dbContributionLink) {
|
||||
throw new LogError('Contribution Link not found', id)
|
||||
}
|
||||
await contributionLink.softRemove()
|
||||
logger.debug(`deleteContributionLink successful!`)
|
||||
const newContributionLink = await DbContributionLink.findOne({ id }, { withDeleted: true })
|
||||
return newContributionLink ? newContributionLink.deletedAt : null
|
||||
await dbContributionLink.softRemove()
|
||||
await EVENT_ADMIN_CONTRIBUTION_LINK_DELETE(getUser(context), dbContributionLink)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@Authorized([RIGHTS.UPDATE_CONTRIBUTION_LINK])
|
||||
@ -118,6 +128,7 @@ export class ContributionLinkResolver {
|
||||
maxPerCycle,
|
||||
}: ContributionLinkArgs,
|
||||
@Arg('id', () => Int) id: number,
|
||||
@Ctx() context: Context,
|
||||
): Promise<ContributionLink> {
|
||||
const dbContributionLink = await DbContributionLink.findOne(id)
|
||||
if (!dbContributionLink) {
|
||||
@ -132,7 +143,8 @@ export class ContributionLinkResolver {
|
||||
dbContributionLink.maxAmountPerMonth = maxAmountPerMonth
|
||||
dbContributionLink.maxPerCycle = maxPerCycle
|
||||
await dbContributionLink.save()
|
||||
logger.debug(`updateContributionLink successful!`)
|
||||
await EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE(getUser(context), dbContributionLink, amount)
|
||||
|
||||
return new ContributionLink(dbContributionLink)
|
||||
}
|
||||
}
|
||||
|
||||
@ -379,7 +379,7 @@ describe('UserResolver', () => {
|
||||
type: EventType.REDEEM_REGISTER,
|
||||
affectedUserId: result.data.createUser.id,
|
||||
actingUserId: result.data.createUser.id,
|
||||
involvedContributionId: link.id,
|
||||
involvedContributionLinkId: link.id,
|
||||
}),
|
||||
)
|
||||
})
|
||||
@ -464,7 +464,7 @@ describe('UserResolver', () => {
|
||||
type: EventType.REDEEM_REGISTER,
|
||||
affectedUserId: newUser.data.createUser.id,
|
||||
actingUserId: newUser.data.createUser.id,
|
||||
involvedTransactionId: transactionLink.id,
|
||||
involvedTransactionLinkId: transactionLink.id,
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
@ -20,9 +20,7 @@ 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'
|
||||
@ -293,16 +291,14 @@ export class UserResolver {
|
||||
logger.info('redeemCode found contributionLink', contributionLink)
|
||||
if (contributionLink) {
|
||||
dbUser.contributionLinkId = contributionLink.id
|
||||
// TODO this is so wrong
|
||||
eventRegisterRedeem.involvedContribution = { id: contributionLink.id } as DbContribution
|
||||
eventRegisterRedeem.involvedContributionLink = contributionLink
|
||||
}
|
||||
} else {
|
||||
const transactionLink = await DbTransactionLink.findOne({ code: redeemCode })
|
||||
logger.info('redeemCode found transactionLink', transactionLink)
|
||||
if (transactionLink) {
|
||||
dbUser.referrerId = transactionLink.userId
|
||||
// TODO this is so wrong
|
||||
eventRegisterRedeem.involvedTransaction = { id: transactionLink.id } as DbTransaction
|
||||
eventRegisterRedeem.involvedTransactionLink = transactionLink
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
99
database/entity/0063-event_link_fields/Event.ts
Normal file
99
database/entity/0063-event_link_fields/Event.ts
Normal file
@ -0,0 +1,99 @@
|
||||
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'
|
||||
import { TransactionLink } from '../TransactionLink'
|
||||
import { ContributionLink } from '../ContributionLink'
|
||||
|
||||
@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({ name: 'involved_transaction_link_id', type: 'int', unsigned: true, nullable: true })
|
||||
involvedTransactionLinkId: number | null
|
||||
|
||||
@ManyToOne(() => TransactionLink)
|
||||
@JoinColumn({ name: 'involved_transaction_link_id', referencedColumnName: 'id' })
|
||||
involvedTransactionLink: TransactionLink | null
|
||||
|
||||
@Column({ name: 'involved_contribution_link_id', type: 'int', unsigned: true, nullable: true })
|
||||
involvedContributionLinkId: number | null
|
||||
|
||||
@ManyToOne(() => ContributionLink)
|
||||
@JoinColumn({ name: 'involved_contribution_link_id', referencedColumnName: 'id' })
|
||||
involvedContributionLink: ContributionLink | null
|
||||
|
||||
@Column({
|
||||
type: 'decimal',
|
||||
precision: 40,
|
||||
scale: 20,
|
||||
nullable: true,
|
||||
transformer: DecimalTransformer,
|
||||
})
|
||||
amount: Decimal | null
|
||||
}
|
||||
@ -1 +1 @@
|
||||
export { Event } from './0061-event_refactoring/Event'
|
||||
export { Event } from './0063-event_link_fields/Event'
|
||||
|
||||
29
database/migrations/0063-event_link_fields.ts
Normal file
29
database/migrations/0063-event_link_fields.ts
Normal file
@ -0,0 +1,29 @@
|
||||
/* MIGRATION TO ADD LINK ID FIELDS TO EVENT TABLE
|
||||
*
|
||||
* This migration add two fields to store a TransactionLinkId and a ContributionLinkId
|
||||
* in the event table. Furthermore the event `REDEEM_REGISTER` is rewritten to use the
|
||||
* new fields.
|
||||
*/
|
||||
|
||||
/* 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(
|
||||
'ALTER TABLE `events` ADD COLUMN `involved_transaction_link_id` int(10) unsigned DEFAULT NULL AFTER `involved_contribution_message_id`;',
|
||||
)
|
||||
await queryFn(
|
||||
'ALTER TABLE `events` ADD COLUMN `involved_contribution_link_id` int(10) unsigned DEFAULT NULL AFTER `involved_transaction_link_id`;',
|
||||
)
|
||||
await queryFn(
|
||||
'UPDATE `events` SET `involved_transaction_link_id` = `involved_transaction_id`, `involved_transaction_id` = NULL, `involved_contribution_link_id` = `involved_contribution_id`, `involved_contribution_id` = NULL WHERE `type` = "REDEEM_REGISTER";',
|
||||
)
|
||||
}
|
||||
|
||||
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
await queryFn(
|
||||
'UPDATE `events` SET `involved_transaction_id` = `involved_transaction_link_id`, `involved_contribution_id` = `involved_contribution_link_id` WHERE `type` = "REDEEM_REGISTER";',
|
||||
)
|
||||
await queryFn('ALTER TABLE `events` DROP COLUMN `involved_contribution_link_id`;')
|
||||
await queryFn('ALTER TABLE `events` DROP COLUMN `involved_transaction_link_id`;')
|
||||
}
|
||||
@ -3,7 +3,7 @@ import dotenv from 'dotenv'
|
||||
dotenv.config()
|
||||
|
||||
const constants = {
|
||||
DB_VERSION: '0062-event_contribution_confirm',
|
||||
DB_VERSION: '0063-event_link_fields',
|
||||
LOG4JS_CONFIG: 'log4js-config.json',
|
||||
// default log level on production should be info
|
||||
LOG_LEVEL: process.env.LOG_LEVEL || 'info',
|
||||
|
||||
@ -11,7 +11,7 @@ Decimal.set({
|
||||
*/
|
||||
|
||||
const constants = {
|
||||
DB_VERSION: '0062-event_contribution_confirm',
|
||||
DB_VERSION: '0063-event_link_fields',
|
||||
// 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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user