mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
events for contributionMessageResolver
This commit is contained in:
parent
cdb7fe32c8
commit
933e9168bc
23
backend/src/event/EVENT_ADMIN_CONTRIBUTION_MESSAGE_CREATE.ts
Normal file
23
backend/src/event/EVENT_ADMIN_CONTRIBUTION_MESSAGE_CREATE.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { User as DbUser } from '@entity/User'
|
||||||
|
import { Contribution as DbContribution } from '@entity/Contribution'
|
||||||
|
import { ContributionMessage as DbContributionMessage } from '@entity/ContributionMessage'
|
||||||
|
import { Event as DbEvent } from '@entity/Event'
|
||||||
|
import { Event, EventType } from './Event'
|
||||||
|
|
||||||
|
export const EVENT_ADMIN_CONTRIBUTION_MESSAGE_CREATE = async (
|
||||||
|
user: DbUser,
|
||||||
|
moderator: DbUser,
|
||||||
|
contribution: DbContribution,
|
||||||
|
contributionMessage: DbContributionMessage,
|
||||||
|
): Promise<DbEvent> =>
|
||||||
|
Event(
|
||||||
|
EventType.ADMIN_CONTRIBUTION_MESSAGE_CREATE,
|
||||||
|
user,
|
||||||
|
moderator,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
contribution,
|
||||||
|
contributionMessage,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
).save()
|
||||||
22
backend/src/event/EVENT_CONTRIBUTION_MESSAGE_CREATE.ts
Normal file
22
backend/src/event/EVENT_CONTRIBUTION_MESSAGE_CREATE.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { User as DbUser } from '@entity/User'
|
||||||
|
import { Contribution as DbContribution } from '@entity/Contribution'
|
||||||
|
import { ContributionMessage as DbContributionMessage } from '@entity/ContributionMessage'
|
||||||
|
import { Event as DbEvent } from '@entity/Event'
|
||||||
|
import { Event, EventType } from './Event'
|
||||||
|
|
||||||
|
export const EVENT_CONTRIBUTION_MESSAGE_CREATE = async (
|
||||||
|
user: DbUser,
|
||||||
|
contribution: DbContribution,
|
||||||
|
contributionMessage: DbContributionMessage,
|
||||||
|
): Promise<DbEvent> =>
|
||||||
|
Event(
|
||||||
|
EventType.CONTRIBUTION_MESSAGE_CREATE,
|
||||||
|
user,
|
||||||
|
user,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
contribution,
|
||||||
|
contributionMessage,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
).save()
|
||||||
@ -45,10 +45,12 @@ export { EVENT_ADMIN_CONTRIBUTION_UPDATE } from './EVENT_ADMIN_CONTRIBUTION_UPDA
|
|||||||
export { EVENT_ADMIN_CONTRIBUTION_LINK_CREATE } from './EVENT_ADMIN_CONTRIBUTION_LINK_CREATE'
|
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_DELETE } from './EVENT_ADMIN_CONTRIBUTION_LINK_DELETE'
|
||||||
export { EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE } from './EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE'
|
export { EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE } from './EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE'
|
||||||
|
export { EVENT_ADMIN_CONTRIBUTION_MESSAGE_CREATE } from './EVENT_ADMIN_CONTRIBUTION_MESSAGE_CREATE'
|
||||||
export { EVENT_ADMIN_SEND_CONFIRMATION_EMAIL } from './EVENT_ADMIN_SEND_CONFIRMATION_EMAIL'
|
export { EVENT_ADMIN_SEND_CONFIRMATION_EMAIL } from './EVENT_ADMIN_SEND_CONFIRMATION_EMAIL'
|
||||||
export { EVENT_CONTRIBUTION_CREATE } from './EVENT_CONTRIBUTION_CREATE'
|
export { EVENT_CONTRIBUTION_CREATE } from './EVENT_CONTRIBUTION_CREATE'
|
||||||
export { EVENT_CONTRIBUTION_DELETE } from './EVENT_CONTRIBUTION_DELETE'
|
export { EVENT_CONTRIBUTION_DELETE } from './EVENT_CONTRIBUTION_DELETE'
|
||||||
export { EVENT_CONTRIBUTION_UPDATE } from './EVENT_CONTRIBUTION_UPDATE'
|
export { EVENT_CONTRIBUTION_UPDATE } from './EVENT_CONTRIBUTION_UPDATE'
|
||||||
|
export { EVENT_CONTRIBUTION_MESSAGE_CREATE } from './EVENT_CONTRIBUTION_MESSAGE_CREATE'
|
||||||
export { EVENT_LOGIN } from './EVENT_LOGIN'
|
export { EVENT_LOGIN } from './EVENT_LOGIN'
|
||||||
export { EVENT_REGISTER } from './EVENT_REGISTER'
|
export { EVENT_REGISTER } from './EVENT_REGISTER'
|
||||||
export { EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL } from './EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL'
|
export { EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL } from './EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL'
|
||||||
|
|||||||
@ -9,10 +9,12 @@ export enum EventType {
|
|||||||
ADMIN_CONTRIBUTION_LINK_CREATE = 'ADMIN_CONTRIBUTION_LINK_CREATE',
|
ADMIN_CONTRIBUTION_LINK_CREATE = 'ADMIN_CONTRIBUTION_LINK_CREATE',
|
||||||
ADMIN_CONTRIBUTION_LINK_DELETE = 'ADMIN_CONTRIBUTION_LINK_DELETE',
|
ADMIN_CONTRIBUTION_LINK_DELETE = 'ADMIN_CONTRIBUTION_LINK_DELETE',
|
||||||
ADMIN_CONTRIBUTION_LINK_UPDATE = 'ADMIN_CONTRIBUTION_LINK_UPDATE',
|
ADMIN_CONTRIBUTION_LINK_UPDATE = 'ADMIN_CONTRIBUTION_LINK_UPDATE',
|
||||||
|
ADMIN_CONTRIBUTION_MESSAGE_CREATE = 'ADMIN_CONTRIBUTION_MESSAGE_CREATE',
|
||||||
ADMIN_SEND_CONFIRMATION_EMAIL = 'ADMIN_SEND_CONFIRMATION_EMAIL',
|
ADMIN_SEND_CONFIRMATION_EMAIL = 'ADMIN_SEND_CONFIRMATION_EMAIL',
|
||||||
CONTRIBUTION_CREATE = 'CONTRIBUTION_CREATE',
|
CONTRIBUTION_CREATE = 'CONTRIBUTION_CREATE',
|
||||||
CONTRIBUTION_DELETE = 'CONTRIBUTION_DELETE',
|
CONTRIBUTION_DELETE = 'CONTRIBUTION_DELETE',
|
||||||
CONTRIBUTION_UPDATE = 'CONTRIBUTION_UPDATE',
|
CONTRIBUTION_UPDATE = 'CONTRIBUTION_UPDATE',
|
||||||
|
CONTRIBUTION_MESSAGE_CREATE = 'CONTRIBUTION_MESSAGE_CREATE',
|
||||||
LOGIN = 'LOGIN',
|
LOGIN = 'LOGIN',
|
||||||
REGISTER = 'REGISTER',
|
REGISTER = 'REGISTER',
|
||||||
REDEEM_REGISTER = 'REDEEM_REGISTER',
|
REDEEM_REGISTER = 'REDEEM_REGISTER',
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import { RIGHTS } from '@/auth/RIGHTS'
|
|||||||
import { Context, getUser } from '@/server/context'
|
import { Context, getUser } from '@/server/context'
|
||||||
import { sendAddedContributionMessageEmail } from '@/emails/sendEmailVariants'
|
import { sendAddedContributionMessageEmail } from '@/emails/sendEmailVariants'
|
||||||
import LogError from '@/server/LogError'
|
import LogError from '@/server/LogError'
|
||||||
|
import { EVENT_CONTRIBUTION_MESSAGE_CREATE } from '@/event/Event'
|
||||||
|
|
||||||
@Resolver()
|
@Resolver()
|
||||||
export class ContributionMessageResolver {
|
export class ContributionMessageResolver {
|
||||||
@ -56,6 +57,11 @@ export class ContributionMessageResolver {
|
|||||||
await queryRunner.manager.update(DbContribution, { id: contributionId }, contribution)
|
await queryRunner.manager.update(DbContribution, { id: contributionId }, contribution)
|
||||||
}
|
}
|
||||||
await queryRunner.commitTransaction()
|
await queryRunner.commitTransaction()
|
||||||
|
await EVENT_CONTRIBUTION_MESSAGE_CREATE(
|
||||||
|
user,
|
||||||
|
{ id: contributionMessage.contributionId } as DbContribution,
|
||||||
|
contributionMessage,
|
||||||
|
)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await queryRunner.rollbackTransaction()
|
await queryRunner.rollbackTransaction()
|
||||||
throw new LogError(`ContributionMessage was not sent successfully: ${e}`, e)
|
throw new LogError(`ContributionMessage was not sent successfully: ${e}`, e)
|
||||||
@ -97,7 +103,7 @@ export class ContributionMessageResolver {
|
|||||||
@Args() { contributionId, message }: ContributionMessageArgs,
|
@Args() { contributionId, message }: ContributionMessageArgs,
|
||||||
@Ctx() context: Context,
|
@Ctx() context: Context,
|
||||||
): Promise<ContributionMessage> {
|
): Promise<ContributionMessage> {
|
||||||
const user = getUser(context)
|
const moderator = getUser(context)
|
||||||
|
|
||||||
const queryRunner = getConnection().createQueryRunner()
|
const queryRunner = getConnection().createQueryRunner()
|
||||||
await queryRunner.connect()
|
await queryRunner.connect()
|
||||||
@ -111,7 +117,7 @@ export class ContributionMessageResolver {
|
|||||||
if (!contribution) {
|
if (!contribution) {
|
||||||
throw new LogError('Contribution not found', contributionId)
|
throw new LogError('Contribution not found', contributionId)
|
||||||
}
|
}
|
||||||
if (contribution.userId === user.id) {
|
if (contribution.userId === moderator.id) {
|
||||||
throw new LogError('Admin can not answer on his own contribution', contributionId)
|
throw new LogError('Admin can not answer on his own contribution', contributionId)
|
||||||
}
|
}
|
||||||
if (!contribution.user.emailContact) {
|
if (!contribution.user.emailContact) {
|
||||||
@ -122,7 +128,7 @@ export class ContributionMessageResolver {
|
|||||||
contributionMessage.contributionId = contributionId
|
contributionMessage.contributionId = contributionId
|
||||||
contributionMessage.createdAt = new Date()
|
contributionMessage.createdAt = new Date()
|
||||||
contributionMessage.message = message
|
contributionMessage.message = message
|
||||||
contributionMessage.userId = user.id
|
contributionMessage.userId = moderator.id
|
||||||
contributionMessage.type = ContributionMessageType.DIALOG
|
contributionMessage.type = ContributionMessageType.DIALOG
|
||||||
contributionMessage.isModerator = true
|
contributionMessage.isModerator = true
|
||||||
await queryRunner.manager.insert(DbContributionMessage, contributionMessage)
|
await queryRunner.manager.insert(DbContributionMessage, contributionMessage)
|
||||||
@ -141,11 +147,12 @@ export class ContributionMessageResolver {
|
|||||||
lastName: contribution.user.lastName,
|
lastName: contribution.user.lastName,
|
||||||
email: contribution.user.emailContact.email,
|
email: contribution.user.emailContact.email,
|
||||||
language: contribution.user.language,
|
language: contribution.user.language,
|
||||||
senderFirstName: user.firstName,
|
senderFirstName: moderator.firstName,
|
||||||
senderLastName: user.lastName,
|
senderLastName: moderator.lastName,
|
||||||
contributionMemo: contribution.memo,
|
contributionMemo: contribution.memo,
|
||||||
})
|
})
|
||||||
await queryRunner.commitTransaction()
|
await queryRunner.commitTransaction()
|
||||||
|
await EVENT_ADMIN_CONTRIBUTION_MESSAGE_CREATE({id: contribution.userId} as DbUser, moderator, contribution, contributionMessage)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await queryRunner.rollbackTransaction()
|
await queryRunner.rollbackTransaction()
|
||||||
throw new LogError(`ContributionMessage was not sent successfully: ${e}`, e)
|
throw new LogError(`ContributionMessage was not sent successfully: ${e}`, e)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user