Skip to content

Commit

Permalink
on_cancel rto and quote trail checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jagannath-Padhy committed May 2, 2024
1 parent 451363a commit 8377ead
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 15 deletions.
25 changes: 13 additions & 12 deletions shared/validateLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import checkRsfOnReceiverRecon from '../utils/RSF/rsfOnReciverRecon'
export const validateLogs = async (data: any, domain: string, flow: string) => {
const msgIdSet = new Set()
const settlementDetatilSet = new Set()
const quoteTrailItemsSet = new Set()
let logReport: any = {}
setValue('flow', flow)
setValue('domain', domain.split(':')[1])
Expand Down Expand Up @@ -228,29 +229,29 @@ export const validateLogs = async (data: any, domain: string, flow: string) => {
case ApiSequence.ON_STATUS_DELIVERED:
return checkOnStatusDelivered(data, 'delivered', msgIdSet)
case ApiSequence.ON_UPDATE_PART_CANCEL:
return checkOnUpdate(data, msgIdSet, ApiSequence.ON_UPDATE_PART_CANCEL,settlementDetatilSet, "6-a")
return checkOnUpdate(data, msgIdSet, ApiSequence.ON_UPDATE_PART_CANCEL, settlementDetatilSet, quoteTrailItemsSet, "6-a")
case ApiSequence.UPDATE_SETTLEMENT_PART_CANCEL:
return checkUpdate(data, msgIdSet, ApiSequence.UPDATE_SETTLEMENT_PART_CANCEL,settlementDetatilSet, '6-a')
return checkUpdate(data, msgIdSet, ApiSequence.UPDATE_SETTLEMENT_PART_CANCEL, settlementDetatilSet, '6-a')
case ApiSequence.UPDATE_REVERSE_QC:
return checkUpdate(data, msgIdSet, ApiSequence.UPDATE_REVERSE_QC,settlementDetatilSet, '6-b')
return checkUpdate(data, msgIdSet, ApiSequence.UPDATE_REVERSE_QC, settlementDetatilSet, '6-b')
case ApiSequence.ON_UPDATE_INTERIM_REVERSE_QC:
return checkOnUpdate(data, msgIdSet, ApiSequence.ON_UPDATE_INTERIM_REVERSE_QC,settlementDetatilSet, '6-b')
return checkOnUpdate(data, msgIdSet, ApiSequence.ON_UPDATE_INTERIM_REVERSE_QC, settlementDetatilSet, quoteTrailItemsSet, '6-b')
case ApiSequence.ON_UPDATE_APPROVAL:
return checkOnUpdate(data, msgIdSet, ApiSequence.ON_UPDATE_APPROVAL,settlementDetatilSet, "6-b")
return checkOnUpdate(data, msgIdSet, ApiSequence.ON_UPDATE_APPROVAL, settlementDetatilSet, quoteTrailItemsSet, "6-b")
case ApiSequence.ON_UPDATE_PICKED:
return checkOnUpdate(data, msgIdSet, ApiSequence.ON_UPDATE_PICKED,settlementDetatilSet, "6-b")
return checkOnUpdate(data, msgIdSet, ApiSequence.ON_UPDATE_PICKED, settlementDetatilSet, quoteTrailItemsSet, "6-b")
case ApiSequence.UPDATE_SETTLEMENT_REVERSE_QC:
return checkUpdate(data, msgIdSet, ApiSequence.UPDATE_SETTLEMENT_REVERSE_QC,settlementDetatilSet, '6-b')
return checkUpdate(data, msgIdSet, ApiSequence.UPDATE_SETTLEMENT_REVERSE_QC, settlementDetatilSet, '6-b')
case ApiSequence.ON_UPDATE_DELIVERED:
return checkOnUpdate(data, msgIdSet, ApiSequence.ON_UPDATE_APPROVAL,settlementDetatilSet, "6-b")
return checkOnUpdate(data, msgIdSet, ApiSequence.ON_UPDATE_APPROVAL, settlementDetatilSet, quoteTrailItemsSet, "6-b")
case ApiSequence.UPDATE_LIQUIDATED:
return checkUpdate(data, msgIdSet, ApiSequence.UPDATE_LIQUIDATED,settlementDetatilSet, '6-c')
return checkUpdate(data, msgIdSet, ApiSequence.UPDATE_LIQUIDATED, settlementDetatilSet, '6-c')
case ApiSequence.ON_UPDATE_INTERIM_LIQUIDATED:
return checkOnUpdate(data, msgIdSet, ApiSequence.ON_UPDATE_INTERIM_LIQUIDATED,settlementDetatilSet, "6-c")
return checkOnUpdate(data, msgIdSet, ApiSequence.ON_UPDATE_INTERIM_LIQUIDATED, settlementDetatilSet, quoteTrailItemsSet, "6-c")
case ApiSequence.ON_UPDATE_LIQUIDATED:
return checkOnUpdate(data, msgIdSet, ApiSequence.ON_UPDATE_LIQUIDATED,settlementDetatilSet, "6-c")
return checkOnUpdate(data, msgIdSet, ApiSequence.ON_UPDATE_LIQUIDATED, settlementDetatilSet, quoteTrailItemsSet, "6-c")
case ApiSequence.UPDATE_SETTLEMENT_LIQUIDATED:
return checkUpdate(data, msgIdSet, ApiSequence.UPDATE_SETTLEMENT_LIQUIDATED,settlementDetatilSet, '6-c')
return checkUpdate(data, msgIdSet, ApiSequence.UPDATE_SETTLEMENT_LIQUIDATED, settlementDetatilSet, '6-c')
case ApiSequence.TRACK:
return checkTrack(data)
case ApiSequence.ON_TRACK:
Expand Down
93 changes: 93 additions & 0 deletions utils/Retail/Cancel/onCancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,99 @@ export const checkOnCancel = (data: any, msgIdSet: any) => {
} catch (error: any) {
logger.error(`Error while checking for fulfillment IDs for /${constants.ON_CANCEL}`, error.stack)
}

if (flow == '5') {
try {
const deliveryFFObj = _.filter(on_cancel.fulfillments, { type: 'Delivery' })
if (deliveryFFObj.length == 0) {
onCnclObj[`deliveryFFObj`] = `fulfillment type delivery is missing in /${constants.ON_CANCEL}`
}
else {
const deliveryFF = deliveryFFObj[0]
const deliveryFFStart = deliveryFF.start
const deliveryFFEnd = deliveryFF.end

function checkFFStartOrEnd(ffStartOrEnd: any, startOrEnd: string) {
if (!ffStartOrEnd) {
onCnclObj[`deliveryFFObj${startOrEnd}`] = `fulfillment type delivery ${startOrEnd.toLowerCase()} is missing in /${constants.ON_CANCEL}`
}
else {
if (_.isEmpty(ffStartOrEnd.location)) {
onCnclObj[`deliveryFFObj/${startOrEnd}/Location`] = `fulfillment type delivery ${startOrEnd.toLowerCase()}/location is missing in /${constants.ON_CANCEL}`
}
if (_.isEmpty(ffStartOrEnd.time)) {
onCnclObj[`deliveryFFObj/${startOrEnd}/time`] = `fulfillment type delivery ${startOrEnd.toLowerCase()}/time is missing in /${constants.ON_CANCEL}`
}
else {
if (_.isEmpty(ffStartOrEnd.time.range)) {
onCnclObj[`deliveryFFObj/${startOrEnd}/Time/Range`] = `fulfillment type delivery ${startOrEnd.toLowerCase()}/time/range is missing in /${constants.ON_CANCEL}`
}
else {
if (!ffStartOrEnd.time.range.start) {
onCnclObj[`deliveryFFObj/${startOrEnd}/Time/Range/Start`] = `fulfillment type delivery ${startOrEnd.toLowerCase()}/time/range/start is missing in /${constants.ON_CANCEL}`
}
else {
const date = new Date(ffStartOrEnd.time.range.start);
if (String(date) == "Invalid Date") {
onCnclObj[`deliveryFFObj/${startOrEnd}/Time/Range/Start`] = `fulfillment type delivery ${startOrEnd.toLowerCase()}/time/range/start is not of a valid date format in /${constants.ON_CANCEL}`
}
}
if (!ffStartOrEnd.time.range.end) {
onCnclObj[`deliveryFFObj/${startOrEnd}/Time/Range/End`] = `fulfillment type delivery ${startOrEnd.toLowerCase()}/time/range/end is missing in /${constants.ON_CANCEL}`
}
else {
const date = new Date(ffStartOrEnd.time.range.end);
if (String(date) == "Invalid Date") {
onCnclObj[`deliveryFFObj/${startOrEnd}/Time/Range/End`] = `fulfillment type delivery ${startOrEnd.toLowerCase()}/time/range/end is not of a valid date format in /${constants.ON_CANCEL}`
}
}
}
}
if (_.isEmpty(ffStartOrEnd.contact)) {
onCnclObj[`deliveryFFObj/${startOrEnd}/Contact`] = `fulfillment type delivery ${startOrEnd.toLowerCase()}/contact is missing in /${constants.ON_CANCEL}`
}
else {
if (!ffStartOrEnd.contact.phone) {
onCnclObj[`deliveryFFObj/${startOrEnd}/Contact/Phone`] = `fulfillment type delivery ${startOrEnd.toLowerCase()}/contact/phone is missing in /${constants.ON_CANCEL}`

}
else if (isNaN(Number(ffStartOrEnd.contact.phone))) {
onCnclObj[`deliveryFFObj/${startOrEnd}/Contact/Phone`] = `fulfillment type delivery ${startOrEnd.toLowerCase()}/contact/phone is not a valid phone_number in /${constants.ON_CANCEL}`

}
if (!ffStartOrEnd.contact.email) {
onCnclObj[`deliveryFFObj/${startOrEnd}/Contact/Email`] = `fulfillment type delivery ${startOrEnd.toLowerCase()}/contact/email is missing in /${constants.ON_CANCEL}`
}
else if (typeof ffStartOrEnd.contact.email != "string") {
onCnclObj[`deliveryFFObj/${startOrEnd}/Contact/Email`] = `fulfillment type delivery ${startOrEnd.toLowerCase()}/contact/email is not a type of string in /${constants.ON_CANCEL}`

}
}
if (startOrEnd == "End") {
if (_.isEmpty(ffStartOrEnd.person)) {
onCnclObj[`deliveryFFObj/${startOrEnd}/Person`] = `fulfillment type delivery ${startOrEnd.toLowerCase()}/person is missing in /${constants.ON_CANCEL}`
}
else {
if (!ffStartOrEnd.person.name) {
onCnclObj[`deliveryFFObj/${startOrEnd}/Person/Name`] = `fulfillment type delivery ${startOrEnd.toLowerCase()}/person/name is missing in /${constants.ON_CANCEL}`
}
else if (typeof ffStartOrEnd.person.name != "string") {
onCnclObj[`deliveryFFObj/${startOrEnd}/Person`] = `fulfillment type delivery ${startOrEnd.toLowerCase()}/person/name is not a type of string in /${constants.ON_CANCEL}`
}
}
}
}
}
checkFFStartOrEnd(deliveryFFStart, "Start")
checkFFStartOrEnd(deliveryFFEnd, "End")
}
}
catch (error: any) {
logger.error(`!!Error while checking fulfillment type delivery in /${constants.ON_CANCEL}, ${error.stack}`)
}
}


//Comparing item count in /on_cancel and /select
const select_items: any = getValue('items')
try {
Expand Down
106 changes: 103 additions & 3 deletions utils/Retail/Update/onUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
return_rejected_request_reasonCodes,
return_request_reasonCodes,
} from '../../../constants/reasonCode'
export const checkOnUpdate = (data: any, msgIdSet: any, apiSeq: any, settlementDetatilSet: any, flow: any) => {
export const checkOnUpdate = (data: any, msgIdSet: any, apiSeq: any, settlementDetatilSet: any, quoteTrailItemsSet: any, flow: any) => {
const onupdtObj: any = {}
const quoteItemSet: any = new Set()
try {
Expand Down Expand Up @@ -265,6 +265,43 @@ export const checkOnUpdate = (data: any, msgIdSet: any, apiSeq: any, settlementD
)
}

// Checking for quoteTrailItems and adding to quoteTrailItemsSet and comparing with the previous calls
try {
let cancelFulfillmentsArray = _.filter(on_update.fulfillments, { type: 'Cancel' })
if (cancelFulfillmentsArray.length != 0) {
const cancelFulfillments = cancelFulfillmentsArray[0]
const quoteTrailItems = cancelFulfillments.tags.filter(
(tag: any) => tag.code == 'quote_trail')
if (quoteTrailItems.length != 0) {
if (apiSeq == ApiSequence.ON_UPDATE_INTERIM_REVERSE_QC) {
quoteTrailItems.forEach((item: any) => {
quoteTrailItemsSet.add(item)
});
}

quoteTrailItemsSet.forEach((obj1: any) => {
const exist = quoteTrailItems.some((obj2: any) => {
return _.isEqual(obj1, obj2)
});
if (!exist) {
onupdtObj[`message/order.fulfillments/Cancel/tags/quote_trail`] = "Missing fulfillments/Cancel/tags/quote_trail as compare to the previous calls"
}
});

}
else {
onupdtObj[`message/order.fulfillments/Cancel/tags/quote_trail`] = `Fulfillments/Cancel/tags/quote_trail is missing in ${apiSeq}`
}
}
else {
onupdtObj[`message/order.fulfillments/Cancel`] = `Fulfillments/Cancel is missing in ${apiSeq}`
}
} catch (error: any) {
logger.error(
`Error occurred while checking for quote_trail in /${apiSeq}`,
)
}

//Reason_id mapping
try {
logger.info(`Reason_id mapping for cancel_request`)
Expand Down Expand Up @@ -359,7 +396,45 @@ export const checkOnUpdate = (data: any, msgIdSet: any, apiSeq: any, settlementD
`Error occuerred while checking for quote_trail price and quote breakup price on /${apiSeq}`,
)
}

// Checking for quoteTrailItems and adding to quoteTrailItemsSet and comparing with the previous calls
try {
let cancelFulfillmentsArray = _.filter(on_update.fulfillments, { type: 'Cancel' })
if (cancelFulfillmentsArray.length != 0) {
const cancelFulfillments = cancelFulfillmentsArray[0]
const quoteTrailItems = cancelFulfillments.tags.filter(
(tag: any) => tag.code == 'quote_trail')
if (quoteTrailItems.length != 0) {
if (apiSeq == ApiSequence.ON_UPDATE_LIQUIDATED) {
quoteTrailItems.forEach((item: any) => {
quoteTrailItemsSet.add(item)
});
}

quoteTrailItemsSet.forEach((obj1: any) => {
const exist = quoteTrailItems.some((obj2: any) => {
return _.isEqual(obj1, obj2)
});
if (!exist) {
onupdtObj[`message/order.fulfillments/Cancel/tags/quote_trail`] = "Missing fulfillments/Cancel/tags/quote_trail as compare to the previous calls"
}
});
}
else {
onupdtObj[`message/order.fulfillments/Cancel/tags/quote_trail`] = `Fulfillments/Cancel/tags/quote_trail is missing in ${apiSeq}`
}
}
else {
onupdtObj[`message/order.fulfillments/Cancel`] = `Fulfillments/Cancel is missing in ${apiSeq}`
}

} catch (error: any) {
logger.error(
`Error occurred while checking for quote_trail in /${apiSeq}`,
)
}
}

try {
logger.info(`Checking for the availability of initiated_by code in ${apiSeq}`)
const fulfillments = on_update.fulfillments
Expand Down Expand Up @@ -402,7 +477,7 @@ export const checkOnUpdate = (data: any, msgIdSet: any, apiSeq: any, settlementD
logger.error(`Error while setting cancelFulfillmentID in /${apiSeq}`)
}

// Checking for quote_trail price and item quote price
// Checking for quote_trail price and item quote price and adding
try {
if (sumQuoteBreakUp(on_update.quote)) {
const price = Number(on_update.quote.price.value)
Expand All @@ -417,7 +492,32 @@ export const checkOnUpdate = (data: any, msgIdSet: any, apiSeq: any, settlementD
}
} catch (error: any) {
logger.error(
`Error occuerred while checking for quote_trail price and quote breakup price on /${apiSeq}`,
`Error occurred while checking for quote_trail price and quote breakup price on /${apiSeq}`,
)
}

// Checking for quoteTrailItems and adding to quoteTrailItemsSet
try {
let cancelFulfillmentsArray = _.filter(on_update.fulfillments, { type: 'Cancel' })
if (cancelFulfillmentsArray.length != 0) {
const cancelFulfillments = cancelFulfillmentsArray[0]
const quoteTrailItems = cancelFulfillments.tags.filter(
(tag: any) => tag.code == 'quote_trail')
if (quoteTrailItems.length != 0) {
quoteTrailItems.forEach((item: any) => {
quoteTrailItemsSet.add(item)
});
}
else {
onupdtObj[`message/order.fulfillments/Cancel/tags/quote_trail`] = `Fulfillments/Cancel/tags/quote_trail is missing in ${apiSeq}`
}
}
else {
onupdtObj[`message/order.fulfillments/Cancel`] = `Fulfillments/Cancel is missing in ${apiSeq}`
}
} catch (error: any) {
logger.error(
`Error occurred while checking for quote_trail in /${apiSeq}`,
)
}

Expand Down

0 comments on commit 8377ead

Please sign in to comment.