cleanup code

This commit is contained in:
clauspeterhuebner 2026-02-18 16:55:51 +01:00
parent 839ef63335
commit 9b5e64d455
10 changed files with 44 additions and 35 deletions

View File

@ -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<GraphQLSchema> => {
resolvers: [
AiChatResolver,
BalanceResolver,
CommandResolver,
CommunityResolver,
ContributionLinkResolver,
ContributionMessageResolver,

View File

@ -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}`)

View File

@ -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';
}
}

View File

@ -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}`)

View File

@ -1,24 +0,0 @@
// core/src/command/CommandRegistry.ts
import { ICommand } from './CommandTypes';
export class CommandRegistry {
private static instance: CommandRegistry;
private commands: Map<string, new (params: any) => 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);
}
}

View File

@ -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);
*/

View File

@ -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<Record<string, unknown> | 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<Record<string, unknown> | 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}`;

View File

@ -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"],

View File

@ -82,6 +82,17 @@ export async function findForeignUserByUuids(
})
}
export async function findUserByUuids(
communityUuid: string,
gradidoID: string,
foreign: boolean = false,
): Promise<DbUser | null> {
return DbUser.findOne({
where: { foreign, communityUuid, gradidoID },
relations: ['emailContact'],
})
}
export async function findUserNamesByIds(userIds: number[]): Promise<Map<number, string>> {
const users = await DbUser.find({
select: { id: true, firstName: true, lastName: true, alias: true },