Skip to content

Commit

Permalink
Improved: code to fetch all rejection reasons if no entity found for …
Browse files Browse the repository at this point in the history
…fetching bopis group reasons (#438)
  • Loading branch information
amansinghbais committed Nov 13, 2024
1 parent 4512aa2 commit 605d709
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/store/modules/util/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const actions: ActionTree<UtilState, RootState> = {
async fetchRejectReasons({ commit }) {
const permissions = store.getters['user/getUserPermissions'];
const isAdminUser = permissions.some((permission: any) => permission.action === "APP_STOREFULFILLMENT_ADMIN")
let isAdminReasonsNeeded = false;

let rejectReasons = [];
let payload = {
Expand Down Expand Up @@ -53,6 +54,33 @@ const actions: ActionTree<UtilState, RootState> = {
}
} catch (err) {
logger.error('Failed to fetch reject reasons', err)
if(!isAdminUser) isAdminReasonsNeeded = true;
}

// Refetching all rejection reasons if the api fails to fetch bopis rejection reason due to no entity found.
// Todo: revert these changes when all the oms are updated.
if(isAdminReasonsNeeded) {
try {
const resp = await UtilService.fetchRejectReasons({
"inputFields": {
"parentEnumTypeId": ["REPORT_AN_ISSUE", "RPRT_NO_VAR_LOG"],
"parentEnumTypeId_op": "in"
},
"fieldList": ["enumId", "description"],
"entityName": "EnumTypeChildAndEnum",
"distinct": "Y",
"viewSize": 100,
"orderBy": "sequenceNum"
})

if(!hasError(resp)) {
rejectReasons = resp.data.docs
} else {
throw resp.data;
}
} catch(err) {
logger.error('Failed to fetch reject reasons', err)
}
}

commit(types.UTIL_REJECT_REASONS_UPDATED, rejectReasons)
Expand Down

0 comments on commit 605d709

Please sign in to comment.