Skip to content

Commit

Permalink
Merge pull request #68 from Jagannath-Padhy/master
Browse files Browse the repository at this point in the history
Fixed false errors
  • Loading branch information
sandeepshahi authored May 3, 2024
2 parents 25b40c0 + d1d0e84 commit 05ea1d6
Show file tree
Hide file tree
Showing 16 changed files with 349 additions and 13,177 deletions.
13,066 changes: 0 additions & 13,066 deletions constants/electronics.json

This file was deleted.

4 changes: 2 additions & 2 deletions schema/Retail/Cancel/on_cancel_rto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ export const cancel_RTO_Schema = {
required: ['phone'],
},
},
required:['location','time']
},
end: {
type: 'object',
Expand Down Expand Up @@ -406,7 +407,6 @@ export const cancel_RTO_Schema = {
required: ['start', 'end'],
},
},
required: ['range'],
},
person: {
type: 'object',
Expand Down Expand Up @@ -434,7 +434,7 @@ export const cancel_RTO_Schema = {
required: ['phone'],
},
},
required: ['location', 'time', 'person', 'contact'],
required: ['location', 'time'],
},
tags: {
type: 'array',
Expand Down
6 changes: 3 additions & 3 deletions schema/Retail/RET/on_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const onSearchSchema = {
},
type: {
type: 'string',
enum: ['Delivery', 'Self-Pickup', 'Delivery and Self-Pickup'],
enum: ['Delivery', 'Self-Pickup'],
},
},
required: ['id', 'type'],
Expand Down Expand Up @@ -410,7 +410,7 @@ export const onSearchSchema = {
required: ['gps', 'radius'],
},
},
required: ['id', 'time', 'gps', 'address'],
required: ['id', 'time', 'gps', 'address','time'],
},
},
categories: {
Expand Down Expand Up @@ -586,7 +586,7 @@ export const onSearchSchema = {
},
value: {
type: 'string',
pattern: '^[0-9]+(\.[0-9]{1,2})?$',
pattern: '^[0-9]+(.[0-9]{1,2})?$',
errorMessage: 'Price value should be a number in string with upto 2 decimal places',
},
maximum_value: {
Expand Down
3 changes: 1 addition & 2 deletions schema/Retail/RET/on_search_inc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ export const onSearchIncSchema = {
},
type: {
type: 'string',
enum: ['Self-Pickup','Order','Delivery', 'All'],
errorMessage: "timing for fulfillment type, enum - 'Order' (online order processing timings 'Delivery' (order shipment timings, will be same as delivery timings for hyperlocal), 'Self-Pickup' (self-pickup timings), All",
enum: ['Self-Pickup','Delivery'],
},
},
required: ['id', 'type'],
Expand Down
14 changes: 3 additions & 11 deletions schema/Retail/RET11/on_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const FnBonSearchSchema = {
},
type: {
type: 'string',
enum: ['Delivery', 'Self-Pickup', 'Delivery and Self-Pickup'],
enum: ['Delivery', 'Self-Pickup'],
},
},
required: ['id', 'type'],
Expand Down Expand Up @@ -238,7 +238,7 @@ export const FnBonSearchSchema = {
},
type: {
type: 'string',
enum: ['Delivery', 'Self-Pickup', 'Buyer-Delivery'],
enum: ['Delivery', 'Self-Pickup'],
},
contact: {
type: 'object',
Expand Down Expand Up @@ -327,7 +327,6 @@ export const FnBonSearchSchema = {
},
frequency: {
type: 'string',
format: 'duration',
},
times: {
type: 'array',
Expand Down Expand Up @@ -703,13 +702,6 @@ export const FnBonSearchSchema = {
'price',
'category_id',
'tags',
'@ondc/org/returnable',
'@ondc/org/cancellable',
'@ondc/org/return_window',
'@ondc/org/seller_pickup_return',
'@ondc/org/time_to_ship',
'@ondc/org/available_on_cod',
'@ondc/org/contact_details_consumer_care',
],
},
},
Expand Down Expand Up @@ -835,7 +827,7 @@ export const FnBonSearchSchema = {
enum: ['Self-Pickup', 'Order', 'Delivery', 'All'],
errorMessage:
"timing for fulfillment type, enum - 'Order' (online order processing timings 'Delivery' (order shipment timings, will be same as delivery timings for hyperlocal), 'Self-Pickup' (self-pickup timings)",
},
},
},
required: ['code', 'value'],
},
Expand Down
2 changes: 1 addition & 1 deletion schema/Retail/RET11/on_search_inc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const FnBonSearchIncSchema = {
},
type: {
type: 'string',
enum: ['Delivery', 'Self-Pickup', 'Delivery and Self-Pickup'],
enum: ['Delivery', 'Self-Pickup'],
},
},
required: ['id', 'type'],
Expand Down
2 changes: 1 addition & 1 deletion schema/Retail/Update/on_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export const onUpdateSchema = {
required: ['locality', 'city', 'area_code', 'state'],
},
},
required: ['id', 'gps', 'address'],
required: ['gps', 'address'],
},
time: {
type: 'object',
Expand Down
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
126 changes: 119 additions & 7 deletions utils/Retail/Cancel/onCancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,18 @@ export const checkOnCancel = (data: any, msgIdSet: any) => {
Object.assign(onCnclObj, contextRes.ERRORS)
}

if(flow === '4')
{
if (flow === '4') {
try {
logger.info(`Comparing Message Ids of /${constants.CANCEL} and /${constants.ON_CANCEL}`)
if (!_.isEqual(getValue(`${ApiSequence.CANCEL}_msgId`), context.message_id)) {
onCnclObj[`${ApiSequence.ON_CANCEL}_msgId`] = `Message Ids for /${constants.CANCEL} and /${constants.ON_CANCEL} api should be same`
onCnclObj[`${ApiSequence.ON_CANCEL}_msgId`] = `Message Ids for /${constants.CANCEL} and /${constants.ON_CANCEL} api should be same`
}
} catch (error: any) {
logger.error(`!!Error while checking message id for /${constants.ON_CANCEL}, ${error.stack}`)
}
}

if(flow === '5')
{
if (flow === '5') {
try {
logger.info(`Adding Message Id /${constants.ON_CANCEL}`)
if (msgIdSet.has(context.message_id)) {
Expand Down Expand Up @@ -102,7 +100,7 @@ export const checkOnCancel = (data: any, msgIdSet: any) => {

try {
logger.info(`Comparing timestamp of /${constants.ON_INIT} and /${constants.ON_CANCEL}`)
if (_.gte(getValue('tmpstmp'), context.timestamp)) {
if (_.gte(getValue('onInitTmpstmp'), context.timestamp)) {
onCnclObj.tmpstmp = `Timestamp for /${constants.ON_CONFIRM} api cannot be greater than or equal to /${constants.ON_CANCEL} api`
}

Expand Down Expand Up @@ -165,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 Expand Up @@ -521,7 +612,7 @@ export const checkOnCancel = (data: any, msgIdSet: any) => {
const key = `missingDelivery`
onCnclObj[key] = `Delivery object is mandatory for ${constants.ON_CANCEL}`
} else {

// Checking for start object inside Delivery
if (!_.isEmpty(DELobj[0]?.start)) {
const del_obj_start = DELobj[0]?.start
Expand Down Expand Up @@ -654,6 +745,27 @@ export const checkOnCancel = (data: any, msgIdSet: any) => {
logger.error(`Pre Cancel is mandatory for ${constants.ON_CANCEL}`)
const key = `missingPreCancel`
onCnclObj[key] = `Pre Cancel is mandatory for ${constants.ON_CANCEL}`
} else {
try {
logger.info(`Comparing timestamp of ${flow == '4' ? constants.ON_CONFIRM : constants.ON_STATUS_OUT_FOR_DELIVERY} and /${constants.ON_CANCEL} pre_cancel state updated_at timestamp`)
const timeStampObj = _.filter(preCancelObj[0]?.list, { code: 'updated_at' })
if (!timeStampObj.length) {
logger.error(`Pre Cancel timestamp is mandatory for ${constants.ON_CANCEL}`)
const key = `missingPrecancelUpdatedAttimeStamp`
onCnclObj[key] = `Pre Cancel Updated at timeStamp is mandatory for ${constants.ON_CANCEL}`
}
else {
if (!_.isEqual(getValue('PreviousUpdatedTimestamp'), timeStampObj[0].value)) {
logger.error(`precancel_state.updated_at of ${constants.ON_CANCEL} is not equal with the ${flow == '4' ? constants.ON_CONFIRM : constants.ON_STATUS_OUT_FOR_DELIVERY} order.updated_at`)
const key = `precancelState.updatedAt`
onCnclObj[key] = `precancel_state.updated_at of ${constants.ON_CANCEL} is not equal with the ${flow == '4' ? constants.ON_CONFIRM : constants.ON_STATUS_OUT_FOR_DELIVERY} order.updated_at`
}
}
} catch (error: any) {
logger.error(
`!!Error while comparing timestamp for /${flow == '4' ? constants.ON_CONFIRM : constants.ON_STATUS_OUT_FOR_DELIVERY} and /${constants.ON_CANCEL} api, ${error.stack}`,
)
}
}
}
if (!reasonID_flag) {
Expand Down
2 changes: 2 additions & 0 deletions utils/Retail/Init/onInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export const checkOnInit = (data: any) => {
}

setValue('tmpstmp', context.timestamp)
setValue('onInitTmpstmp', context.timestamp)

} catch (error: any) {
logger.error(
`!!Error while comparing timestamp for /${constants.INIT} and /${constants.ON_INIT} api, ${error.stack}`,
Expand Down
Loading

0 comments on commit 05ea1d6

Please sign in to comment.