diff --git a/src/index.ts b/src/index.ts index 15b50d023b91c9ffbd1f266899e342fea313cdd1..34c70e3536b9dcecda1a5f95b0fd063ae9b55338 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,7 +24,7 @@ async function main() { log.info('Connected to Redis!'); await queryServiceReader(frontendPublisher, mlPublisher, 'neo4j'); - await insightProcessor(); + await insightProcessor(frontendPublisher); } await main(); diff --git a/src/readers/insightProcessor.ts b/src/readers/insightProcessor.ts index 777c620bb4e6bef6665e1568d46e69d8392a375c..e9374525c426109e3a04af908a5ea141571f2ef8 100644 --- a/src/readers/insightProcessor.ts +++ b/src/readers/insightProcessor.ts @@ -1,4 +1,4 @@ -import { rabbitMq, ums, mail, SMTP_USER, DEBUG_EMAIL } from '../variables'; +import { rabbitMq, ums, mail, SMTP_USER, DEBUG_EMAIL, ENV } from '../variables'; import { log } from '../logger'; import { type InsightModel } from 'ts-common'; import { createHeadlessEditor } from '@lexical/headless'; @@ -14,6 +14,7 @@ import { populateTemplate } from '../utils/insights'; import { RabbitMqBroker } from 'ts-common/rabbitMq'; import { validateInsight } from '../utils/insights/validateInsight'; import { validateTypeInsight } from '../utils/insights/validateTypeInsight'; +import { wsReturnKey, type WsMessageBackend2Frontend } from 'ts-common'; const dom = new JSDOM(); function setUpDom() { @@ -36,7 +37,7 @@ function setUpDom() { }; } -export const insightProcessor = async () => { +export const insightProcessor = async (frontendPublisher: RabbitMqBroker) => { if (mail == null) { log.warn('Mail is not configured. Insight processor will be disabled'); //return; @@ -101,8 +102,21 @@ export const insightProcessor = async () => { 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, + callID: headers.callID, + insight, + status: 'success', + }; + + frontendPublisher.publishMessageToFrontend(message, headers.routingKey, headers); + } + if (insight.status || message.force) { if (insight.status) log.debug('Insight passed the check'); if (message.force) log.debug('Forced insight processing');