Skip to content

Commit 4394144

Browse files
committed
fix: remove status from channel object
1 parent 78a7530 commit 4394144

File tree

5 files changed

+35
-52
lines changed

5 files changed

+35
-52
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
],
4040
"license": "ISC",
4141
"dependencies": {
42-
"@frmscoe/frms-coe-lib": "^2.1.3",
42+
"@frmscoe/frms-coe-lib": "^2.1.5",
4343
"@frmscoe/frms-coe-startup-lib": "^2.1.0",
4444
"@log4js-node/logstash-http": "^1.1.0",
4545
"arangojs": "^8.4.0",

src/interfaces/metaData.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/services/helper.service.ts

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ import { type ChannelResult } from '@frmscoe/frms-coe-lib/lib/interfaces/process
77
import { type TypologyResult } from '@frmscoe/frms-coe-lib/lib/interfaces/processor-files/TypologyResult';
88
import { databaseManager, loggerService } from '..';
99
import apm from '../apm';
10-
import { type MetaData } from '../interfaces/metaData';
10+
import { type MetaData } from '@frmscoe/frms-coe-lib/lib/interfaces/metaData';
11+
import { CalculateDuration } from '@frmscoe/frms-coe-lib/lib/helpers/calculatePrcg';
12+
13+
interface HandleResults {
14+
channelResults: ChannelResult[];
15+
review: boolean;
16+
}
1117

1218
export const handleChannels = async (
1319
message: Message,
1420
transaction: Pacs002,
1521
networkMap: NetworkMap,
1622
channelResult: ChannelResult,
17-
): Promise<ChannelResult[]> => {
23+
): Promise<HandleResults> => {
1824
const span = apm.startSpan('handleChannels');
1925

2026
try {
@@ -30,7 +36,7 @@ export const handleChannels = async (
3036
if (jchannelCount && jchannelCount < message.channels.length) {
3137
span?.end();
3238
loggerService.log('All channels not completed.');
33-
return [];
39+
return { channelResults: [], review: false };
3440
}
3541
const jchannelResults = await databaseManager.getMemberValues(cacheKey);
3642
spanDBMembers?.end();
@@ -42,24 +48,19 @@ export const handleChannels = async (
4248
if (configuredChannel) {
4349
const channelRes = channelResults.find((c) => c.id === configuredChannel.id && c.cfg === configuredChannel.cfg);
4450
if (!channelRes) continue;
45-
const channelIndex = channelResults.findIndex((c) => c.id === configuredChannel.id && c.cfg === configuredChannel.cfg);
4651
for (const typology of configuredChannel.typologies) {
4752
const typologyResult = channelRes?.typologyResult.find((t) => t.id === typology.id && t.cfg === typology.cfg);
4853
if (!typologyResult) continue;
4954
if (typologyResult.review) review = true;
5055
}
51-
52-
channelResults[channelIndex].status = review ? 'ALRT' : 'NALT';
53-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
54-
loggerService.log(`Transaction: ${transactionID} has status: ${channelRes.status}`);
5556
}
5657
}
5758

5859
// Delete interim cache as transaction processed to fulfilment
5960
await databaseManager.deleteKey(cacheKey);
6061

6162
span?.end();
62-
return channelResults;
63+
return { channelResults, review };
6364
} catch (error) {
6465
span?.end();
6566
loggerService.error(error as string);
@@ -73,7 +74,7 @@ export const handleTypologies = async (
7374
networkMap: NetworkMap,
7475
typologyResult: TypologyResult,
7576
metaData?: MetaData,
76-
): Promise<any> => {
77+
): Promise<HandleResults> => {
7778
let span;
7879
const startTime = process.hrtime.bigint();
7980
try {
@@ -84,8 +85,8 @@ export const handleTypologies = async (
8485
// check if all results for this Channel is found
8586
if (jtypologyCount && jtypologyCount < channel.typologies.length) {
8687
return {
87-
result: 'Incomplete',
88-
tadpReqBody: undefined,
88+
review: false,
89+
channelResults: [],
8990
};
9091
}
9192

@@ -94,17 +95,12 @@ export const handleTypologies = async (
9495
const typologyResults: TypologyResult[] = jtypologyResults.map((jtypologyResult) => jtypologyResult.typologyResult as TypologyResult);
9596
if (!typologyResults || !typologyResults.length)
9697
return {
97-
result: 'Error',
98-
tadpReqBody: undefined,
98+
review: false,
99+
channelResults: [],
99100
};
100101

101-
// Keep scaffold here - this will be used in future.
102-
// const expressionRes = await arangoDBService.getExpression(channel.channel_id);
103-
// if (!expressionRes)
104-
// return 0.0;
105-
106102
const channelResult: ChannelResult = {
107-
prcgTm: calculateDuration(startTime),
103+
prcgTm: CalculateDuration(startTime),
108104
result: 0.0,
109105
cfg: channel.cfg,
110106
id: channel.id,
@@ -117,29 +113,24 @@ export const handleTypologies = async (
117113
if (!message) {
118114
loggerService.error(`Failed to process Channel ${channel.id} request , Message missing from networkmap.`);
119115
return {
120-
result: 'Error',
121-
tadpReqBody: undefined,
116+
review: false,
117+
channelResults: [],
122118
};
123119
}
124120

125-
const channelResults = await handleChannels(message, transaction, networkMap, channelResult);
121+
const { channelResults, review } = await handleChannels(message, transaction, networkMap, channelResult);
126122
apmTadProc?.end();
127123

128124
span = apm.startSpan(`[${transactionID}] Delete Channel interim cache key`);
129125
await databaseManager.deleteKey(cacheKey);
130126
span?.end();
131-
return channelResults;
127+
return { channelResults, review };
132128
} catch (error) {
133129
span?.end();
134130
loggerService.error(`Failed to process Channel ${channel.id} request`, error as Error, 'executeRequest');
135131
return {
136-
result: 'Error',
137-
tadpReqBody: undefined,
132+
review: false,
133+
channelResults: [],
138134
};
139135
}
140136
};
141-
142-
export const calculateDuration = (startTime: bigint): number => {
143-
const endTime = process.hrtime.bigint();
144-
return Number(endTime - startTime);
145-
};

src/services/logic.service.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import { type Pacs002, type NetworkMap } from '@frmscoe/frms-coe-lib/lib/interfaces';
55
import { Alert } from '@frmscoe/frms-coe-lib/lib/interfaces/processor-files/Alert';
66
import { type CMSRequest } from '@frmscoe/frms-coe-lib/lib/interfaces/processor-files/CMSRequest';
7-
import { type ChannelResult } from '@frmscoe/frms-coe-lib/lib/interfaces/processor-files/ChannelResult';
87
import { type TADPResult } from '@frmscoe/frms-coe-lib/lib/interfaces/processor-files/TADPResult';
98
import { type TypologyResult } from '@frmscoe/frms-coe-lib/lib/interfaces/processor-files/TypologyResult';
109
import apm from '../apm';
1110
import { databaseManager, loggerService, server } from '../index';
12-
import { type MetaData } from '../interfaces/metaData';
13-
import { calculateDuration, handleTypologies } from './helper.service';
11+
import { type MetaData } from '@frmscoe/frms-coe-lib/lib/interfaces/metaData';
12+
import { handleTypologies } from './helper.service';
13+
import { CalculateDuration } from '@frmscoe/frms-coe-lib/lib/helpers/calculatePrcg';
1414

1515
export const handleExecute = async (rawTransaction: any): Promise<any> => {
1616
let apmTransaction = null;
@@ -43,15 +43,13 @@ export const handleExecute = async (rawTransaction: any): Promise<any> => {
4343
)[0];
4444

4545
loggerService.debug(`Processing Channel ${channel.id}.`);
46-
let review = false;
47-
const channelResults: ChannelResult[] = await handleTypologies(transaction, channel, networkMap, typologyResult, metaData);
46+
const { channelResults, review } = await handleTypologies(transaction, channel, networkMap, typologyResult, metaData);
4847

4948
if (channelResults.length > 0 && channelResults.length === networkMap.messages[0].channels.length) {
50-
if (channelResults.some((c: ChannelResult) => c.status === 'ALRT')) review = true;
5149
toReturn.id = networkMap.messages[0].id;
5250
toReturn.cfg = networkMap.messages[0].cfg;
5351
toReturn.channelResult = channelResults;
54-
toReturn.prcgTm = calculateDuration(startTime);
52+
toReturn.prcgTm = CalculateDuration(startTime);
5553

5654
const alert = new Alert();
5755
alert.tadpResult = toReturn;
@@ -69,7 +67,7 @@ export const handleExecute = async (rawTransaction: any): Promise<any> => {
6967
const spanInsertTransactionHistory = apm.startSpan('db.insert.transactionHistory');
7068
await databaseManager.insertTransaction(transactionID, transaction, networkMap, alert);
7169
spanInsertTransactionHistory?.end();
72-
result.report.tadpResult.prcgTm = calculateDuration(startTime);
70+
result.report.tadpResult.prcgTm = CalculateDuration(startTime);
7371
await server.handleResponse(result);
7472
}
7573
apmTransaction?.end();

0 commit comments

Comments
 (0)