@@ -7,14 +7,20 @@ import { type ChannelResult } from '@frmscoe/frms-coe-lib/lib/interfaces/process
77import { type TypologyResult } from '@frmscoe/frms-coe-lib/lib/interfaces/processor-files/TypologyResult' ;
88import { databaseManager , loggerService } from '..' ;
99import 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
1218export 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- } ;
0 commit comments