From e67be6394178e12fdd2fbdc9a74dd40e12de78a2 Mon Sep 17 00:00:00 2001
From: clauspeterhuebner
Date: Thu, 19 Feb 2026 00:18:07 +0100
Subject: [PATCH] cleanup code
---
core/src/command/BaseCommand.ts | 2 +-
core/src/command/Command.ts | 2 +-
core/src/command/CommandExecutor.ts | 59 ++++++++++---------
core/src/command/commands/ExampleCommands.ts | 28 ---------
core/src/command/commands/SendEmailCommand.ts | 2 +-
5 files changed, 35 insertions(+), 58 deletions(-)
delete mode 100644 core/src/command/commands/ExampleCommands.ts
diff --git a/core/src/command/BaseCommand.ts b/core/src/command/BaseCommand.ts
index 856d2f7a3..6c60ce7bd 100644
--- a/core/src/command/BaseCommand.ts
+++ b/core/src/command/BaseCommand.ts
@@ -12,7 +12,7 @@ export abstract class BaseCommand implements Command {
// this.validateRequiredFields();
}
- abstract execute(): Promise;
+ abstract execute(): Promise | boolean | null | Error>;
private validateRequiredFields(): void {
const methodLogger = createLogger(`validateRequiredFields`)
diff --git a/core/src/command/Command.ts b/core/src/command/Command.ts
index c95e45af9..ac1392dc5 100644
--- a/core/src/command/Command.ts
+++ b/core/src/command/Command.ts
@@ -1,4 +1,4 @@
export interface Command {
- execute(): Promise;
+ execute(): Promise | boolean | null | Error>;
validate?(): boolean;
}
diff --git a/core/src/command/CommandExecutor.ts b/core/src/command/CommandExecutor.ts
index bfb505aaa..f4987c2a1 100644
--- a/core/src/command/CommandExecutor.ts
+++ b/core/src/command/CommandExecutor.ts
@@ -2,7 +2,6 @@
import { CommandJwtPayloadType } from 'shared';
import { interpretEncryptedTransferArgs } from '../graphql/logic/interpretEncryptedTransferArgs';
import { EncryptedTransferArgs } from '../graphql/model/EncryptedTransferArgs';
-import { BaseCommand } from './BaseCommand';
import { Command } from './Command';
import { getLogger } from 'log4js';
import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const';
@@ -24,20 +23,9 @@ export class CommandExecutor {
}
methodLogger.debug(`executeCommand() executing command=${command.constructor.name}`)
const result = await command.execute();
- // "accepted":["stage5@gradido.net"],"rejected":[],"ehlo":["PIPELINING","SIZE 25600000","ETRN","AUTH DIGEST-MD5 CRAM-MD5 PLAIN LOGIN","ENHANCEDSTATUSCODES","8BITMIME","DSN","CHUNKING"],"envelopeTime":25,"messageTime":146,"messageSize":37478,"response":"250 2.0.0 Ok: queued as 14B46100B7F","envelope":{"from":"stage5@gradido.net","to":["stage5@gradido.net"]}
- const resultMsg = this.isEmailResult(result) ? {
- accepted: result.accepted,
- messageSize: result.messageSize,
- response: result.response,
- envelope: result.envelope,
- } : {
- accepted: [],
- messageSize: 0,
- response: JSON.stringify(result),
- envelope: null
- };
- methodLogger.debug(`executeCommand() executed result=${JSON.stringify(resultMsg)}`)
- return { success: true, data: JSON.stringify(resultMsg) };
+ const resultMsg = this.getEmailResult(result);
+ methodLogger.debug(`executeCommand() executed email-result=${resultMsg}`)
+ return { success: true, data: resultMsg };
} catch (error) {
methodLogger.error(`executeCommand() error=${error}`)
return {
@@ -84,18 +72,35 @@ export class CommandExecutor {
}
}
- private isEmailResult(result: any): result is {
- accepted: string[];
- messageSize: number;
- response: string;
- envelope: any;
- } {
- return result &&
- typeof result === 'object' &&
- Array.isArray(result.accepted) &&
- typeof result.messageSize === 'number' &&
- typeof result.response === 'string' &&
- typeof result.envelope === 'object';
+ private getEmailResult(result: Record | boolean | null | Error): string {
+ const methodLogger = createLogger(`getEmailResult`)
+ if (methodLogger.isDebugEnabled()) {
+ methodLogger.debug(`getEmailResult() result=${JSON.stringify(result)}`)
+ }
+ let emailResult: string;
+ if(result === null) {
+ emailResult = `getEmailResult() result is null`
+ }
+ else if(typeof result === 'boolean') {
+ emailResult = `getEmailResult() result is ${result}`
+ }
+ else if(result instanceof Error) {
+ emailResult = `getEmailResult() error-message is ${result.message}`
+ }
+ else if(typeof result === 'object') {
+ // "accepted":["stage5@gradido.net"],"rejected":[],"ehlo":["PIPELINING","SIZE 25600000","ETRN","AUTH DIGEST-MD5 CRAM-MD5 PLAIN LOGIN","ENHANCEDSTATUSCODES","8BITMIME","DSN","CHUNKING"],"envelopeTime":25,"messageTime":146,"messageSize":37478,"response":"250 2.0.0 Ok: queued as 14B46100B7F","envelope":{"from":"stage5@gradido.net","to":["stage5@gradido.net"]}
+
+ const accepted = (result as Record).accepted;
+ const messageSize = (result as Record).messageSize;
+ const response = (result as Record).response;
+ const envelope = (result as Record).envelope;
+ emailResult = `getEmailResult() accepted=${accepted}, messageSize=${messageSize}, response=${response}, envelope=${envelope}`
+ }
+ else {
+ emailResult = `getEmailResult() result is unknown type`
+ }
+
+ return emailResult;
}
}
diff --git a/core/src/command/commands/ExampleCommands.ts b/core/src/command/commands/ExampleCommands.ts
deleted file mode 100644
index 2ca9ea2bb..000000000
--- a/core/src/command/commands/ExampleCommands.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-// core/src/command/commands/ExampleCommand.ts
-/*
-import { BaseCommand } from '../BaseCommand';
-import { CommandRegistry } from '../CommandRegistry';
-
-export interface ExampleCommandParams {
- someData: string;
-}
-
-export class ExampleCommand extends BaseCommand<{ processed: boolean }> {
- constructor(params: ExampleCommandParams) {
- super('EXAMPLE_COMMAND', params);
- }
-
- validate(): boolean {
- return !!this.params.someData;
- }
-
- async execute(): Promise<{ processed: boolean }> {
- // Command implementation here
- console.log('Executing ExampleCommand with data:', this.params.someData);
- return { processed: true };
- }
-}
-
-// Register the command
-CommandRegistry.registerCommand('EXAMPLE_COMMAND', ExampleCommand);
-*/
\ No newline at end of file
diff --git a/core/src/command/commands/SendEmailCommand.ts b/core/src/command/commands/SendEmailCommand.ts
index 1e119e755..2a67bdd94 100644
--- a/core/src/command/commands/SendEmailCommand.ts
+++ b/core/src/command/commands/SendEmailCommand.ts
@@ -57,7 +57,7 @@ export class SendEmailCommand extends BaseCommand | bool
}
methodLogger.debug(`find recipient user: ${this.sendEmailCommandParams.receiverComUuid} ${this.sendEmailCommandParams.receiverGradidoId}`)
- const recipientUser = await findUserByUuids(this.sendEmailCommandParams.receiverGradidoId, this.sendEmailCommandParams.receiverComUuid);
+ const recipientUser = await findUserByUuids(this.sendEmailCommandParams.receiverComUuid, this.sendEmailCommandParams.receiverGradidoId);
methodLogger.debug(`recipientUser=${JSON.stringify(recipientUser)}`)
if (!recipientUser) {
const errmsg = `Recipient user not found: ${this.sendEmailCommandParams.receiverComUuid} ${this.sendEmailCommandParams.receiverGradidoId}`;