mirror of
https://github.com/IT4Change/gradido.git
synced 2026-03-01 12:44:43 +00:00
linting
This commit is contained in:
parent
a4d5fef185
commit
3ce4b92d0f
@ -1,28 +1,30 @@
|
||||
import { getLogger } from 'log4js';
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const';
|
||||
import { Command } from './Command';
|
||||
import { getLogger } from 'log4js'
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const'
|
||||
import { Command } from './Command'
|
||||
|
||||
const createLogger = (method: string) =>
|
||||
getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.command.BaseCommand.${method}`)
|
||||
|
||||
export abstract class BaseCommand<T = any> implements Command<T> {
|
||||
protected abstract requiredFields: string[];
|
||||
protected abstract requiredFields: string[]
|
||||
|
||||
protected constructor(protected readonly params: any[]) {
|
||||
// this.validateRequiredFields();
|
||||
}
|
||||
|
||||
abstract execute(): Promise<string | boolean | null | Error>;
|
||||
abstract execute(): Promise<string | boolean | null | Error>
|
||||
|
||||
private validateRequiredFields(): void {
|
||||
const methodLogger = createLogger(`validateRequiredFields`)
|
||||
if(!this.requiredFields || this.requiredFields.length === 0) {
|
||||
if (!this.requiredFields || this.requiredFields.length === 0) {
|
||||
methodLogger.debug(`validateRequiredFields() no required fields`)
|
||||
return;
|
||||
return
|
||||
}
|
||||
methodLogger.debug(`validateRequiredFields() requiredFields=${JSON.stringify(this.requiredFields)}`)
|
||||
const commandArgs = JSON.parse(this.params[0])
|
||||
methodLogger.debug(
|
||||
`validateRequiredFields() requiredFields=${JSON.stringify(this.requiredFields)}`,
|
||||
)
|
||||
/*
|
||||
const commandArgs = JSON.parse(this.params[0])
|
||||
const missingFields = this.requiredFields.filter(field =>
|
||||
commandArgs.{ field } === undefined || commandArgs.{ field } === null || commandArgs.{ field } === ''
|
||||
);
|
||||
@ -37,7 +39,9 @@ export abstract class BaseCommand<T = any> implements Command<T> {
|
||||
|
||||
validate(): boolean {
|
||||
const methodLogger = createLogger(`validate`)
|
||||
methodLogger.debug(`validate() requiredFields=${JSON.stringify(this.requiredFields)} params=${JSON.stringify(this.params)}`)
|
||||
methodLogger.debug(
|
||||
`validate() requiredFields=${JSON.stringify(this.requiredFields)} params=${JSON.stringify(this.params)}`,
|
||||
)
|
||||
/*
|
||||
const isValid = this.requiredFields.every(field =>
|
||||
this.params[field] !== undefined &&
|
||||
@ -46,7 +50,6 @@ export abstract class BaseCommand<T = any> implements Command<T> {
|
||||
);
|
||||
methodLogger.debug(`validate() isValid=${isValid}`)
|
||||
*/
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
export interface Command<T = any> {
|
||||
execute(): Promise<string | boolean | null | Error>;
|
||||
validate?(): boolean;
|
||||
export interface Command<_T = any> {
|
||||
execute(): Promise<string | boolean | null | Error>
|
||||
validate?(): boolean
|
||||
}
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
// core/src/command/CommandExecutor.ts
|
||||
import { CommandJwtPayloadType } from 'shared';
|
||||
import { interpretEncryptedTransferArgs } from '../graphql/logic/interpretEncryptedTransferArgs';
|
||||
import { EncryptedTransferArgs } from '../graphql/model/EncryptedTransferArgs';
|
||||
import { Command } from './Command';
|
||||
import { getLogger } from 'log4js';
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const';
|
||||
import { CommandFactory } from './CommandFactory';
|
||||
import { CommandResult } from '../graphql/model/CommandResult';
|
||||
|
||||
import { getLogger } from 'log4js'
|
||||
import { CommandJwtPayloadType } from 'shared'
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const'
|
||||
import { interpretEncryptedTransferArgs } from '../graphql/logic/interpretEncryptedTransferArgs'
|
||||
import { CommandResult } from '../graphql/model/CommandResult'
|
||||
import { EncryptedTransferArgs } from '../graphql/model/EncryptedTransferArgs'
|
||||
import { Command } from './Command'
|
||||
import { CommandFactory } from './CommandFactory'
|
||||
|
||||
const createLogger = (method: string) =>
|
||||
getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.command.CommandExecutor.${method}`)
|
||||
@ -19,28 +20,28 @@ export class CommandExecutor {
|
||||
if (command.validate && !command.validate()) {
|
||||
const errmsg = `Command validation failed for command=${command.constructor.name}`
|
||||
methodLogger.error(errmsg)
|
||||
return { success: false, error: errmsg };
|
||||
return { success: false, error: errmsg }
|
||||
}
|
||||
methodLogger.debug(`executeCommand() executing command=${command.constructor.name}`)
|
||||
const result = await command.execute();
|
||||
const result = await command.execute()
|
||||
methodLogger.debug(`executeCommand() executed result=${result}`)
|
||||
return { success: true, data: result };
|
||||
return { success: true, data: result }
|
||||
} catch (error) {
|
||||
methodLogger.error(`executeCommand() error=${error}`)
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Unknown error occurred'
|
||||
};
|
||||
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async executeEncryptedCommand<T>(
|
||||
encryptedArgs: EncryptedTransferArgs
|
||||
): Promise<CommandResult> {
|
||||
async executeEncryptedCommand<_T>(encryptedArgs: EncryptedTransferArgs): Promise<CommandResult> {
|
||||
const methodLogger = createLogger(`executeEncryptedCommand`)
|
||||
try {
|
||||
// Decrypt the command data
|
||||
const commandArgs = (await interpretEncryptedTransferArgs(encryptedArgs)) as CommandJwtPayloadType
|
||||
const commandArgs = (await interpretEncryptedTransferArgs(
|
||||
encryptedArgs,
|
||||
)) as CommandJwtPayloadType
|
||||
if (!commandArgs) {
|
||||
const errmsg = `invalid commandArgs payload of requesting community with publicKey=${encryptedArgs.publicKey}`
|
||||
methodLogger.error(errmsg)
|
||||
@ -49,13 +50,16 @@ export class CommandExecutor {
|
||||
if (methodLogger.isDebugEnabled()) {
|
||||
methodLogger.debug(`executeEncryptedCommand() commandArgs=${JSON.stringify(commandArgs)}`)
|
||||
}
|
||||
const command = CommandFactory.getInstance().createCommand(commandArgs.commandName, commandArgs.commandArgs);
|
||||
const command = CommandFactory.getInstance().createCommand(
|
||||
commandArgs.commandName,
|
||||
commandArgs.commandArgs,
|
||||
)
|
||||
if (methodLogger.isDebugEnabled()) {
|
||||
methodLogger.debug(`executeEncryptedCommand() command=${JSON.stringify(command)}`)
|
||||
}
|
||||
|
||||
// Execute the command
|
||||
const result = await this.executeCommand(command);
|
||||
const result = await this.executeCommand(command)
|
||||
if (methodLogger.isDebugEnabled()) {
|
||||
methodLogger.debug(`executeCommand() result=${JSON.stringify(result)}`)
|
||||
}
|
||||
@ -65,9 +69,9 @@ export class CommandExecutor {
|
||||
methodLogger.error(`executeEncryptedCommand() error=${error}`)
|
||||
const errorResult: CommandResult = {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Failed to process command'
|
||||
};
|
||||
return errorResult;
|
||||
error: error instanceof Error ? error.message : 'Failed to process command',
|
||||
}
|
||||
return errorResult
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,25 +1,25 @@
|
||||
import { ICommandConstructor } from './CommandTypes';
|
||||
import { BaseCommand } from './BaseCommand';
|
||||
import { getLogger } from 'log4js';
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const';
|
||||
import { getLogger } from 'log4js'
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const'
|
||||
import { BaseCommand } from './BaseCommand'
|
||||
import { Command } from './Command'
|
||||
import { ICommandConstructor } from './CommandTypes'
|
||||
// import { ICommandConstructor } from './CommandTypes';
|
||||
import { SendEmailCommand } from './commands/SendEmailCommand';
|
||||
import { Command } from './Command';
|
||||
import { SendEmailCommand } from './commands/SendEmailCommand'
|
||||
|
||||
const createLogger = (method: string) =>
|
||||
getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.command.CommandFactory.${method}`)
|
||||
|
||||
export class CommandFactory {
|
||||
private static instance: CommandFactory;
|
||||
private commands: Map<string, ICommandConstructor> = new Map();
|
||||
private static instance: CommandFactory
|
||||
private commands: Map<string, ICommandConstructor> = new Map()
|
||||
|
||||
private constructor() {}
|
||||
|
||||
static getInstance(): CommandFactory {
|
||||
if (!CommandFactory.instance) {
|
||||
CommandFactory.instance = new CommandFactory();
|
||||
CommandFactory.instance = new CommandFactory()
|
||||
}
|
||||
return CommandFactory.instance;
|
||||
return CommandFactory.instance
|
||||
}
|
||||
|
||||
registerCommand<T>(name: string, commandClass: ICommandConstructor<T>): void {
|
||||
@ -27,7 +27,7 @@ export class CommandFactory {
|
||||
if (methodLogger.isDebugEnabled()) {
|
||||
methodLogger.debug(`registerCommand() name=${name}, commandClass=${commandClass.name}`)
|
||||
}
|
||||
this.commands.set(name, commandClass);
|
||||
this.commands.set(name, commandClass)
|
||||
if (methodLogger.isDebugEnabled()) {
|
||||
methodLogger.debug(`registerCommand() commands=${JSON.stringify(this.commands.entries())}`)
|
||||
}
|
||||
@ -38,14 +38,16 @@ export class CommandFactory {
|
||||
if (methodLogger.isDebugEnabled()) {
|
||||
methodLogger.debug(`createCommand() name=${name} params=${JSON.stringify(params)}`)
|
||||
}
|
||||
const CommandClass = this.commands.get(name);
|
||||
const CommandClass = this.commands.get(name)
|
||||
if (methodLogger.isDebugEnabled()) {
|
||||
methodLogger.debug(`createCommand() name=${name} commandClass=${CommandClass ? CommandClass.name : 'null'}`)
|
||||
methodLogger.debug(
|
||||
`createCommand() name=${name} commandClass=${CommandClass ? CommandClass.name : 'null'}`,
|
||||
)
|
||||
}
|
||||
if (CommandClass === undefined) {
|
||||
const errmsg = `Command ${name} not found`;
|
||||
methodLogger.error(errmsg);
|
||||
throw new Error(errmsg);
|
||||
const errmsg = `Command ${name} not found`
|
||||
methodLogger.error(errmsg)
|
||||
throw new Error(errmsg)
|
||||
}
|
||||
/*
|
||||
try {
|
||||
@ -60,15 +62,16 @@ export class CommandFactory {
|
||||
throw new Error(errmsg);
|
||||
}
|
||||
*/
|
||||
let command: BaseCommand;
|
||||
switch(CommandClass.name) {
|
||||
let command: BaseCommand
|
||||
switch (CommandClass.name) {
|
||||
case 'SendEmailCommand':
|
||||
command = new SendEmailCommand(params);
|
||||
break;
|
||||
default:
|
||||
const errmsg = `Command ${name} not found`;
|
||||
methodLogger.error(errmsg);
|
||||
throw new Error(errmsg);
|
||||
command = new SendEmailCommand(params)
|
||||
break
|
||||
default: {
|
||||
const errmsg = `Command ${name} not found`
|
||||
methodLogger.error(errmsg)
|
||||
throw new Error(errmsg)
|
||||
}
|
||||
}
|
||||
if (methodLogger.isDebugEnabled()) {
|
||||
methodLogger.debug(`createCommand() created command=${JSON.stringify(command)}`)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { Command } from "./Command";
|
||||
import { Command } from './Command'
|
||||
|
||||
export interface ICommandConstructor<T = any> {
|
||||
new (params: any): Command<T>;
|
||||
new (params: any): Command<T>
|
||||
}
|
||||
@ -1,68 +1,89 @@
|
||||
import { BaseCommand } from '../BaseCommand';
|
||||
import { sendTransactionReceivedEmail } from '../../emails/sendEmailVariants';
|
||||
import { findUserByUuids } from 'database';
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from '../../config/const';
|
||||
import { getLogger } from 'log4js';
|
||||
import Decimal from 'decimal.js-light';
|
||||
import { findUserByUuids } from 'database'
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { getLogger } from 'log4js'
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from '../../config/const'
|
||||
import { sendTransactionReceivedEmail } from '../../emails/sendEmailVariants'
|
||||
import { BaseCommand } from '../BaseCommand'
|
||||
|
||||
const createLogger = (method: string) =>
|
||||
getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.command.commands.SendEmailCommand.${method}`)
|
||||
|
||||
export interface SendEmailCommandParams {
|
||||
mailType: string;
|
||||
senderComUuid: string;
|
||||
senderGradidoId: string;
|
||||
receiverComUuid: string;
|
||||
receiverGradidoId: string;
|
||||
memo?: string;
|
||||
amount?: string;
|
||||
mailType: string
|
||||
senderComUuid: string
|
||||
senderGradidoId: string
|
||||
receiverComUuid: string
|
||||
receiverGradidoId: string
|
||||
memo?: string
|
||||
amount?: string
|
||||
}
|
||||
export class SendEmailCommand extends BaseCommand<Record<string, unknown> | boolean | null | Error> {
|
||||
static readonly SEND_MAIL_COMMAND = 'SEND_MAIL_COMMAND';
|
||||
protected requiredFields: string[] = ['mailType', 'senderComUuid', 'senderGradidoId', 'receiverComUuid', 'receiverGradidoId'];
|
||||
protected sendEmailCommandParams: SendEmailCommandParams;
|
||||
export class SendEmailCommand extends BaseCommand<
|
||||
Record<string, unknown> | boolean | null | Error
|
||||
> {
|
||||
static readonly SEND_MAIL_COMMAND = 'SEND_MAIL_COMMAND'
|
||||
protected requiredFields: string[] = [
|
||||
'mailType',
|
||||
'senderComUuid',
|
||||
'senderGradidoId',
|
||||
'receiverComUuid',
|
||||
'receiverGradidoId',
|
||||
]
|
||||
protected sendEmailCommandParams: SendEmailCommandParams
|
||||
|
||||
constructor(params: any[]) {
|
||||
const methodLogger = createLogger(`constructor`)
|
||||
methodLogger.debug(`constructor() params=${JSON.stringify(params)}`)
|
||||
super(params);
|
||||
this.sendEmailCommandParams = JSON.parse(params[0]) as SendEmailCommandParams;
|
||||
super(params)
|
||||
this.sendEmailCommandParams = JSON.parse(params[0]) as SendEmailCommandParams
|
||||
}
|
||||
|
||||
validate(): boolean {
|
||||
const baseValid = super.validate();
|
||||
const baseValid = super.validate()
|
||||
if (!baseValid) {
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
// Additional validations
|
||||
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
|
||||
async execute(): Promise<string | boolean | null | Error> {
|
||||
const methodLogger = createLogger(`execute`)
|
||||
methodLogger.debug(`execute() sendEmailCommandParams=${JSON.stringify(this.sendEmailCommandParams)}`)
|
||||
let result: string;
|
||||
methodLogger.debug(
|
||||
`execute() sendEmailCommandParams=${JSON.stringify(this.sendEmailCommandParams)}`,
|
||||
)
|
||||
let result: string
|
||||
if (!this.validate()) {
|
||||
throw new Error('Invalid command parameters');
|
||||
throw new Error('Invalid command parameters')
|
||||
}
|
||||
// find sender user
|
||||
methodLogger.debug(`find sender user: ${this.sendEmailCommandParams.senderComUuid} ${this.sendEmailCommandParams.senderGradidoId}`)
|
||||
const senderUser = await findUserByUuids(this.sendEmailCommandParams.senderComUuid, this.sendEmailCommandParams.senderGradidoId, true);
|
||||
methodLogger.debug(
|
||||
`find sender user: ${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}`;
|
||||
methodLogger.error(errmsg);
|
||||
throw new Error(errmsg);
|
||||
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.sendEmailCommandParams.receiverComUuid} ${this.sendEmailCommandParams.receiverGradidoId}`)
|
||||
const recipientUser = await findUserByUuids(this.sendEmailCommandParams.receiverComUuid, this.sendEmailCommandParams.receiverGradidoId);
|
||||
methodLogger.debug(
|
||||
`find recipient user: ${this.sendEmailCommandParams.receiverComUuid} ${this.sendEmailCommandParams.receiverGradidoId}`,
|
||||
)
|
||||
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}`;
|
||||
methodLogger.error(errmsg);
|
||||
throw new Error(errmsg);
|
||||
const errmsg = `Recipient user not found: ${this.sendEmailCommandParams.receiverComUuid} ${this.sendEmailCommandParams.receiverGradidoId}`
|
||||
methodLogger.error(errmsg)
|
||||
throw new Error(errmsg)
|
||||
}
|
||||
|
||||
const emailParams = {
|
||||
@ -75,23 +96,24 @@ export class SendEmailCommand extends BaseCommand<Record<string, unknown> | bool
|
||||
senderEmail: senderUser.emailId !== null ? senderUser.emailContact.email : null,
|
||||
memo: this.sendEmailCommandParams.memo || '',
|
||||
transactionAmount: new Decimal(this.sendEmailCommandParams.amount || 0).abs(),
|
||||
};
|
||||
}
|
||||
methodLogger.debug(`emailParams=${JSON.stringify(emailParams)}`)
|
||||
switch(this.sendEmailCommandParams.mailType) {
|
||||
case 'sendTransactionReceivedEmail':
|
||||
const emailResult = await sendTransactionReceivedEmail(emailParams);
|
||||
result = this.getEmailResult(emailResult);
|
||||
break;
|
||||
switch (this.sendEmailCommandParams.mailType) {
|
||||
case 'sendTransactionReceivedEmail': {
|
||||
const emailResult = await sendTransactionReceivedEmail(emailParams)
|
||||
result = this.getEmailResult(emailResult)
|
||||
break
|
||||
}
|
||||
default:
|
||||
throw new Error(`Unknown mail type: ${this.sendEmailCommandParams.mailType}`);
|
||||
throw new Error(`Unknown mail type: ${this.sendEmailCommandParams.mailType}`)
|
||||
}
|
||||
|
||||
try {
|
||||
// Example: const result = await emailService.sendEmail(this.params);
|
||||
return result;
|
||||
return result
|
||||
} catch (error) {
|
||||
methodLogger.error('Error executing SendEmailCommand:', error);
|
||||
throw error;
|
||||
methodLogger.error('Error executing SendEmailCommand:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,29 +122,24 @@ export class SendEmailCommand extends BaseCommand<Record<string, unknown> | bool
|
||||
if (methodLogger.isDebugEnabled()) {
|
||||
methodLogger.debug(`result=${JSON.stringify(result)}`)
|
||||
}
|
||||
let emailResult: string;
|
||||
if(result === null) {
|
||||
let emailResult: string
|
||||
if (result === null) {
|
||||
emailResult = `result is null`
|
||||
}
|
||||
else if(typeof result === 'boolean') {
|
||||
} else if (typeof result === 'boolean') {
|
||||
emailResult = `result is ${result}`
|
||||
}
|
||||
else if(result instanceof Error) {
|
||||
} else if (result instanceof Error) {
|
||||
emailResult = `error-message is ${result.message}`
|
||||
}
|
||||
else if(typeof result === 'object') {
|
||||
} 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":23,"messageTime":135,"messageSize":37478,"response":"250 2.0.0 Ok: queued as C45C2100BD7","envelope":{"from":"stage5@gradido.net","to":["stage5@gradido.net"]},"messageId":"<d269161f-f3d2-2c96-49c0-58154366271b@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 = JSON.stringify((result as Record<string, unknown>).envelope);
|
||||
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 = JSON.stringify((result as Record<string, unknown>).envelope)
|
||||
emailResult = `accepted=${accepted}, messageSize=${messageSize}, response=${response}, envelope=${envelope}`
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
emailResult = `result is unknown type`
|
||||
}
|
||||
|
||||
return emailResult;
|
||||
return emailResult
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,11 +1,11 @@
|
||||
import { CommandFactory } from './CommandFactory';
|
||||
import { SendEmailCommand } from './commands/SendEmailCommand';
|
||||
import { CommandFactory } from './CommandFactory'
|
||||
import { SendEmailCommand } from './commands/SendEmailCommand'
|
||||
// Import other commands...
|
||||
|
||||
export function initializeCommands(): void {
|
||||
const factory = CommandFactory.getInstance();
|
||||
const factory = CommandFactory.getInstance()
|
||||
|
||||
// Register all commands
|
||||
factory.registerCommand(SendEmailCommand.SEND_MAIL_COMMAND, SendEmailCommand);
|
||||
factory.registerCommand(SendEmailCommand.SEND_MAIL_COMMAND, SendEmailCommand)
|
||||
// Register other commands...
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,7 +186,7 @@ export const sendTransactionReceivedEmail = (
|
||||
locals: {
|
||||
...data,
|
||||
transactionAmount: decimalSeparatorByLanguage(data.transactionAmount, data.language),
|
||||
...data.senderEmail !== null ? getEmailCommonLocales() : {locale: data.language},
|
||||
...(data.senderEmail !== null ? getEmailCommonLocales() : { locale: data.language }),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { EncryptedTransferArgs } from '../../../graphql/model/EncryptedTransferArgs'
|
||||
import { FederatedCommunity as DbFederatedCommunity } from 'database'
|
||||
import { GraphQLClient } from 'graphql-request'
|
||||
import { getLogger } from 'log4js'
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from '../../../config/const'
|
||||
import { sendCommand as sendCommandQuery} from './query/sendCommand'
|
||||
import { EncryptedTransferArgs } from '../../../graphql/model/EncryptedTransferArgs'
|
||||
import { ensureUrlEndsWithSlash } from '../../../util/utilities'
|
||||
import { sendCommand as sendCommandQuery } from './query/sendCommand'
|
||||
|
||||
const logger = getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.federation.client.1_0.CommandClient`)
|
||||
|
||||
|
||||
@ -39,9 +39,7 @@ export class CommandClientFactory {
|
||||
* just one instance of each subclass around.
|
||||
*/
|
||||
public static getInstance(dbCom: DbFederatedCommunity): CommandClient | null {
|
||||
const instance = CommandClientFactory.instanceArray.find(
|
||||
(instance) => instance.id === dbCom.id,
|
||||
)
|
||||
const instance = CommandClientFactory.instanceArray.find((instance) => instance.id === dbCom.id)
|
||||
if (instance) {
|
||||
return instance.client
|
||||
}
|
||||
|
||||
@ -4,7 +4,11 @@ import { LOG4JS_BASE_CATEGORY_NAME } from '../../config/const'
|
||||
const createLogger = (method: string) =>
|
||||
getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.graphql.resolver.logic.processCommand.${method}`)
|
||||
|
||||
export async function processCommand(commandClass: string, commandMethod: string, commandArgs: string[]) {
|
||||
export async function processCommand(
|
||||
commandClass: string,
|
||||
commandMethod: string,
|
||||
commandArgs: string[],
|
||||
) {
|
||||
const methodLogger = createLogger(`processCommand`)
|
||||
methodLogger.info('processing a command...')
|
||||
}
|
||||
|
||||
@ -24,14 +24,16 @@ import {
|
||||
verifyAndDecrypt,
|
||||
} from 'shared'
|
||||
import { randombytes_random } from 'sodium-native'
|
||||
import { SendEmailCommand } from '../../command/commands/SendEmailCommand'
|
||||
import { CONFIG as CONFIG_CORE } from '../../config'
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from '../../config/const'
|
||||
import { sendTransactionLinkRedeemedEmail, sendTransactionReceivedEmail } from '../../emails'
|
||||
import { CommandClient as V1_0_CommandClient } from '../../federation/client/1_0/CommandClient'
|
||||
import { SendCoinsResultLoggingView } from '../../federation/client/1_0/logging/SendCoinsResultLogging.view'
|
||||
import { SendCoinsResult } from '../../federation/client/1_0/model/SendCoinsResult'
|
||||
import { SendCoinsClient as V1_0_SendCoinsClient } from '../../federation/client/1_0/SendCoinsClient'
|
||||
import { SendCoinsClientFactory } from '../../federation/client/SendCoinsClientFactory'
|
||||
import { CommandClientFactory } from '../../federation/client/CommandClientFactory'
|
||||
import { SendCoinsClientFactory } from '../../federation/client/SendCoinsClientFactory'
|
||||
import { TransactionTypeId } from '../../graphql/enum/TransactionTypeId'
|
||||
import { EncryptedTransferArgs } from '../../graphql/model/EncryptedTransferArgs'
|
||||
import { calculateSenderBalance } from '../../util/calculateSenderBalance'
|
||||
@ -39,8 +41,6 @@ import { fullName } from '../../util/utilities'
|
||||
import { settlePendingSenderTransaction } from './settlePendingSenderTransaction'
|
||||
import { storeForeignUser } from './storeForeignUser'
|
||||
import { storeLinkAsRedeemed } from './storeLinkAsRedeemed'
|
||||
import { CommandClient as V1_0_CommandClient } from '../../federation/client/1_0/CommandClient'
|
||||
import { SendEmailCommand } from '../../command/commands/SendEmailCommand'
|
||||
|
||||
const createLogger = (method: string) =>
|
||||
getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.graphql.resolver.util.processXComSendCoins.${method}`)
|
||||
@ -533,7 +533,8 @@ export async function processXComCommittingSendCoins(
|
||||
memo: pendingTx.memo,
|
||||
amount: pendingTx.amount,
|
||||
}),
|
||||
])
|
||||
],
|
||||
)
|
||||
const jws = await encryptAndSign(
|
||||
payload,
|
||||
senderCom.privateJwtKey!,
|
||||
|
||||
@ -3,11 +3,11 @@ import { Field, ObjectType } from 'type-graphql'
|
||||
@ObjectType()
|
||||
export class CommandResult {
|
||||
@Field(() => Boolean)
|
||||
success: boolean;
|
||||
success: boolean
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
data?: any;
|
||||
data?: any
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
error?: string;
|
||||
error?: string
|
||||
}
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
export * from './config/index'
|
||||
export * from './command/CommandExecutor'
|
||||
export * from './command/CommandFactory'
|
||||
export * from './command/initCommands'
|
||||
export * from './config/index'
|
||||
export * from './emails'
|
||||
export { CommandClient as V1_0_CommandClient } from './federation/client/1_0/CommandClient'
|
||||
export * from './federation/client/1_0/logging/SendCoinsArgsLogging.view'
|
||||
export * from './federation/client/1_0/logging/SendCoinsResultLogging.view'
|
||||
export * from './federation/client/1_0/model/SendCoinsArgs'
|
||||
@ -11,9 +12,8 @@ export * from './federation/client/1_0/query/revertSendCoins'
|
||||
export * from './federation/client/1_0/query/revertSettledSendCoins'
|
||||
export * from './federation/client/1_0/query/settleSendCoins'
|
||||
export * from './federation/client/1_0/query/voteForSendCoins'
|
||||
export { CommandClient as V1_0_CommandClient } from './federation/client/1_0/CommandClient'
|
||||
export { CommandClient as V1_1_CommandClient } from './federation/client/1_1/CommandClient'
|
||||
export { SendCoinsClient as V1_0_SendCoinsClient } from './federation/client/1_0/SendCoinsClient'
|
||||
export { CommandClient as V1_1_CommandClient } from './federation/client/1_1/CommandClient'
|
||||
export { SendCoinsClient as V1_1_SendCoinsClient } from './federation/client/1_1/SendCoinsClient'
|
||||
export * from './federation/client/CommandClientFactory'
|
||||
export * from './federation/client/SendCoinsClientFactory'
|
||||
|
||||
@ -1,19 +1,17 @@
|
||||
import { Resolver, Mutation, Arg, Ctx } from 'type-graphql';
|
||||
import { CommandExecutor } from 'core';
|
||||
import { CommandResult } from 'core';
|
||||
import { EncryptedTransferArgs } from 'core';
|
||||
import { CommandExecutor, CommandResult, EncryptedTransferArgs } from 'core'
|
||||
import { Arg, Ctx, Mutation, Resolver } from 'type-graphql'
|
||||
|
||||
@Resolver()
|
||||
export class CommandResolver {
|
||||
private commandExecutor = new CommandExecutor();
|
||||
private commandExecutor = new CommandExecutor()
|
||||
|
||||
@Mutation(() => CommandResult)
|
||||
async sendCommand(
|
||||
@Arg('encryptedArgs', () => EncryptedTransferArgs) encryptedArgs: any,
|
||||
@Ctx() context: any
|
||||
@Ctx() context: any,
|
||||
): Promise<CommandResult> {
|
||||
// Convert to EncryptedTransferArgs if needed
|
||||
const result = await this.commandExecutor.executeEncryptedCommand(encryptedArgs);
|
||||
return result as unknown as CommandResult;
|
||||
const result = await this.commandExecutor.executeEncryptedCommand(encryptedArgs)
|
||||
return result as unknown as CommandResult
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
import { NonEmptyArray } from 'type-graphql'
|
||||
import { AuthenticationResolver } from '../1_0/resolver/AuthenticationResolver'
|
||||
import { CommandResolver } from '../1_0/resolver/CommandResolver'
|
||||
import { PublicCommunityInfoResolver } from '../1_0/resolver/PublicCommunityInfoResolver'
|
||||
import { SendCoinsResolver } from '../1_0/resolver/SendCoinsResolver'
|
||||
import { PublicKeyResolver } from './resolver/PublicKeyResolver'
|
||||
import { CommandResolver } from '../1_0/resolver/CommandResolver'
|
||||
|
||||
export const getApiResolvers = (): NonEmptyArray<Function> => {
|
||||
return [AuthenticationResolver, CommandResolver, PublicCommunityInfoResolver, PublicKeyResolver, SendCoinsResolver]
|
||||
return [
|
||||
AuthenticationResolver,
|
||||
CommandResolver,
|
||||
PublicCommunityInfoResolver,
|
||||
PublicKeyResolver,
|
||||
SendCoinsResolver,
|
||||
]
|
||||
}
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import 'source-map-support/register'
|
||||
|
||||
import { defaultCategory, initLogger } from 'config-schema'
|
||||
import { initializeCommands } from 'core'
|
||||
import { getLogger } from 'log4js'
|
||||
import { onShutdown, printServerCrashAsciiArt, ShutdownReason } from 'shared'
|
||||
// config
|
||||
import { CONFIG } from './config'
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from './config/const'
|
||||
import { createServer } from './server/createServer'
|
||||
import { initializeCommands } from 'core'
|
||||
|
||||
async function main() {
|
||||
const startTime = new Date()
|
||||
@ -47,7 +47,6 @@ async function main() {
|
||||
})
|
||||
|
||||
initializeCommands()
|
||||
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
|
||||
@ -7,7 +7,12 @@ export class CommandJwtPayloadType extends JwtPayloadType {
|
||||
commandClass: string
|
||||
commandArgs: string[]
|
||||
|
||||
constructor(handshakeID: string, commandName: string, commandClass: string, commandArgs: string[]) {
|
||||
constructor(
|
||||
handshakeID: string,
|
||||
commandName: string,
|
||||
commandClass: string,
|
||||
commandArgs: string[],
|
||||
) {
|
||||
super(handshakeID)
|
||||
this.tokentype = CommandJwtPayloadType.COMMAND_TYPE
|
||||
this.commandName = commandName
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user