mirror of
https://github.com/IT4Change/gradido.git
synced 2026-03-01 12:44:43 +00:00
correct validRequiredFields
This commit is contained in:
parent
4a71bec63c
commit
4eef68e334
@ -1,10 +1,15 @@
|
||||
import { getLogger } from 'log4js';
|
||||
import { Command } from './Command';
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const';
|
||||
|
||||
const createLogger = (method: string) =>
|
||||
getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.command.CommandExecutor.${method}`)
|
||||
|
||||
export abstract class BaseCommand<T = any> implements Command<T> {
|
||||
protected abstract requiredFields: string[];
|
||||
|
||||
|
||||
protected constructor(protected readonly params: any = {}) {
|
||||
this.validateRequiredFields();
|
||||
// this.validateRequiredFields();
|
||||
}
|
||||
|
||||
abstract execute(): Promise<T>;
|
||||
@ -18,11 +23,18 @@ export abstract class BaseCommand<T = any> implements Command<T> {
|
||||
}
|
||||
*/
|
||||
private validateRequiredFields(): void {
|
||||
if(!this.requiredFields || this.requiredFields.length === 0) {
|
||||
const methodLogger = createLogger(`validateRequiredFields`)
|
||||
methodLogger.debug(`validateRequiredFields() no required fields`)
|
||||
return;
|
||||
}
|
||||
const missingFields = this.requiredFields.filter(field =>
|
||||
this.params[field] === undefined || this.params[field] === null || this.params[field] === ''
|
||||
);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const methodLogger = createLogger(`validateRequiredFields`)
|
||||
methodLogger.error(`validateRequiredFields() missing fields: ${missingFields.join(', ')}`)
|
||||
throw new Error(`Missing required fields for ${this.constructor.name}: ${missingFields.join(', ')}`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ export interface SendEmailCommandParams {
|
||||
}
|
||||
export class SendEmailCommand extends BaseCommand<{ success: boolean }> {
|
||||
static readonly SEND_MAIL_COMMAND = 'SEND_MAIL_COMMAND';
|
||||
requiredFields: string[] = ['mailType', 'senderComUuid', 'senderGradidoId', 'receiverComUuid', 'receiverGradidoId'];
|
||||
protected requiredFields: string[] = ['mailType', 'senderComUuid', 'senderGradidoId', 'receiverComUuid', 'receiverGradidoId'];
|
||||
|
||||
constructor(params: SendEmailCommandParams) {
|
||||
const methodLogger = createLogger(`constructor`)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user