Skip to content

Commit 4f328e8

Browse files
author
rtkay123
committed
feat: remove channel
1 parent 2b3adb6 commit 4f328e8

File tree

2 files changed

+34
-90
lines changed

2 files changed

+34
-90
lines changed

src/services/helper.service.ts

Lines changed: 21 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,30 @@
11
// SPDX-License-Identifier: Apache-2.0
22

33
import apm from '../apm';
4-
import { CalculateDuration } from '@frmscoe/frms-coe-lib/lib/helpers/calculatePrcg';
4+
// import { CalculateDuration } from '@frmscoe/frms-coe-lib/lib/helpers/calculatePrcg';
55
import { databaseManager, loggerService } from '..';
6-
import { type Channel, type Message, type NetworkMap, type Pacs002 } from '@frmscoe/frms-coe-lib/lib/interfaces';
7-
import { type ChannelResult } from '@frmscoe/frms-coe-lib/lib/interfaces/processor-files/ChannelResult';
6+
import { type NetworkMap, type Pacs002 } from '@frmscoe/frms-coe-lib/lib/interfaces';
87
import { type TypologyResult } from '@frmscoe/frms-coe-lib/lib/interfaces/processor-files/TypologyResult';
98

10-
export const handleChannels = async (
11-
message: Message,
12-
transaction: Pacs002,
13-
networkMap: NetworkMap,
14-
channelResult: ChannelResult,
15-
): Promise<{ channelResults: ChannelResult[]; review: boolean }> => {
16-
const span = apm.startSpan('handleChannels');
17-
const functionName = 'handleChannels()';
18-
19-
try {
20-
const transactionType = 'FIToFIPmtSts';
21-
const transactionID = transaction[transactionType].GrpHdr.MsgId;
22-
const cacheKey = `tadp_${transactionID}_${message.id}_${message.cfg}`;
23-
const spanDBMembers = apm.startSpan('db.get.members');
24-
const jchannelCount = await databaseManager.addOneGetCount(cacheKey, { channelResult: { ...channelResult } });
25-
26-
// check if all Channel results for this transaction is found
27-
if (jchannelCount && jchannelCount < message.channels.length) {
28-
span?.end();
29-
loggerService.log('All channels not completed.', functionName, transactionID);
30-
return { channelResults: [], review: false };
31-
}
32-
const jchannelResults = await databaseManager.getMemberValues(cacheKey);
33-
spanDBMembers?.end();
34-
35-
const channelResults: ChannelResult[] = jchannelResults.map(
36-
(jchannelResult: { channelResult: ChannelResult }) => jchannelResult.channelResult,
37-
);
38-
39-
let review = false;
40-
for (const configuredChannel of networkMap.messages[0].channels) {
41-
if (configuredChannel) {
42-
const channelRes = channelResults.find((c) => c.id === configuredChannel.id && c.cfg === configuredChannel.cfg);
43-
if (!channelRes) continue;
44-
for (const typology of configuredChannel.typologies) {
45-
const typologyResult = channelRes?.typologyResult.find((t) => t.id === typology.id && t.cfg === typology.cfg);
46-
if (!typologyResult) continue;
47-
if (typologyResult.review) review = true;
48-
}
49-
}
50-
}
51-
52-
// Delete interim cache as transaction processed to fulfilment
53-
await databaseManager.deleteKey(cacheKey);
54-
55-
span?.end();
56-
return { channelResults, review };
57-
} catch (error) {
58-
span?.end();
59-
let innerError;
60-
loggerService.error(error as string, innerError, functionName);
61-
throw error;
62-
}
63-
};
64-
659
export const handleTypologies = async (
6610
transaction: Pacs002,
67-
channel: Channel,
6811
networkMap: NetworkMap,
6912
typologyResult: TypologyResult,
70-
): Promise<{ channelResults: ChannelResult[]; review: boolean }> => {
13+
): Promise<{ typologyResult: TypologyResult[]; review: boolean }> => {
7114
let span;
72-
const startTime = process.hrtime.bigint();
15+
// const startTime = process.hrtime.bigint();
7316
const functionName = 'handleTypologies()';
7417
try {
18+
const typologies = networkMap.messages[0].typologies.filter((t) => t.id === typologyResult.id && t.cfg === typologyResult.cfg);
7519
const transactionID = transaction.FIToFIPmtSts.GrpHdr.MsgId;
76-
const cacheKey = `CADP_${transactionID}_${channel.id}_${channel.cfg}`;
20+
const cacheKey = `TADP_${transactionID}_${typologyResult.id}_${typologyResult.cfg}`;
7721
const jtypologyCount = await databaseManager.addOneGetCount(cacheKey, { typologyResult: { ...typologyResult } });
7822

7923
// check if all results for this Channel is found
80-
if (jtypologyCount && jtypologyCount < channel.typologies.length) {
24+
if (jtypologyCount && jtypologyCount < typologies.length) {
8125
return {
8226
review: false,
83-
channelResults: [],
27+
typologyResult: [],
8428
};
8529
}
8630

@@ -92,47 +36,46 @@ export const handleTypologies = async (
9236
if (!typologyResults || !typologyResults.length)
9337
return {
9438
review: false,
95-
channelResults: [],
39+
typologyResult: [],
9640
};
9741

98-
const channelResult: ChannelResult = {
99-
prcgTm: CalculateDuration(startTime),
100-
result: 0.0,
101-
cfg: channel.cfg,
102-
id: channel.id,
103-
typologyResult: typologyResults,
104-
};
10542
const apmTadProc = apm.startSpan('tadProc.exec');
10643

10744
const message = networkMap.messages.find((tran) => tran.txTp === transaction.TxTp);
10845

10946
if (!message) {
11047
let innerError;
11148
loggerService.error(
112-
`Failed to process Channel ${channel.id} request , Message missing from networkmap.`,
49+
`Failed to process Typology ${typologyResult.id}@${typologyResult.cfg} request , Message missing from networkmap.`,
11350
innerError,
11451
functionName,
11552
transactionID,
11653
);
11754
return {
11855
review: false,
119-
channelResults: [],
56+
typologyResult: [],
12057
};
12158
}
12259

123-
const { channelResults, review } = await handleChannels(message, transaction, networkMap, channelResult);
60+
let review = false;
61+
for (const typology of networkMap.messages[0].typologies) {
62+
const typologyResult = typologyResults.find((t) => t.id === typology.id && t.cfg === typology.cfg);
63+
if (!typologyResult) continue;
64+
if (typologyResult.review) review = true;
65+
}
66+
12467
apmTadProc?.end();
12568

12669
span = apm.startSpan(`[${transactionID}] Delete Channel interim cache key`);
12770
await databaseManager.deleteKey(cacheKey);
12871
span?.end();
129-
return { channelResults, review };
72+
return { typologyResult: typologyResults, review };
13073
} catch (error) {
13174
span?.end();
132-
loggerService.error(`Failed to process Channel ${channel.id} request`, error as Error, functionName);
75+
loggerService.error(`Failed to process Typology ${typologyResult.id}@${typologyResult.cfg} request`, error as Error, functionName);
13376
return {
13477
review: false,
135-
channelResults: [],
78+
typologyResult: [],
13679
};
13780
}
13881
};

src/services/logic.service.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { type TADPResult } from '@frmscoe/frms-coe-lib/lib/interfaces/processor-
1111
import { type TypologyResult } from '@frmscoe/frms-coe-lib/lib/interfaces/processor-files/TypologyResult';
1212
import { type MetaData } from '@frmscoe/frms-coe-lib/lib/interfaces/metaData';
1313

14-
export const handleExecute = async (rawTransaction: any): Promise<any> => {
14+
export const handleExecute = async (rawTransaction: any): Promise<void> => {
1515
const functionName = 'handleExecute()';
1616
let apmTransaction = null;
1717
try {
@@ -35,30 +35,32 @@ export const handleExecute = async (rawTransaction: any): Promise<any> => {
3535
const toReturn: TADPResult = {
3636
id: '',
3737
cfg: '',
38-
channelResult: [],
38+
typologyResult: [],
3939
prcgTm: 0,
4040
};
4141

42-
// Messages is hardcoded at the moment since we only ever have 1. Should we move to include more messages, we will have to revist.
43-
const channel = networkMap.messages[0].channels.filter((c) =>
44-
c.typologies.some((t) => t.id === typologyResult.id && t.cfg === typologyResult.cfg),
45-
)[0];
42+
const typologies = networkMap.messages[0].typologies.filter((t) => t.id === typologyResult.id && t.cfg === typologyResult.cfg);
43+
/* typologies.find()
4644
47-
loggerService.debug(`Processing Channel ${channel.id}.`, functionName, transactionID);
48-
const { channelResults, review } = await handleTypologies(transaction, channel, networkMap, typologyResult);
45+
const typologyResult = channelRes?.typologyResult.find((t) => t.id === typology.id && t.cfg === typology.cfg);
46+
if (!typologyResult) continue;
47+
if (typologyResult.review) review = true; */
4948

50-
if (channelResults.length > 0 && channelResults.length === networkMap.messages[0].channels.length) {
49+
loggerService.debug(`Processing Typology ${typologyResult.id}.`, functionName, transactionID);
50+
const { typologyResult: typologyResults, review } = await handleTypologies(transaction, networkMap, typologyResult);
51+
52+
if (typologyResults.length && typologyResults.length === networkMap.messages[0].typologies.length) {
5153
toReturn.id = networkMap.messages[0].id;
5254
toReturn.cfg = networkMap.messages[0].cfg;
53-
toReturn.channelResult = channelResults;
55+
toReturn.typologyResult = typologyResults;
5456
toReturn.prcgTm = CalculateDuration(startTime);
5557

5658
const alert = new Alert();
5759
alert.tadpResult = toReturn;
5860
alert.status = review ? 'ALRT' : 'NALT';
5961
alert.metaData = metaData;
6062
const result: CMSRequest = {
61-
message: `Successfully completed ${channelResults.length} channels`,
63+
message: `Successfully completed ${typologies.length} typologies`,
6264
report: alert,
6365
transaction,
6466
networkMap,
@@ -71,7 +73,6 @@ export const handleExecute = async (rawTransaction: any): Promise<any> => {
7173
await server.handleResponse(result);
7274
}
7375
apmTransaction?.end();
74-
return channelResults;
7576
} catch (e) {
7677
loggerService.error('Error while calculating Transaction score', e as Error, functionName);
7778
} finally {

0 commit comments

Comments
 (0)