Skip to content

Commit

Permalink
Merge pull request #22 from ymaheshwari1/feat/enums
Browse files Browse the repository at this point in the history
Implemented: support to fetch the enums based on parentType
  • Loading branch information
ymaheshwari1 authored Jan 16, 2024
2 parents f043448 + 7875b9a commit 81f76f9
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/services/UtilService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import api from "@/api"

const fetchEnums = async (payload: any): Promise<any> => {
return api({
url: "enums",
method: "GET",
params: payload
});
}

export const UtilService = {
fetchEnums
}
6 changes: 5 additions & 1 deletion src/store/modules/util/UtilState.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Enumeration } from "@/types";

export default interface UtilState {
enums: Array<Enumeration>
enums: {
[key: string]: {
[key: string]: Enumeration
}
}
}
32 changes: 31 additions & 1 deletion src/store/modules/util/actions.ts
Original file line number Diff line number Diff line change
@@ -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<UtilState, RootState> = {}
const actions: ActionTree<UtilState, RootState> = {
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;
2 changes: 1 addition & 1 deletion src/store/modules/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import RootState from "@/store/RootState"
const utilModule: Module<UtilState, RootState> = {
namespaced: true,
state: {
enums: [],
enums: {},
},
getters,
actions,
Expand Down
7 changes: 7 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ type Enumeration = {
sequenceNum: number
}

type EnumerationAndType = Enumeration & {
typeDescription: string,
parentTypeId: string,
hasTable: string
}

type Group = {
routingGroupId: string,
productStoreId: string,
Expand Down Expand Up @@ -46,6 +52,7 @@ type Rule = {

export {
Enumeration,
EnumerationAndType,
Group,
Route,
Rule
Expand Down
5 changes: 3 additions & 2 deletions src/views/BrokeringRuns.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 81f76f9

Please sign in to comment.