From 605d709495d707a6c060616598455d506dc085df Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Wed, 13 Nov 2024 15:09:36 +0530 Subject: [PATCH] Improved: code to fetch all rejection reasons if no entity found for fetching bopis group reasons (#438) --- src/store/modules/util/actions.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/store/modules/util/actions.ts b/src/store/modules/util/actions.ts index 90e76fe0..200bdd2e 100644 --- a/src/store/modules/util/actions.ts +++ b/src/store/modules/util/actions.ts @@ -11,6 +11,7 @@ const actions: ActionTree = { 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 = { @@ -53,6 +54,33 @@ const actions: ActionTree = { } } 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)