diff --git a/src/readers/insightProcessor.ts b/src/readers/insightProcessor.ts index e9374525c426109e3a04af908a5ea141571f2ef8..1fb06370d65960efea417fc87629bc9b2158a058 100644 --- a/src/readers/insightProcessor.ts +++ b/src/readers/insightProcessor.ts @@ -57,10 +57,31 @@ export const insightProcessor = async (frontendPublisher: RabbitMqBroker) => { let insight = message.insight; if (!validateInsight(insight, message.force)) { + if (ENV == 'develop') { + const message: WsMessageBackend2Frontend = { + type: wsReturnKey.error, + callID: headers.callID, + status: 'success', + value: 'Insight no valid', + }; + + frontendPublisher.publishMessageToFrontend(message, headers.routingKey, headers); + } return; } if (!validateTypeInsight(insight, message.force)) { + if (ENV == 'develop') { + const message: WsMessageBackend2Frontend = { + type: wsReturnKey.error, + callID: headers.callID, + status: 'success', + value: 'Insight Type no valid', + }; + + frontendPublisher.publishMessageToFrontend(message, headers.routingKey, headers); + } + return; } @@ -102,16 +123,14 @@ export const insightProcessor = async (frontendPublisher: RabbitMqBroker) => { insight = statCheck(insight, result); } - log.info('Insight save: ', insight); - await ums.updateInsight(insight.userId as number, insight.id, insight); if (ENV == 'develop') { const message: WsMessageBackend2Frontend = { - type: wsReturnKey.insightResults, + type: wsReturnKey.insightResult, callID: headers.callID, - insight, status: 'success', + value: insight, }; frontendPublisher.publishMessageToFrontend(message, headers.routingKey, headers); diff --git a/src/utils/insights/validateInsight.ts b/src/utils/insights/validateInsight.ts index e8efc8d0d570acc481de7b558e9f607ea26deaff..f0827ab1372659af922440011959fa9b297ec4ea 100644 --- a/src/utils/insights/validateInsight.ts +++ b/src/utils/insights/validateInsight.ts @@ -1,4 +1,4 @@ -import { type InsightModel } from 'ts-common'; +import { type InsightModel, isValidEmail, isValidCronExpression } from 'ts-common'; import { log } from '../../logger'; export function validateInsight(insight: InsightModel, force: boolean) { @@ -8,7 +8,19 @@ export function validateInsight(insight: InsightModel, force: boolean) { } if (!insight.recipients || insight.recipients.length === 0) { - log.debug('No recipients found in the insight, skipping'); + log.error('No recipients found in the insight, skipping'); + return false; + } + + for (const recipient of insight.recipients) { + if (!isValidEmail(recipient)) { + log.error(`Invalid email for recipient: ${recipient}`); + return false; + } + } + + if (!insight.frequency || !isValidCronExpression(insight.frequency)) { + log.error('No frequency found in the insight, skipping'); return false; }