From 7875b9a6493bdd6f89c3769a26c522f27095662c Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Tue, 16 Jan 2024 18:31:44 +0530 Subject: [PATCH] Implemented: support to fetch the enums based on parentType Fetching enums with parentType ORDER_ROUTING Improved type for enums state Fetching enums on the initial load of runs page --- src/services/UtilService.ts | 13 ++++++++++++ src/store/modules/util/UtilState.ts | 6 +++++- src/store/modules/util/actions.ts | 32 ++++++++++++++++++++++++++++- src/store/modules/util/index.ts | 2 +- src/types/index.ts | 7 +++++++ src/views/BrokeringRuns.vue | 5 +++-- 6 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 src/services/UtilService.ts diff --git a/src/services/UtilService.ts b/src/services/UtilService.ts new file mode 100644 index 0000000..0a59366 --- /dev/null +++ b/src/services/UtilService.ts @@ -0,0 +1,13 @@ +import api from "@/api" + +const fetchEnums = async (payload: any): Promise => { + return api({ + url: "enums", + method: "GET", + params: payload + }); +} + +export const UtilService = { + fetchEnums +} \ No newline at end of file diff --git a/src/store/modules/util/UtilState.ts b/src/store/modules/util/UtilState.ts index 0533ce1..60076be 100644 --- a/src/store/modules/util/UtilState.ts +++ b/src/store/modules/util/UtilState.ts @@ -1,5 +1,9 @@ import { Enumeration } from "@/types"; export default interface UtilState { - enums: Array + enums: { + [key: string]: { + [key: string]: Enumeration + } + } } \ No newline at end of file diff --git a/src/store/modules/util/actions.ts b/src/store/modules/util/actions.ts index f6b52d1..0445f74 100644 --- a/src/store/modules/util/actions.ts +++ b/src/store/modules/util/actions.ts @@ -1,7 +1,37 @@ import { ActionTree } from "vuex" import RootState from "@/store/RootState" import UtilState from "./UtilState" +import logger from "@/logger" +import { hasError } from "@/utils" +import * as types from "./mutation-types" +import { UtilService } from "@/services/UtilService" +import { EnumerationAndType } from "@/types" -const actions: ActionTree = {} +const actions: ActionTree = { + async fetchEnums({ commit }, payload) { + let enums = {} + + try { + const resp = await UtilService.fetchEnums(payload); + + if(!hasError(resp) && resp.data.length) { + enums = resp.data.reduce((enumerations: any, data: EnumerationAndType) => { + if(enumerations[data.enumTypeId]) { + enumerations[data.enumTypeId][data.enumId] = data + } else { + enumerations[data.enumTypeId] = { + [data.enumId]: data + } + } + return enumerations + }, {}) + } + } catch(err) { + logger.error('error', err) + } + + commit(types.UTIL_ENUMS_UPDATED, enums) + } +} export default actions; \ No newline at end of file diff --git a/src/store/modules/util/index.ts b/src/store/modules/util/index.ts index 5318251..6ca9e4a 100644 --- a/src/store/modules/util/index.ts +++ b/src/store/modules/util/index.ts @@ -8,7 +8,7 @@ import RootState from "@/store/RootState" const utilModule: Module = { namespaced: true, state: { - enums: [], + enums: {}, }, getters, actions, diff --git a/src/types/index.ts b/src/types/index.ts index 3d40a57..b314955 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -8,6 +8,12 @@ type Enumeration = { sequenceNum: number } +type EnumerationAndType = Enumeration & { + typeDescription: string, + parentTypeId: string, + hasTable: string +} + type Group = { routingGroupId: string, productStoreId: string, @@ -46,6 +52,7 @@ type Rule = { export { Enumeration, + EnumerationAndType, Group, Route, Rule diff --git a/src/views/BrokeringRuns.vue b/src/views/BrokeringRuns.vue index 7b7ba0c..4569fd3 100644 --- a/src/views/BrokeringRuns.vue +++ b/src/views/BrokeringRuns.vue @@ -54,10 +54,11 @@ import { useStore } from "vuex"; const store = useStore() const router = useRouter() -const groups = computed(() => store.getters['orderRouting/getRoutingGroups']) +const groups = computed(() => store.getters["orderRouting/getRoutingGroups"]) onIonViewWillEnter(async () => { - await store.dispatch('orderRouting/fetchOrderRoutingGroups'); + await store.dispatch("orderRouting/fetchOrderRoutingGroups"); + store.dispatch("util/fetchEnums", { parentTypeId: "ORDER_ROUTING" }) }) async function addNewRun() {