mirror of
https://github.com/IT4Change/gradido.git
synced 2026-03-01 12:44:43 +00:00
cleanup code
This commit is contained in:
parent
9b5e64d455
commit
e67be63941
@ -12,7 +12,7 @@ export abstract class BaseCommand<T = any> implements Command<T> {
|
|||||||
// this.validateRequiredFields();
|
// this.validateRequiredFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract execute(): Promise<T>;
|
abstract execute(): Promise<Record<string, unknown> | boolean | null | Error>;
|
||||||
|
|
||||||
private validateRequiredFields(): void {
|
private validateRequiredFields(): void {
|
||||||
const methodLogger = createLogger(`validateRequiredFields`)
|
const methodLogger = createLogger(`validateRequiredFields`)
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
export interface Command<T = any> {
|
export interface Command<T = any> {
|
||||||
execute(): Promise<T>;
|
execute(): Promise<Record<string, unknown> | boolean | null | Error>;
|
||||||
validate?(): boolean;
|
validate?(): boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
import { CommandJwtPayloadType } from 'shared';
|
import { CommandJwtPayloadType } from 'shared';
|
||||||
import { interpretEncryptedTransferArgs } from '../graphql/logic/interpretEncryptedTransferArgs';
|
import { interpretEncryptedTransferArgs } from '../graphql/logic/interpretEncryptedTransferArgs';
|
||||||
import { EncryptedTransferArgs } from '../graphql/model/EncryptedTransferArgs';
|
import { EncryptedTransferArgs } from '../graphql/model/EncryptedTransferArgs';
|
||||||
import { BaseCommand } from './BaseCommand';
|
|
||||||
import { Command } from './Command';
|
import { Command } from './Command';
|
||||||
import { getLogger } from 'log4js';
|
import { getLogger } from 'log4js';
|
||||||
import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const';
|
import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const';
|
||||||
@ -24,20 +23,9 @@ export class CommandExecutor {
|
|||||||
}
|
}
|
||||||
methodLogger.debug(`executeCommand() executing command=${command.constructor.name}`)
|
methodLogger.debug(`executeCommand() executing command=${command.constructor.name}`)
|
||||||
const result = await command.execute();
|
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.getEmailResult(result);
|
||||||
const resultMsg = this.isEmailResult(result) ? {
|
methodLogger.debug(`executeCommand() executed email-result=${resultMsg}`)
|
||||||
accepted: result.accepted,
|
return { success: true, data: resultMsg };
|
||||||
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) {
|
} catch (error) {
|
||||||
methodLogger.error(`executeCommand() error=${error}`)
|
methodLogger.error(`executeCommand() error=${error}`)
|
||||||
return {
|
return {
|
||||||
@ -84,18 +72,35 @@ export class CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private isEmailResult(result: any): result is {
|
private getEmailResult(result: Record<string, unknown> | boolean | null | Error): string {
|
||||||
accepted: string[];
|
const methodLogger = createLogger(`getEmailResult`)
|
||||||
messageSize: number;
|
if (methodLogger.isDebugEnabled()) {
|
||||||
response: string;
|
methodLogger.debug(`getEmailResult() result=${JSON.stringify(result)}`)
|
||||||
envelope: any;
|
}
|
||||||
} {
|
let emailResult: string;
|
||||||
return result &&
|
if(result === null) {
|
||||||
typeof result === 'object' &&
|
emailResult = `getEmailResult() result is null`
|
||||||
Array.isArray(result.accepted) &&
|
}
|
||||||
typeof result.messageSize === 'number' &&
|
else if(typeof result === 'boolean') {
|
||||||
typeof result.response === 'string' &&
|
emailResult = `getEmailResult() result is ${result}`
|
||||||
typeof result.envelope === 'object';
|
}
|
||||||
|
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<string, unknown>).accepted;
|
||||||
|
const messageSize = (result as Record<string, unknown>).messageSize;
|
||||||
|
const response = (result as Record<string, unknown>).response;
|
||||||
|
const envelope = (result as Record<string, unknown>).envelope;
|
||||||
|
emailResult = `getEmailResult() accepted=${accepted}, messageSize=${messageSize}, response=${response}, envelope=${envelope}`
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
emailResult = `getEmailResult() result is unknown type`
|
||||||
|
}
|
||||||
|
|
||||||
|
return emailResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
|
||||||
*/
|
|
||||||
@ -57,7 +57,7 @@ export class SendEmailCommand extends BaseCommand<Record<string, unknown> | bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
methodLogger.debug(`find recipient user: ${this.sendEmailCommandParams.receiverComUuid} ${this.sendEmailCommandParams.receiverGradidoId}`)
|
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)}`)
|
methodLogger.debug(`recipientUser=${JSON.stringify(recipientUser)}`)
|
||||||
if (!recipientUser) {
|
if (!recipientUser) {
|
||||||
const errmsg = `Recipient user not found: ${this.sendEmailCommandParams.receiverComUuid} ${this.sendEmailCommandParams.receiverGradidoId}`;
|
const errmsg = `Recipient user not found: ${this.sendEmailCommandParams.receiverComUuid} ${this.sendEmailCommandParams.receiverGradidoId}`;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user