Skip to content

Commit a501873

Browse files
Rupal SinglaRupal Singla
Rupal Singla
authored and
Rupal Singla
committedFeb 11, 2025·
igm2
1 parent c45aec8 commit a501873

File tree

7 files changed

+595
-37
lines changed

7 files changed

+595
-37
lines changed
 

‎constants/index.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,21 @@ export const IGM2Flows ={
370370
FLOW_2: 'FLOW_2',
371371
FLOW_3: 'FLOW_3',
372372
}
373-
export const IGM2apiSequence = {
374-
// ISSUE_1:
373+
export const IGM2Sequence = {
374+
"ISSUE_1": "issue_1",
375+
"ON_ISSUE_1": "on_issue_1",
376+
"ON_ISSUE_2": "on_issue_2",
377+
"ISSUE_2": "issue_2",
378+
"ON_ISSUE_3": "on_issue_3",
379+
"ON_ISSUE_4": "on_issue_4",
380+
"ISSUE_3": "issue_3",
381+
"ON_ISSUE_5": "on_issue_5",
382+
"ON_ISSUE_6": "on_issue_6",
383+
"ISSUE_4": "issue_4",
384+
"ON_ISSUE_7": "on_issue_7",
385+
"ISSUE_5": "issue_5",
375386
}
376387

377-
378388
export const RSFapiSequence = {
379389
RECEIVER_RECON: 'receiver_recon',
380390
ON_RECEIVER_RECON: 'on_receiver_recon',

‎controller/validate/helper.ts

+7-21
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import _ from 'lodash'
22
import { sign, hash } from '../../shared/crypto'
33
import { logger } from '../../shared/logger'
44
import { DOMAIN, ERROR_MESSAGE } from '../../shared/types'
5-
import { IGMvalidateLogs, validateLogs, RSFvalidateLogs, RSFvalidateLogsV2 } from '../../shared/validateLogs'
5+
import { IGMvalidateLogs, validateLogs, RSFvalidateLogs, RSFvalidateLogsV2, IGMvalidateLogs2 } from '../../shared/validateLogs'
66
import { validateLogsForFIS12 } from '../../shared/Actions/FIS12Actions'
77
import { validateLogsForMobility } from '../../shared/Actions/mobilityActions'
88
import { validateLogsForMetro } from '../../shared/Actions/metroActions'
@@ -180,26 +180,8 @@ const validateIGM = async (payload: string, version: string) => {
180180
}
181181

182182
break
183-
184-
default:
185-
message = ERROR_MESSAGE.LOG_VERIFICATION_INVALID_VERSION
186-
logger.warn('Invalid Version!!')
187-
}
188-
189-
190-
191-
return { response, success, message }
192-
}
193-
194-
195-
const validateIGM2 = async (payload: string, version: string) =>
196-
let response
197-
let success = false
198-
let message = ERROR_MESSAGE.LOG_VERIFICATION_UNSUCCESSFUL
199-
200-
switch (version) {
201-
case '2.0.0':
202-
response = IGM2validateLogs(payload)
183+
case '2.0.0':
184+
response = IGMvalidateLogs2(payload)
203185

204186
if (_.isEmpty(response)) {
205187
success = true
@@ -217,6 +199,10 @@ const validateIGM2 = async (payload: string, version: string) =>
217199

218200
return { response, success, message }
219201
}
202+
203+
204+
205+
220206
const validateRSF = async (payload: string, version: string) => {
221207
logger.info('Entering validateRSF function')
222208
let response

‎controller/validate/index.ts

-11
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,6 @@ const controller = {
5656
const { response, success, message } = await helper.validateIGM(payload, version)
5757
result = { response, success, message }
5858
break
59-
case DOMAIN.IGM2:
60-
// eslint-disable-next-line no-case-declarations
61-
const { response, success, message } = await helper.validateIGM2(payload, version)
62-
result = { response, success, message }
63-
break
64-
65-
66-
67-
68-
69-
7059
case DOMAIN.RSF:
7160
{
7261
const { response, success, message } = await helper.validateRSF(payload, version)

‎routes/validate/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const router = express.Router()
66
router.post('/validate', validateController.validate)
77
router.post('/validate/fis', validateController.validate)
88
router.post('/validate/igm', validateController.validate)
9-
router.post('/validate/igm2', validateController.validate)
109
router.post('/validate/trv', validateController.validate)
1110
router.post('/validate-schema', validateController.validateSingleAction)
1211
router.post('/validate/token', validateController.validateToken)

‎shared/validateLogs.ts

+86-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import _ from 'lodash'
22
import { dropDB, setValue } from '../shared/dao'
33
import { logger } from './logger'
4-
import { ApiSequence, retailDomains, IGMApiSequence, RSFapiSequence, RSF_v2_apiSequence } from '../constants'
4+
import { ApiSequence, retailDomains, IGMApiSequence,IGM2Sequence, RSFapiSequence, RSF_v2_apiSequence } from '../constants'
55
import { validateSchema, isObjectEmpty } from '../utils'
66
import { checkOnsearchFullCatalogRefresh } from '../utils/Retail/RET11_onSearch/onSearch'
77
import { checkSelect } from '../utils/Retail/Select/select'
@@ -49,6 +49,8 @@ import checkRsfReport from '../utils/RSF/RSF_v2/report'
4949
import checkRsfOnReport from '../utils/RSF/RSF_v2/on_report'
5050
import checkRsfRecon from '../utils/RSF/RSF_v2/recon'
5151
import checkRsfOnRecon from '../utils/RSF/RSF_v2/on_recon'
52+
import checkIssueV2 from 'utils/igm/igm2/issue'
53+
import checkOnIssueV2 from 'utils/igm/igm2/on_issue'
5254

5355
export const validateLogs = async (data: any, domain: string, flow: string) => {
5456
const msgIdSet = new Set()
@@ -408,6 +410,89 @@ export const IGMvalidateLogs = (data: any) => {
408410
}
409411
}
410412

413+
export const IGMvalidateLogs2 = (data: any) => {
414+
let logReport: any = {}
415+
416+
417+
try {
418+
dropDB()
419+
} catch (error) {
420+
logger.error('!!Error while removing LMDB', error)
421+
}
422+
423+
try {
424+
if (data[IGM2Sequence.ISSUE_1]) {
425+
const issue_1 = checkIssueV2(data[IGM2Sequence.ISSUE_1])
426+
427+
if (!_.isEmpty(issue_1)) {
428+
logReport = { ...logReport, [IGM2Sequence.ISSUE_1]: issue_1 }
429+
}
430+
}
431+
432+
if (data[IGM2Sequence.ON_ISSUE_1]) {
433+
const on_issue_1 = checkOnIssueV2(data[IGM2Sequence.ON_ISSUE_1],IGM2Sequence.ON_ISSUE_1)
434+
435+
if (!_.isEmpty(on_issue_1)) {
436+
logReport = { ...logReport, [IGM2Sequence.ON_ISSUE_1]: on_issue_1 }
437+
}
438+
}
439+
440+
if(data[IGM2Sequence.ON_ISSUE_2]){
441+
const on_issue_2 = checkOnIssueV2(data[IGM2Sequence.ON_ISSUE_2],IGM2Sequence.ON_ISSUE_2 )
442+
443+
if (!_.isEmpty(on_issue_2)) {
444+
logReport = { ...logReport, [IGM2Sequence.ON_ISSUE_1]: on_issue_2 }
445+
}
446+
}
447+
448+
if(data[IGM2Sequence.ISSUE_2]){
449+
const on_issue_2 = checkOnIssueV2(data[IGM2Sequence.ON_ISSUE_2],IGM2Sequence.ISSUE_2 )
450+
451+
if (!_.isEmpty(on_issue_2)) {
452+
logReport = { ...logReport, [IGM2Sequence.ON_ISSUE_1]: on_issue_2 }
453+
}
454+
}
455+
456+
if (data[IGM2Sequence.ON_ISSUE_3]) {
457+
const on_issue_3 = checkOnIssueV2(data[IGM2Sequence.ON_ISSUE_3],IGM2Sequence.ON_ISSUE_3)
458+
459+
if (!_.isEmpty(on_issue_3)) {
460+
logReport = { ...logReport, [IGM2Sequence.ON_ISSUE_3]: on_issue_3 }
461+
}
462+
}
463+
464+
if(data[IGM2Sequence.ON_ISSUE_4]){
465+
const ON_ISSUE_4 = checkOnIssueV2(data[IGM2Sequence.ON_ISSUE_4],IGM2Sequence.ISSUE_4 )
466+
467+
if (!_.isEmpty(ON_ISSUE_4)) {
468+
logReport = { ...logReport, [IGM2Sequence.ON_ISSUE_4]: ON_ISSUE_4}
469+
}
470+
}
471+
472+
if(data[IGM2Sequence.ISSUE_3]){
473+
const ISSUE_3 = checkOnIssueV2(data[IGM2Sequence.ON_ISSUE_3],IGM2Sequence.ISSUE_3 )
474+
475+
if (!_.isEmpty(ISSUE_3)) {
476+
logReport = { ...logReport, [IGM2Sequence.ON_ISSUE_1]: ISSUE_3 }
477+
}
478+
}
479+
480+
if(data[IGM2Sequence.ON_ISSUE_5]){
481+
const on_issue_5 = checkOnIssueV2(data[IGM2Sequence.ON_ISSUE_5],IGM2Sequence.ON_ISSUE_5 )
482+
483+
if (!_.isEmpty(on_issue_5)) {
484+
logReport = { ...logReport, [IGM2Sequence.ON_ISSUE_5]: on_issue_5 }
485+
}
486+
}
487+
488+
logger.info(logReport, 'Report Generated Successfully!!')
489+
return logReport
490+
} catch (error: any) {
491+
logger.error(error.message)
492+
return error.message
493+
}
494+
}
495+
411496
export const RSFvalidateLogs = (data: any) => {
412497
let logReport: any = {}
413498

‎utils/igm/igm2/issue.ts

+296
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
// import _ from 'lodash';
2+
// import { setValue } from '../../../shared/dao';
3+
// import { checkContext, isObjectEmpty } from '../../../utils/index';
4+
// import constants from '../../../constants/index';
5+
// import { validateSchema } from '../../../utils/index';
6+
// import { logger } from '../../../shared/logger';
7+
// import issue_subcategory from '../../issue_subcategories';
8+
// import {
9+
// checkOrganizationNameandDomain,
10+
// compareContextTimeStampAndUpdatedAt,
11+
// compareCreatedAtAndUpdationTime,
12+
// compareUpdatedAtAndContextTimeStamp,
13+
// } from '../igmHelpers';
14+
15+
// const checkIssueV2 = (data: any) => {
16+
// const issueObj: any = {};
17+
// let res: any = {};
18+
19+
// if (!data || isObjectEmpty(data)) {
20+
// return { [constants.RET_ISSUE]: 'JSON cannot be empty' };
21+
// }
22+
23+
// try {
24+
// const issue: any = data;
25+
26+
// try {
27+
// logger.info(`Validating Schema for ${constants.ISSUE_1} API`);
28+
// const vs = validateSchema('igm', constants.ISSUE_1, issue);
29+
// if (vs !== 'error') {
30+
// Object.assign(issueObj, vs);
31+
// }
32+
// } catch (error: any) {
33+
// logger.error(`Schema validation error for /${constants.ISSUE_1}, ${error.stack}`);
34+
// }
35+
36+
// try {
37+
// logger.info(`Checking context for ${constants.ISSUE_1} API`);
38+
// res = checkContext(issue.context, constants.RET_ISSUE);
39+
// if (!res.valid) {
40+
// Object.assign(issueObj, res.ERRORS);
41+
// }
42+
// } catch (error: any) {
43+
// logger.error(`Error checking context for /${constants.ISSUE_1}, ${error.stack}`);
44+
// }
45+
46+
// try {
47+
// logger.info(`Storing necessary context values for /${constants.ISSUE_1}`);
48+
// setValue('igmTxnId', issue.context.transaction_id);
49+
// setValue('igmTmpstmp', issue.context.timestamp);
50+
// setValue('igmCoreVersion', issue.context.core_version);
51+
// setValue('igmDomain', issue.context.domain);
52+
// setValue('igmIssueMsgId', issue.context.message_id);
53+
// setValue('seller_bpp_id', issue.context.bpp_id);
54+
// setValue('seller_bpp_uri', issue.context.bpp_uri);
55+
56+
// if (issue.message) {
57+
// setValue('igmIssueType', issue.message.issue.level);
58+
// }
59+
// } catch (error: any) {
60+
// logger.error(`Error storing context values for /${constants.RET_ISSUE}, ${error.stack}`);
61+
// }
62+
63+
// try {
64+
// logger.info(`Validating issue category and subcategory for /${constants.RET_ISSUE}`);
65+
// if (!issue.message.issue.description || !issue.message.issue.description.code) {
66+
// issueObj.ctgrySubCategory = 'Missing or invalid issue description code';
67+
// }
68+
// } catch (error: any) {
69+
// logger.error(`Error validating issue category and subcategory, ${error.stack}`);
70+
// }
71+
72+
// checkOrganizationNameandDomain({
73+
// endpoint: constants.RET_ISSUE,
74+
// actionPayload: issue.message.issue.actors,
75+
// contextSubscriberId: issue.context.bap_id,
76+
// contextDomain: issue.context.domain,
77+
// issueReportObj: issueObj,
78+
// IdType: 'BAP',
79+
// });
80+
81+
// compareUpdatedAtAndContextTimeStamp({
82+
// endpoint: constants.RET_ISSUE,
83+
// actionPayload: issue.message.issue.actions,
84+
// messageUpdatedAt: issue.message.issue.updated_at,
85+
// issueReportObj: issueObj,
86+
// });
87+
88+
// compareCreatedAtAndUpdationTime({
89+
// endpoint: constants.RET_ISSUE,
90+
// created_at: issue.message.issue.created_at,
91+
// contextTimeStamp: issue.context.timestamp,
92+
// messageUpdatedAt: issue.message.issue.updated_at,
93+
// domain: issue.context.domain,
94+
// issueReportObj: issueObj,
95+
// });
96+
97+
// compareContextTimeStampAndUpdatedAt({
98+
// endpoint: constants.RET_ISSUE,
99+
// contextTimeStamp: issue.context.timestamp,
100+
// issue_updated_at: issue.message.issue.updated_at,
101+
// issueReportObj: issueObj,
102+
// });
103+
104+
// try {
105+
// logger.info(`Checking for mandatory images in issue description`);
106+
// if (!issue.message.issue.description.images || !issue.message.issue.description.images.length) {
107+
// issueObj.mndtryImages = 'Issue description images are mandatory';
108+
// }
109+
// } catch (error: any) {
110+
// logger.error(`Error checking mandatory images, ${error.stack}`);
111+
// }
112+
113+
// try {
114+
// logger.info(`Validating phone numbers for /${constants.ISSUE_1}`);
115+
// const complainantPhone = issue.message.issue.actors.find((actor: any) => actor.id === issue.message.issue.complainant_id)?.info.contact.phone;
116+
// if (!_.inRange(Number(complainantPhone), 1000000000, 99999999999)) {
117+
// issueObj.Phn = `Invalid phone number in complainant info`;
118+
// }
119+
// setValue('igmPhn', complainantPhone);
120+
// } catch (error: any) {
121+
// logger.error(`Error validating phone number, ${error.stack}`);
122+
// }
123+
124+
// setValue('igmCreatedAt', issue.message.issue.created_at);
125+
// return issueObj;
126+
// } catch (err: any) {
127+
// logger.error(`Unexpected error in /${constants.ISSUE_1} API`, err);
128+
// }
129+
// };
130+
131+
// export default checkIssueV2;
132+
import _ from 'lodash'
133+
import { setValue } from '../../../shared/dao'
134+
import { checkContext, isObjectEmpty } from '../../../utils/index'
135+
import constants, { IGMApiSequence } from '../../../constants/index'
136+
import { validateSchema } from '../../../utils/index'
137+
import { logger } from '../../../shared/logger'
138+
import issue_subcategory from '../../issue_subcategories'
139+
// import messages from '../../utils/messages_constants'
140+
import {
141+
checkOrganizationNameandDomain,
142+
compareContextTimeStampAndUpdatedAt,
143+
compareCreatedAtAndUpdationTime,
144+
compareUpdatedAtAndContextTimeStamp,
145+
} from '../igmHelpers'
146+
147+
const checkIssue = (data: any) => {
148+
const issueObj: any = {}
149+
let res: any = {}
150+
151+
if (!data || isObjectEmpty(data)) {
152+
return { [IGMApiSequence.RET_ISSUE]: 'JSON cannot be empty' }
153+
}
154+
155+
try {
156+
const issue: any = data
157+
158+
try {
159+
logger.info(`Validating Schema for ${constants.RET_ISSUE} API`)
160+
const vs = validateSchema('igm', constants.RET_ISSUE, issue)
161+
if (vs != 'error') {
162+
Object.assign(issueObj, vs)
163+
}
164+
} catch (error: any) {
165+
logger.error(`!!Error occurred while performing schema validation for /${constants.RET_ISSUE}, ${error.stack}`)
166+
}
167+
try {
168+
logger.info(`Checking context for ${constants.RET_ISSUE} API`) //checking context
169+
res = checkContext(issue.context, constants.RET_ISSUE)
170+
if (!res.valid) {
171+
Object.assign(issueObj, res.ERRORS)
172+
}
173+
} catch (error: any) {
174+
logger.error(`Some error occurred while checking /${constants.RET_ISSUE} context, ${error.stack}`)
175+
}
176+
177+
try {
178+
logger.info(
179+
`Storing igmTxnID igmTmpstmp igmType igmCoreVersion igmDomain igmIssueMesgId in /${constants.RET_ISSUE}`,
180+
) //storing IgmTxnId IgmTmpstmp igmType igmCoreVersion igmDomain
181+
setValue('igmTxnId', issue.context.transaction_id)
182+
setValue('igmTmpstmp', issue.context.timestamp)
183+
setValue('igmCoreVersion', issue.context.core_version)
184+
setValue('igmDomain', issue.context.domain)
185+
setValue('igmIssueMsgId', issue.context.message_id)
186+
setValue('seller_bpp_id', issue.context.bpp_id)
187+
setValue('seller_bpp_uri', issue.context.bpp_uri)
188+
189+
if (issue.message) {
190+
setValue('igmIssueType', issue.message.issue.issue_type)
191+
}
192+
// msgIdSet.add(issue.context.message_id);
193+
if (!res.valid) {
194+
Object.assign(issueObj, res.ERRORS)
195+
}
196+
} catch (error: any) {
197+
logger.error(`!!Some error occurred while checking /${constants.RET_ISSUE} context, ${error.stack}`)
198+
}
199+
200+
try {
201+
logger.info(`Validating category and subcategory in /${constants.RET_ISSUE}`)
202+
203+
if (
204+
(issue.message.category === 'ITEM' &&
205+
!issue_subcategory.issueItmSubCategories.includes(issue.message.sub_category)) ||
206+
(issue.message.category === 'FULFILLMENT' &&
207+
!issue_subcategory.issueFlmSubcategories.includes(issue.message.sub_category))
208+
) {
209+
issueObj.ctgrySubCategory = `Invalid sub_category ${issue.sub_category} for issue category "${issue.category}"`
210+
}
211+
212+
if (issue.message.issue.category === 'ITEM') {
213+
if (issue.message.issue.order_details.items.length === 0) {
214+
issueObj.items = `Items in issue.message.issue.order_details.items should not be empty when message category is ITEM`
215+
}
216+
}
217+
if (issue.message.issue.category === 'FULFILLMENT') {
218+
if (issue.message.issue.order_details.fulfillments.length === 0) {
219+
issueObj.items = `Fulfillments in issue.message.issue.order_details.fulfillments should not be empty when message category is FULFILLMENT`
220+
}
221+
}
222+
} catch (error: any) {
223+
logger.error(`!!Error while validating category and subcategory in /${constants.RET_ISSUE}, ${error.stack}`)
224+
}
225+
226+
const complainant_actions = issue.message.issue.issue_actions.complainant_actions
227+
228+
checkOrganizationNameandDomain({
229+
endpoint: constants.RET_ISSUE,
230+
actionPayload: complainant_actions,
231+
contextSubscriberId: issue.context.bap_id,
232+
contextDomain: issue.context.domain,
233+
issueReportObj: issueObj,
234+
IdType: 'BAP',
235+
})
236+
237+
compareUpdatedAtAndContextTimeStamp({
238+
endpoint: constants.RET_ISSUE,
239+
actionPayload: complainant_actions,
240+
messageUpdatedAt: issue.message.issue.updated_at,
241+
issueReportObj: issueObj,
242+
})
243+
244+
compareCreatedAtAndUpdationTime({
245+
endpoint: constants.RET_ISSUE,
246+
created_at: issue.message.issue.created_at,
247+
contextTimeStamp: issue.context.timestamp,
248+
messageUpdatedAt: issue.message.issue.updated_at,
249+
domain: issue.context.domain,
250+
issueReportObj: issueObj,
251+
})
252+
253+
compareContextTimeStampAndUpdatedAt({
254+
endpoint: constants.RET_ISSUE,
255+
contextTimeStamp: issue.context.timestamp,
256+
issue_updated_at: issue.message.issue.updated_at,
257+
issueReportObj: issueObj,
258+
})
259+
260+
try {
261+
logger.info(`Checking conditional mandatory images for certain issue sub-categories`)
262+
if (['ITM02', 'ITM03', 'ITM04', 'ITM05', 'FLM04'].includes(issue.sub_category)) {
263+
const has = Object.prototype.hasOwnProperty
264+
if (!has.call(issue.description, 'images') || !issue.description.images.length) {
265+
issueObj.mndtryImages = `issue/description/images are mandatory for issue sub_category ${issue.sub_category}`
266+
}
267+
}
268+
} catch (error: any) {
269+
logger.error(`Error while checking conditional mandatory images for certain issue sub-categories, ${error.stack}`)
270+
}
271+
272+
try {
273+
logger.info(`Phone Number Check for /${constants.RET_ISSUE}`)
274+
// on_issue.message.issue.issue_actions.respondent_actions[0].updated_by.contact.phone
275+
if (!_.inRange(issue.message.issue.complainant_info.contact.phone, 1000000000, 99999999999)) {
276+
issueObj.Phn = `Phone Number for /${constants.RET_ISSUE} api is not in the valid Range`
277+
}
278+
setValue('igmPhn', issue.message.issue.complainant_info.contact.phone)
279+
} catch (error: any) {
280+
logger.error(`Error while checking phone number for /${constants.RET_ISSUE} api, ${error.stack}`)
281+
}
282+
283+
setValue('igmCreatedAt', issue.message.issue.created_at)
284+
285+
//setValue("issueObj", issueObj);
286+
return issueObj
287+
} catch (err: any) {
288+
if (err.code === 'ENOENT') {
289+
logger.info(`!!File not found for /${constants.RET_ISSUE} API!`)
290+
} else {
291+
logger.error(`!!Some error occurred while checking /${constants.RET_ISSUE} API`, err)
292+
}
293+
}
294+
}
295+
296+
export default checkIssue

‎utils/igm/igm2/on_issue.ts

+193
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
// import _ from 'lodash'
2+
// import { setValue, getValue } from '../../../shared/dao'
3+
// import { checkContext, isObjectEmpty } from '../../../utils/index'
4+
// import constants, { IGMApiSequence } from '../../../constants/index'
5+
// import { validateSchema } from '../../../utils/index'
6+
// import { logger } from '../../../shared/logger'
7+
// import {
8+
// checkCreatedAtInAll,
9+
// checkDomainInAll,
10+
// checkOrganizationNameandDomain,
11+
// compareContextTimeStampAndUpdatedAt,
12+
// compareUpdatedAtAndContextTimeStamp,
13+
// } from '.././igmHelpers'
14+
15+
// const checkOnIssueV2 = (data: any,apiSequenceName: string) => {
16+
// const onissueObj: any = {}
17+
// let res: any = {}
18+
19+
// if(apiSequenceName === "ON_ISSUE_1"){
20+
21+
// }
22+
// if(apiSequenceName === "ON_ISSUE_2"){
23+
24+
// }
25+
// }
26+
27+
// export default checkOnIssueV2
28+
29+
30+
import _ from 'lodash'
31+
import { setValue, getValue } from '../../../shared/dao'
32+
import { checkContext, isObjectEmpty } from '../../../utils/index'
33+
import constants, { IGMApiSequence } from '../../../constants/index'
34+
import { validateSchema } from '../../../utils/index'
35+
import { logger } from '../../../shared/logger'
36+
import {
37+
checkCreatedAtInAll,
38+
checkDomainInAll,
39+
checkOrganizationNameandDomain,
40+
compareContextTimeStampAndUpdatedAt,
41+
compareUpdatedAtAndContextTimeStamp,
42+
} from '../igmHelpers'
43+
44+
const checkOnIssue = (data: any,type: string) => {
45+
const onissueObj: any = {}
46+
let res: any = {}
47+
try {
48+
const on_issue: any = data
49+
50+
if (!data || isObjectEmpty(data)) {
51+
return { [IGMApiSequence.RET_ON_ISSUE]: 'JSON cannot be empty' }
52+
}
53+
54+
try {
55+
logger.info(`Validating Schema for ${constants.RET_ONISSUE} API`)
56+
const vs = validateSchema('igm', constants.RET_ONISSUE, on_issue)
57+
if (vs != 'error') {
58+
Object.assign(onissueObj, vs)
59+
}
60+
} catch (error: any) {
61+
logger.error(`!!Error occurred while performing schema validation for /${constants.RET_ONISSUE}, ${error.stack}`)
62+
}
63+
64+
logger.info(`Checking context for ${constants.RET_ONISSUE} API`) //checking context
65+
try {
66+
res = checkContext(on_issue.context, constants.RET_ONISSUE)
67+
if (!res.valid) {
68+
Object.assign(onissueObj, res.ERRORS)
69+
}
70+
} catch (error: any) {
71+
logger.error(`Some error occurred while checking /${constants.RET_ONISSUE} context, ${error.stack}`)
72+
}
73+
74+
try {
75+
logger.info(`Comparing transaction ID of /${constants.RET_ISSUE} and /${constants.RET_ONISSUE}`)
76+
if (!_.isEqual(getValue('igmTxnId'), on_issue.context.transaction_id)) {
77+
onissueObj.igmTxnId = `transaction ID mismatch in /${constants.RET_ISSUE} and /${constants.RET_ONISSUE}`
78+
}
79+
} catch (error: any) {
80+
logger.error(
81+
`Error while comparing transaction ID in /${constants.RET_ISSUE} and /${constants.RET_ONISSUE}, ${error.stack}`,
82+
)
83+
}
84+
85+
try {
86+
logger.info(`Comparing MESSAGE ID of /${constants.RET_ISSUE} and /${constants.RET_ONISSUE}`)
87+
if (!_.isEqual(getValue('igmIssueMsgId'), on_issue.context.message_id)) {
88+
onissueObj.igmIssueMsgId = `Message ID mismatch in /${constants.RET_ISSUE} and /${constants.RET_ONISSUE}`
89+
}
90+
} catch (error: any) {
91+
logger.error(
92+
`Error while comparing Message ID in /${constants.RET_ISSUE} and /${constants.RET_ONISSUE}, ${error.stack}`,
93+
)
94+
}
95+
96+
try {
97+
logger.info(`Comparing Domain of /${constants.RET_ISSUE} and /${constants.RET_ONISSUE}`)
98+
if (!_.isEqual(getValue('igmDomain'), on_issue.context.domain)) {
99+
onissueObj.igmDomain = `Domain for /${constants.RET_ISSUE} api should be equal to /${constants.RET_ONISSUE} api`
100+
}
101+
} catch (error: any) {
102+
logger.error(
103+
`Error while comparing Domain for /${constants.RET_ISSUE} and /${constants.RET_ONISSUE} api, ${error.stack}`,
104+
)
105+
}
106+
107+
try {
108+
logger.info(`Comparing core version of /${constants.RET_ISSUE} and /${constants.RET_ONISSUE}`)
109+
setValue('core_version', on_issue.context.core_version)
110+
} catch (error: any) {
111+
logger.error(
112+
`Error while comparing core version for /${constants.RET_ISSUE} and /${constants.RET_ONISSUE} api, ${error.stack}`,
113+
)
114+
}
115+
116+
try {
117+
logger.info(`Phone Number Check for /${constants.RET_ONISSUE}`)
118+
119+
if (
120+
!_.inRange(
121+
on_issue?.message?.issue?.issue_actions?.respondent_actions?.[0]?.updated_by?.contact?.phone,
122+
1000000000,
123+
99999999999,
124+
)
125+
) {
126+
onissueObj.Phn = `Phone Number for /${constants.RET_ONISSUE} api is not in the valid Range`
127+
}
128+
} catch (error: any) {
129+
logger.error(`Error while checking phone number for /${constants.RET_ONISSUE} api, ${error.stack}`)
130+
}
131+
132+
// try {
133+
// logger.info(
134+
// `Checking time of creation and updation for /${constants.RET_ONISSUE}`
135+
// );
136+
// if (!_.lte(issue.context.timestamp, on_issue.message.issue.created_at)) {
137+
// onissueObj.updatedTime = `Time of Creation for /${constants.RET_ONISSUE} api should be less than context timestamp`;
138+
// }
139+
// } catch (error:any) {
140+
// logger.error(
141+
// `Error while checking time of creation and updation for /${constants.RET_ONISSUE} api, ${error.stack}`
142+
// );
143+
// }
144+
setValue('igmCreatedAt', on_issue.message.issue.created_at)
145+
146+
const respondent_actions = on_issue.message.issue.issue_actions.respondent_actions
147+
148+
checkOrganizationNameandDomain({
149+
endpoint: constants.RET_ONISSUE,
150+
actionPayload: respondent_actions,
151+
contextSubscriberId: on_issue.context.bpp_id,
152+
contextDomain: on_issue.context.domain,
153+
issueReportObj: onissueObj,
154+
IdType: 'BPP',
155+
})
156+
157+
compareUpdatedAtAndContextTimeStamp({
158+
endpoint: constants.RET_ONISSUE,
159+
actionPayload: respondent_actions,
160+
messageUpdatedAt: on_issue.message.issue.updated_at,
161+
issueReportObj: onissueObj,
162+
})
163+
164+
checkCreatedAtInAll({
165+
endpoint: constants.RET_ONISSUE,
166+
created_at: on_issue.message.issue.created_at,
167+
issueReportObj: onissueObj,
168+
})
169+
170+
checkDomainInAll({ endpoint: constants.RET_ONISSUE, domain: on_issue.context.domain, issueReportObj: onissueObj })
171+
172+
compareContextTimeStampAndUpdatedAt({
173+
endpoint: constants.RET_ONISSUE,
174+
contextTimeStamp: on_issue.context.timestamp,
175+
issue_updated_at: on_issue.message.issue.updated_at,
176+
issueReportObj: onissueObj,
177+
})
178+
179+
setValue('onissueObj', onissueObj)
180+
181+
// setValue("onissueObj", onissueObj);
182+
return onissueObj
183+
} catch (err: any) {
184+
if (err.code === 'ENOENT') {
185+
logger.info(`!!File not found for /${constants.RET_ONISSUE} API!`)
186+
} else {
187+
logger.error(`!!Some error occurred while checking /${constants.RET_ONISSUE} API`, err)
188+
}
189+
}
190+
}
191+
192+
export default checkOnIssue
193+

0 commit comments

Comments
 (0)
Please sign in to comment.