correct email parameter handling

This commit is contained in:
clauspeterhuebner 2026-02-11 22:17:45 +01:00
parent b8c7515ec7
commit d529176741

View File

@ -3,6 +3,7 @@ import { sendTransactionReceivedEmail } from '../../emails/sendEmailVariants';
import { findForeignUserByUuids, findUserByIdentifier } from 'database'; import { findForeignUserByUuids, findUserByIdentifier } from 'database';
import { LOG4JS_BASE_CATEGORY_NAME } from '../../config/const'; import { LOG4JS_BASE_CATEGORY_NAME } from '../../config/const';
import { getLogger } from 'log4js'; import { getLogger } from 'log4js';
import Decimal from 'decimal.js-light';
const createLogger = (method: string) => const createLogger = (method: string) =>
getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.command.commands.SendEmailCommand.${method}`) getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.command.commands.SendEmailCommand.${method}`)
@ -14,16 +15,18 @@ export interface SendEmailCommandParams {
receiverComUuid: string; receiverComUuid: string;
receiverGradidoId: string; receiverGradidoId: string;
memo?: string; memo?: string;
amount?: number; amount?: string;
} }
export class SendEmailCommand extends BaseCommand<{ success: boolean }> { export class SendEmailCommand extends BaseCommand<{ success: boolean }> {
static readonly SEND_MAIL_COMMAND = 'SEND_MAIL_COMMAND'; static readonly SEND_MAIL_COMMAND = 'SEND_MAIL_COMMAND';
protected requiredFields: string[] = ['mailType', 'senderComUuid', 'senderGradidoId', 'receiverComUuid', 'receiverGradidoId']; protected requiredFields: string[] = ['mailType', 'senderComUuid', 'senderGradidoId', 'receiverComUuid', 'receiverGradidoId'];
protected sendEmailCommandParams: SendEmailCommandParams;
constructor(params: SendEmailCommandParams) { constructor(params: SendEmailCommandParams) {
const methodLogger = createLogger(`constructor`) const methodLogger = createLogger(`constructor`)
methodLogger.debug(`constructor() params=${JSON.stringify(params)}`) methodLogger.debug(`constructor() params=${JSON.stringify(params)}`)
super(params); super(params);
this.sendEmailCommandParams = params;
} }
validate(): boolean { validate(): boolean {
@ -42,15 +45,15 @@ export class SendEmailCommand extends BaseCommand<{ success: boolean }> {
throw new Error('Invalid command parameters'); throw new Error('Invalid command parameters');
} }
// find sender user // find sender user
const senderUser = await findForeignUserByUuids(this.params.senderComUuid, this.params.senderGradidoId); const senderUser = await findForeignUserByUuids(this.sendEmailCommandParams.senderComUuid, this.sendEmailCommandParams.senderGradidoId);
if (!senderUser) { if (!senderUser) {
const errmsg = `Sender user not found: ${this.params.senderComUuid} ${this.params.senderGradidoId}`; const errmsg = `Sender user not found: ${this.sendEmailCommandParams.senderComUuid} ${this.sendEmailCommandParams.senderGradidoId}`;
methodLogger.error(errmsg); methodLogger.error(errmsg);
throw new Error(errmsg); throw new Error(errmsg);
} }
const recipientUser = await findUserByIdentifier(this.params.receiverGradidoId, this.params.receiverComUuid); const recipientUser = await findUserByIdentifier(this.sendEmailCommandParams.receiverGradidoId, this.sendEmailCommandParams.receiverComUuid);
if (!recipientUser) { if (!recipientUser) {
const errmsg = `Recipient user not found: ${this.params.receiverComUuid} ${this.params.receiverGradidoId}`; const errmsg = `Recipient user not found: ${this.sendEmailCommandParams.receiverComUuid} ${this.sendEmailCommandParams.receiverGradidoId}`;
methodLogger.error(errmsg); methodLogger.error(errmsg);
throw new Error(errmsg); throw new Error(errmsg);
} }
@ -62,16 +65,16 @@ export class SendEmailCommand extends BaseCommand<{ success: boolean }> {
language: recipientUser.language, language: recipientUser.language,
senderFirstName: senderUser.firstName, senderFirstName: senderUser.firstName,
senderLastName: senderUser.lastName, senderLastName: senderUser.lastName,
senderEmail: senderUser.emailContact?.email, senderEmail: 'transactionReceivedNoSender',
memo: this.params.memo || '', memo: this.sendEmailCommandParams.memo || '',
transactionAmount: this.params.amount || 0, transactionAmount: new Decimal(this.sendEmailCommandParams.amount || 0),
}; };
switch(this.params.mailType) { switch(this.sendEmailCommandParams.mailType) {
case 'sendTransactionReceivedEmail': case 'sendTransactionReceivedEmail':
await sendTransactionReceivedEmail(emailParams); await sendTransactionReceivedEmail(emailParams);
break; break;
default: default:
throw new Error(`Unknown mail type: ${this.params.mailType}`); throw new Error(`Unknown mail type: ${this.sendEmailCommandParams.mailType}`);
} }
try { try {