Skip to content

Commit 3ccf8a6

Browse files
authored
refactor: file structure organization (#106)
1 parent 6c4f23f commit 3ccf8a6

6 files changed

+47
-44
lines changed

__tests__/unit/app.eventFlow.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
handleRefreshCache,
1010
handleUpdateExpiryDateForConditionsOfAccount,
1111
handleUpdateExpiryDateForConditionsOfEntity,
12-
} from '../../src/logic.service';
12+
} from '../../src/services/event-flow.logic.service';
1313
import {
1414
accountResponse,
1515
entityResponse,

__tests__/unit/app.report.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22
import { unwrap } from '@tazama-lf/frms-coe-lib/lib/helpers/unwrap';
33
import { databaseManager, loggerService } from '../../src';
4-
import { handleGetReportRequestByMsgId } from '../../src/logic.service';
4+
import { handleGetReportRequestByMsgId } from '../../src/services/report.logic.service';
55

66
jest.mock('@tazama-lf/frms-coe-lib', () => {
77
const original = jest.requireActual('@tazama-lf/frms-coe-lib');

jest.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const config: Config.InitialOptions = {
2525

2626
// An array of glob patterns indicating a set of files for which coverage information should be collected
2727
// collectCoverageFrom: ['src/app.controller.ts'],
28-
collectCoverageFrom: ['src/logic.service.ts'],
28+
collectCoverageFrom: ['src/services/**'],
2929

3030
// The directory where Jest should output its coverage files
3131
coverageDirectory: '<rootDir>/coverage/',

src/app.controller.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
// SPDX-License-Identifier: Apache-2.0
22

3+
import { type AccountCondition, type EntityCondition } from '@tazama-lf/frms-coe-lib/lib/interfaces';
4+
import { type FastifyReply, type FastifyRequest } from 'fastify';
5+
import { loggerService } from '.';
6+
import { configuration } from './config';
7+
import { type ConditionRequest } from './interface/query';
38
import {
9+
handleGetConditionsForAccount,
410
handleGetConditionsForEntity,
5-
handleGetReportRequestByMsgId,
6-
handlePostConditionEntity,
711
handlePostConditionAccount,
8-
handleGetConditionsForAccount,
12+
handlePostConditionEntity,
13+
handleRefreshCache,
914
handleUpdateExpiryDateForConditionsOfAccount,
1015
handleUpdateExpiryDateForConditionsOfEntity,
11-
handleRefreshCache,
12-
} from './logic.service';
13-
import { type FastifyRequest, type FastifyReply } from 'fastify';
14-
import { loggerService } from '.';
15-
import { type ConditionRequest } from './interface/query';
16-
import { type AccountCondition, type EntityCondition } from '@tazama-lf/frms-coe-lib/lib/interfaces';
17-
import { configuration } from './config';
16+
} from './services/event-flow.logic.service';
17+
import { handleGetReportRequestByMsgId } from './services/report.logic.service';
1818
export const reportRequestHandler = async (req: FastifyRequest, reply: FastifyReply): Promise<void> => {
1919
loggerService.log('Start - Handle report request');
2020
try {

src/logic.service.ts src/services/event-flow.logic.service.ts

+9-31
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
// SPDX-License-Identifier: Apache-2.0
2+
import { createSimpleConditionsBuffer } from '@tazama-lf/frms-coe-lib/lib/helpers/protobuf';
23
import { unwrap } from '@tazama-lf/frms-coe-lib/lib/helpers/unwrap';
34
import { type AccountCondition, type ConditionEdge, type EntityCondition } from '@tazama-lf/frms-coe-lib/lib/interfaces';
45
import {
56
type AccountConditionResponse,
67
type EntityConditionResponse,
78
} from '@tazama-lf/frms-coe-lib/lib/interfaces/event-flow/ConditionDetails';
89
import {
9-
type Entity,
1010
type Account,
11+
type Entity,
1112
type RawConditionResponse,
1213
} from '@tazama-lf/frms-coe-lib/lib/interfaces/event-flow/EntityConditionEdge';
13-
import { databaseManager, loggerService } from '.';
14-
import { configuration } from './config';
15-
import { type ConditionRequest } from './interface/query';
16-
import { type Report } from './interface/report.interface';
17-
import { checkConditionValidity, validateAndParseExpirationDate } from './utils/condition-validation';
18-
import { filterConditions } from './utils/filter-active-conditions';
19-
import { parseConditionAccount, parseConditionEntity } from './utils/parse-condition';
20-
import { updateCache } from './utils/update-cache';
21-
import { createSimpleConditionsBuffer } from '@tazama-lf/frms-coe-lib/lib/helpers/protobuf';
14+
import { databaseManager, loggerService } from '..';
15+
import { configuration } from '../config';
16+
import { type ConditionRequest } from '../interface/query';
17+
import { checkConditionValidity, validateAndParseExpirationDate } from '../utils/condition-validation';
18+
import { filterConditions } from '../utils/filter-active-conditions';
19+
import { parseConditionAccount, parseConditionEntity } from '../utils/parse-condition';
20+
import { updateCache } from '../utils/update-cache';
2221

2322
const saveConditionEdges = async (
2423
perspective: string,
@@ -60,27 +59,6 @@ const saveConditionEdges = async (
6059
}
6160
};
6261

63-
export const handleGetReportRequestByMsgId = async (msgid: string): Promise<Report | undefined> => {
64-
let unWrappedReport;
65-
try {
66-
loggerService.log(`Started handling get request by message id the message id is ${msgid}`);
67-
68-
const report = (await databaseManager.getReportByMessageId('transactions', msgid)) as Report[][];
69-
70-
unWrappedReport = unwrap<Report>(report);
71-
} catch (error) {
72-
const errorMessage = error as { message: string };
73-
loggerService.log(
74-
`Failed fetching report from database service with error message: ${errorMessage.message}`,
75-
'handleGetReportRequestByMsgId()',
76-
);
77-
throw new Error(errorMessage.message);
78-
} finally {
79-
loggerService.log('Completed handling get report by message id');
80-
}
81-
return unWrappedReport;
82-
};
83-
8462
export const handlePostConditionEntity = async (
8563
condition: EntityCondition,
8664
): Promise<{ message: string; result: EntityConditionResponse }> => {

src/services/report.logic.service.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
import { unwrap } from '@tazama-lf/frms-coe-lib/lib/helpers/unwrap';
3+
import { databaseManager, loggerService } from '..';
4+
import { type Report } from '../interface/report.interface';
5+
6+
export const handleGetReportRequestByMsgId = async (msgid: string): Promise<Report | undefined> => {
7+
let unWrappedReport;
8+
try {
9+
loggerService.log(`Started handling get request by message id the message id is ${msgid}`);
10+
11+
const report = (await databaseManager.getReportByMessageId('transactions', msgid)) as Report[][];
12+
13+
unWrappedReport = unwrap<Report>(report);
14+
} catch (error) {
15+
const errorMessage = error as { message: string };
16+
loggerService.log(
17+
`Failed fetching report from database service with error message: ${errorMessage.message}`,
18+
'handleGetReportRequestByMsgId()',
19+
);
20+
throw new Error(errorMessage.message);
21+
} finally {
22+
loggerService.log('Completed handling get report by message id');
23+
}
24+
return unWrappedReport;
25+
};

0 commit comments

Comments
 (0)