From 9b5e64d455a9703f467ad049a916c158484c1cc9 Mon Sep 17 00:00:00 2001 From: clauspeterhuebner Date: Wed, 18 Feb 2026 16:55:51 +0100 Subject: [PATCH] cleanup code --- backend/src/graphql/schema.ts | 2 -- core/src/command/BaseCommand.ts | 2 +- core/src/command/CommandExecutor.ts | 24 +++++++++++++++++-- core/src/command/CommandFactory.ts | 5 ++-- core/src/command/CommandRegistry.ts | 24 ------------------- core/src/command/CommandTypes.ts | 2 +- core/src/command/commands/ExampleCommands.ts | 2 ++ core/src/command/commands/SendEmailCommand.ts | 6 ++--- core/tsconfig.json | 1 + database/src/queries/user.ts | 11 +++++++++ 10 files changed, 44 insertions(+), 35 deletions(-) delete mode 100644 core/src/command/CommandRegistry.ts diff --git a/backend/src/graphql/schema.ts b/backend/src/graphql/schema.ts index 28a35511d..bebc3dbda 100644 --- a/backend/src/graphql/schema.ts +++ b/backend/src/graphql/schema.ts @@ -6,7 +6,6 @@ import { buildSchema } from 'type-graphql' import { isAuthorized } from './directive/isAuthorized' import { AiChatResolver } from './resolver/AiChatResolver' import { BalanceResolver } from './resolver/BalanceResolver' -import { CommandResolver } from 'core' import { CommunityResolver } from './resolver/CommunityResolver' import { ContributionLinkResolver } from './resolver/ContributionLinkResolver' import { ContributionMessageResolver } from './resolver/ContributionMessageResolver' @@ -26,7 +25,6 @@ export const schema = async (): Promise => { resolvers: [ AiChatResolver, BalanceResolver, - CommandResolver, CommunityResolver, ContributionLinkResolver, ContributionMessageResolver, diff --git a/core/src/command/BaseCommand.ts b/core/src/command/BaseCommand.ts index d075a940f..856d2f7a3 100644 --- a/core/src/command/BaseCommand.ts +++ b/core/src/command/BaseCommand.ts @@ -1,6 +1,6 @@ import { getLogger } from 'log4js'; -import { Command } from './Command'; import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const'; +import { Command } from './Command'; const createLogger = (method: string) => getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.command.BaseCommand.${method}`) diff --git a/core/src/command/CommandExecutor.ts b/core/src/command/CommandExecutor.ts index 31cb7e245..bfb505aaa 100644 --- a/core/src/command/CommandExecutor.ts +++ b/core/src/command/CommandExecutor.ts @@ -25,12 +25,17 @@ 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 = { + 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) }; } catch (error) { @@ -78,4 +83,19 @@ export class CommandExecutor { return errorResult; } } + + 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'; + } + } diff --git a/core/src/command/CommandFactory.ts b/core/src/command/CommandFactory.ts index a8ba1b8fd..5c5374778 100644 --- a/core/src/command/CommandFactory.ts +++ b/core/src/command/CommandFactory.ts @@ -1,9 +1,10 @@ -import { Command } from './Command'; +import { ICommandConstructor } from './CommandTypes'; import { BaseCommand } from './BaseCommand'; import { getLogger } from 'log4js'; import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const'; -import { ICommandConstructor } from './CommandTypes'; +// import { ICommandConstructor } from './CommandTypes'; import { SendEmailCommand } from './commands/SendEmailCommand'; +import { Command } from './Command'; const createLogger = (method: string) => getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.command.CommandFactory.${method}`) diff --git a/core/src/command/CommandRegistry.ts b/core/src/command/CommandRegistry.ts deleted file mode 100644 index 321ca370d..000000000 --- a/core/src/command/CommandRegistry.ts +++ /dev/null @@ -1,24 +0,0 @@ -// core/src/command/CommandRegistry.ts -import { ICommand } from './CommandTypes'; - -export class CommandRegistry { - private static instance: CommandRegistry; - private commands: Map ICommand> = new Map(); - - private constructor() {} - - static getInstance(): CommandRegistry { - if (!CommandRegistry.instance) { - CommandRegistry.instance = new CommandRegistry(); - } - return CommandRegistry.instance; - } - - static registerCommand(type: string, commandClass: new (params: any) => ICommand): void { - this.getInstance().commands.set(type, commandClass); - } - - static getCommandClass(type: string): (new (params: any) => ICommand) | undefined { - return this.getInstance().commands.get(type); - } -} diff --git a/core/src/command/CommandTypes.ts b/core/src/command/CommandTypes.ts index 70fc16515..9a6ebefc1 100644 --- a/core/src/command/CommandTypes.ts +++ b/core/src/command/CommandTypes.ts @@ -2,4 +2,4 @@ import { Command } from "./Command"; export interface ICommandConstructor { new (params: any): Command; -} +} \ No newline at end of file diff --git a/core/src/command/commands/ExampleCommands.ts b/core/src/command/commands/ExampleCommands.ts index 9fcc3787e..2ca9ea2bb 100644 --- a/core/src/command/commands/ExampleCommands.ts +++ b/core/src/command/commands/ExampleCommands.ts @@ -1,4 +1,5 @@ // core/src/command/commands/ExampleCommand.ts +/* import { BaseCommand } from '../BaseCommand'; import { CommandRegistry } from '../CommandRegistry'; @@ -24,3 +25,4 @@ export class ExampleCommand extends BaseCommand<{ processed: boolean }> { // 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 e4334e0b6..1e119e755 100644 --- a/core/src/command/commands/SendEmailCommand.ts +++ b/core/src/command/commands/SendEmailCommand.ts @@ -1,6 +1,6 @@ import { BaseCommand } from '../BaseCommand'; import { sendTransactionReceivedEmail } from '../../emails/sendEmailVariants'; -import { findForeignUserByUuids, findUserByIdentifier } from 'database'; +import { findUserByUuids } from 'database'; import { LOG4JS_BASE_CATEGORY_NAME } from '../../config/const'; import { getLogger } from 'log4js'; import Decimal from 'decimal.js-light'; @@ -48,7 +48,7 @@ export class SendEmailCommand extends BaseCommand | bool } // find sender user methodLogger.debug(`find sender user: ${this.sendEmailCommandParams.senderComUuid} ${this.sendEmailCommandParams.senderGradidoId}`) - const senderUser = await findForeignUserByUuids(this.sendEmailCommandParams.senderComUuid, this.sendEmailCommandParams.senderGradidoId); + const senderUser = await findUserByUuids(this.sendEmailCommandParams.senderComUuid, this.sendEmailCommandParams.senderGradidoId, true); methodLogger.debug(`senderUser=${JSON.stringify(senderUser)}`) if (!senderUser) { const errmsg = `Sender user not found: ${this.sendEmailCommandParams.senderComUuid} ${this.sendEmailCommandParams.senderGradidoId}`; @@ -57,7 +57,7 @@ export class SendEmailCommand extends BaseCommand | bool } methodLogger.debug(`find recipient user: ${this.sendEmailCommandParams.receiverComUuid} ${this.sendEmailCommandParams.receiverGradidoId}`) - const recipientUser = await findUserByIdentifier(this.sendEmailCommandParams.receiverGradidoId, this.sendEmailCommandParams.receiverComUuid); + const recipientUser = await findUserByUuids(this.sendEmailCommandParams.receiverGradidoId, this.sendEmailCommandParams.receiverComUuid); methodLogger.debug(`recipientUser=${JSON.stringify(recipientUser)}`) if (!recipientUser) { const errmsg = `Recipient user not found: ${this.sendEmailCommandParams.receiverComUuid} ${this.sendEmailCommandParams.receiverGradidoId}`; diff --git a/core/tsconfig.json b/core/tsconfig.json index 9b7d654d2..711c21cc9 100644 --- a/core/tsconfig.json +++ b/core/tsconfig.json @@ -76,6 +76,7 @@ }, "include": [ "src/**/*.ts", + "src/**/*.json", ], "references": [], /* Any project that is referenced must itself have a `references` array (which may be empty). */ "exclude": ["**/*.test.ts", "**/*.spec.ts", "test/*", "**/bun.d.ts", "esbuild.config.ts"], diff --git a/database/src/queries/user.ts b/database/src/queries/user.ts index 2a1c474d7..7a072e058 100644 --- a/database/src/queries/user.ts +++ b/database/src/queries/user.ts @@ -82,6 +82,17 @@ export async function findForeignUserByUuids( }) } +export async function findUserByUuids( + communityUuid: string, + gradidoID: string, + foreign: boolean = false, +): Promise { + return DbUser.findOne({ + where: { foreign, communityUuid, gradidoID }, + relations: ['emailContact'], + }) +} + export async function findUserNamesByIds(userIds: number[]): Promise> { const users = await DbUser.find({ select: { id: true, firstName: true, lastName: true, alias: true },