change parameter type of command constructor

This commit is contained in:
clauspeterhuebner 2026-02-12 02:02:07 +01:00
parent e48988a0c3
commit 1d43878ad6
3 changed files with 18 additions and 14 deletions

View File

@ -8,7 +8,7 @@ const createLogger = (method: string) =>
export abstract class BaseCommand<T = any> implements Command<T> {
protected abstract requiredFields: string[];
protected constructor(protected readonly params: any = {}) {
protected constructor(protected readonly params: any[]) {
// this.validateRequiredFields();
}
@ -21,6 +21,7 @@ export abstract class BaseCommand<T = any> implements Command<T> {
return;
}
methodLogger.debug(`validateRequiredFields() requiredFields=${JSON.stringify(this.requiredFields)}`)
/*
const missingFields = this.requiredFields.filter(field =>
this.params[field] === undefined || this.params[field] === null || this.params[field] === ''
);
@ -30,6 +31,7 @@ export abstract class BaseCommand<T = any> implements Command<T> {
methodLogger.error(`validateRequiredFields() missing fields: ${missingFields.join(', ')}`)
throw new Error(`Missing required fields for ${this.constructor.name}: ${missingFields.join(', ')}`);
}
*/
}
validate(): boolean {

View File

@ -32,7 +32,7 @@ export class CommandFactory {
}
}
createCommand<T>(name: string, params: any = {}): Command<T> {
createCommand<T>(name: string, params: string[]): Command<T> {
const methodLogger = createLogger(`createCommand`)
if (methodLogger.isDebugEnabled()) {
methodLogger.debug(`createCommand() name=${name} params=${JSON.stringify(params)}`)

View File

@ -20,11 +20,13 @@ export interface SendEmailCommandParams {
export class SendEmailCommand extends BaseCommand<{ success: boolean }> {
static readonly SEND_MAIL_COMMAND = 'SEND_MAIL_COMMAND';
protected requiredFields: string[] = ['mailType', 'senderComUuid', 'senderGradidoId', 'receiverComUuid', 'receiverGradidoId'];
protected sendEmailCommandParams: SendEmailCommandParams;
constructor(params: SendEmailCommandParams) {
constructor(params: any[]) {
const methodLogger = createLogger(`constructor`)
methodLogger.debug(`constructor() params=${JSON.stringify(params)}`)
super(params);
this.sendEmailCommandParams = params[0] as SendEmailCommandParams;
}
validate(): boolean {
@ -39,25 +41,25 @@ export class SendEmailCommand extends BaseCommand<{ success: boolean }> {
async execute(): Promise<{ success: boolean }> {
const methodLogger = createLogger(`execute`)
methodLogger.debug(`execute() params=${JSON.stringify(this.params)}`)
methodLogger.debug(`execute() params=${JSON.stringify(this.sendEmailCommandParams)}`)
if (!this.validate()) {
throw new Error('Invalid command parameters');
}
// find sender user
methodLogger.debug(`find sender user: ${this.params.senderComUuid} ${this.params.senderGradidoId}`)
const senderUser = await findForeignUserByUuids(this.params.senderComUuid, this.params.senderGradidoId);
methodLogger.debug(`find sender user: ${this.sendEmailCommandParams.senderComUuid} ${this.sendEmailCommandParams.senderGradidoId}`)
const senderUser = await findForeignUserByUuids(this.sendEmailCommandParams.senderComUuid, this.sendEmailCommandParams.senderGradidoId);
methodLogger.debug(`senderUser=${JSON.stringify(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);
throw new Error(errmsg);
}
methodLogger.debug(`find recipient user: ${this.params.receiverComUuid} ${this.params.receiverGradidoId}`)
const recipientUser = await findUserByIdentifier(this.params.receiverGradidoId, this.params.receiverComUuid);
methodLogger.debug(`find recipient user: ${this.sendEmailCommandParams.receiverComUuid} ${this.sendEmailCommandParams.receiverGradidoId}`)
const recipientUser = await findUserByIdentifier(this.sendEmailCommandParams.receiverGradidoId, this.sendEmailCommandParams.receiverComUuid);
methodLogger.debug(`recipientUser=${JSON.stringify(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);
throw new Error(errmsg);
}
@ -70,15 +72,15 @@ export class SendEmailCommand extends BaseCommand<{ success: boolean }> {
senderFirstName: senderUser.firstName,
senderLastName: senderUser.lastName,
senderEmail: 'transactionReceivedNoSender',
memo: this.params.memo || '',
transactionAmount: new Decimal(this.params.amount || 0),
memo: this.sendEmailCommandParams.memo || '',
transactionAmount: new Decimal(this.sendEmailCommandParams.amount || 0),
};
switch(this.params.mailType) {
switch(this.sendEmailCommandParams.mailType) {
case 'sendTransactionReceivedEmail':
await sendTransactionReceivedEmail(emailParams);
break;
default:
throw new Error(`Unknown mail type: ${this.params.mailType}`);
throw new Error(`Unknown mail type: ${this.sendEmailCommandParams.mailType}`);
}
try {