From 5b0b431498027bb67d8d54b0b7c54833c5c94fac Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Wed, 17 Jan 2024 12:53:27 +0530 Subject: [PATCH 01/16] Implemented: support for fetching the rules for orderRouting(#24) --- src/router/index.ts | 5 +-- src/services/RoutingService.ts | 11 +++++- .../modules/orderRouting/OrderRoutingState.ts | 2 +- src/store/modules/orderRouting/actions.ts | 32 ++++++++++++++++- src/store/modules/orderRouting/getters.ts | 9 ++++- src/store/modules/orderRouting/index.ts | 2 +- .../modules/orderRouting/mutation-types.ts | 2 +- src/store/modules/orderRouting/mutations.ts | 4 +-- src/views/BrokeringQuery.vue | 36 ++++++++++++------- src/views/BrokeringRoute.vue | 7 +++- 10 files changed, 87 insertions(+), 23 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index 163ee06..9b65a9a 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -43,8 +43,9 @@ const routes: Array = [ props: true }, { - path: "brokering/query", - component: () => import("@/views/BrokeringQuery.vue") + path: "brokering/:routingGroupId/:orderRoutingId/rules", + component: () => import("@/views/BrokeringQuery.vue"), + props: true }, { path: "settings", diff --git a/src/services/RoutingService.ts b/src/services/RoutingService.ts index f7d2acf..6336d77 100644 --- a/src/services/RoutingService.ts +++ b/src/services/RoutingService.ts @@ -24,8 +24,17 @@ const fetchOrderRoutings = async (payload: any): Promise => { }); } +const fetchRoutingRules = async (payload: any): Promise => { + return api({ + url: `routings/${payload.orderRoutingId}/rules`, + method: "GET", + query: payload + }); +} + export const OrderRoutingService = { createRoutingGroup, fetchOrderRoutings, - fetchRoutingGroups + fetchRoutingGroups, + fetchRoutingRules } \ No newline at end of file diff --git a/src/store/modules/orderRouting/OrderRoutingState.ts b/src/store/modules/orderRouting/OrderRoutingState.ts index 38e7251..6b19fb2 100644 --- a/src/store/modules/orderRouting/OrderRoutingState.ts +++ b/src/store/modules/orderRouting/OrderRoutingState.ts @@ -1,7 +1,7 @@ export default interface OrderRoutingState { groups: Array; // runs routes: Array; - rule: Array; + rules: Array; currentGroupId: string; currentRouteId: string; } \ No newline at end of file diff --git a/src/store/modules/orderRouting/actions.ts b/src/store/modules/orderRouting/actions.ts index f21c163..15e80e3 100644 --- a/src/store/modules/orderRouting/actions.ts +++ b/src/store/modules/orderRouting/actions.ts @@ -77,7 +77,37 @@ const actions: ActionTree = { } commit(types.ORDER_ROUTINGS_UPDATED, orderRoutings) - } + }, + + async fetchRoutingRules({ commit }, orderRoutingId) { + let routingRules = [] as any; + // filter groups on the basis of productStoreId + const payload = { + orderRoutingId + } + + try { + const resp = await OrderRoutingService.fetchRoutingRules(payload); + + if(!hasError(resp) && resp.data.length) { + routingRules = resp.data + } else { + throw resp.data + } + } catch(err) { + logger.error(err); + } + + if(routingRules.length) { + routingRules = sortSequence(routingRules) + } + + commit(types.ORDER_ROUTING_RULES_UPDATED, routingRules) + }, + + async setCurrentOrderRoutingId({ commit }, payload) { + commit(types.ORDER_ROUTING_CURRENT_ROUTE_UPDATED, payload) + }, } export default actions; \ No newline at end of file diff --git a/src/store/modules/orderRouting/getters.ts b/src/store/modules/orderRouting/getters.ts index 85a27fd..03866c8 100644 --- a/src/store/modules/orderRouting/getters.ts +++ b/src/store/modules/orderRouting/getters.ts @@ -1,7 +1,7 @@ import { GetterTree } from "vuex" import OrderRoutingState from "./OrderRoutingState" import RootState from "@/store/RootState" -import { Group } from "@/types" +import { Group, Route } from "@/types" const getters: GetterTree = { getRoutingGroups(state) { @@ -10,9 +10,16 @@ const getters: GetterTree = { getOrderRoutings(state) { return state.routes }, + getRoutingRules(state) { + return state.rules + }, getCurrentRoutingGroup(state) { const currentRoutingGroup = state.groups?.find((group: Group) => group.routingGroupId === state.currentGroupId) return currentRoutingGroup ? currentRoutingGroup : {} + }, + getCurrentOrderRouting(state) { + const orderRouting = state.routes?.find((route: Route) => route.orderRoutingId === state.currentRouteId) + return orderRouting ? orderRouting : {} } } diff --git a/src/store/modules/orderRouting/index.ts b/src/store/modules/orderRouting/index.ts index 275bf06..f589cf9 100644 --- a/src/store/modules/orderRouting/index.ts +++ b/src/store/modules/orderRouting/index.ts @@ -10,7 +10,7 @@ const orderRoutingModule: Module = { state: { groups: [], routes: [], - rule: [], + rules: [], currentGroupId: '', // choosing only to save id and not whole object, as when updating the state we don't need to care updating the state on two different places currentRouteId: '' }, diff --git a/src/store/modules/orderRouting/mutation-types.ts b/src/store/modules/orderRouting/mutation-types.ts index 4515191..9df8103 100644 --- a/src/store/modules/orderRouting/mutation-types.ts +++ b/src/store/modules/orderRouting/mutation-types.ts @@ -1,6 +1,6 @@ export const SN_ORDER_ROUTING = "orderRouting" export const ORDER_ROUTING_GROUPS_UPDATED = SN_ORDER_ROUTING + "/GROUPS_UPDATED" export const ORDER_ROUTINGS_UPDATED = SN_ORDER_ROUTING + "/ROUTES_UPDATED" -export const ORDER_ROUTING_RULE_UPDATED = SN_ORDER_ROUTING + "/RULE_UPDATED" +export const ORDER_ROUTING_RULES_UPDATED = SN_ORDER_ROUTING + "/RULE_UPDATED" export const ORDER_ROUTING_CURRENT_GROUP_UPDATED = SN_ORDER_ROUTING + "/CURRENT_GROUP_UPDATED" export const ORDER_ROUTING_CURRENT_ROUTE_UPDATED = SN_ORDER_ROUTING + "/CURRENT_ROUTE_UPDATED" \ No newline at end of file diff --git a/src/store/modules/orderRouting/mutations.ts b/src/store/modules/orderRouting/mutations.ts index 1667a59..8f8581c 100644 --- a/src/store/modules/orderRouting/mutations.ts +++ b/src/store/modules/orderRouting/mutations.ts @@ -9,8 +9,8 @@ const mutations: MutationTree = { [types.ORDER_ROUTINGS_UPDATED](state, payload) { state.routes = payload }, - [types.ORDER_ROUTING_RULE_UPDATED](state, payload) { - state.rule = payload + [types.ORDER_ROUTING_RULES_UPDATED](state, payload) { + state.rules = payload }, [types.ORDER_ROUTING_CURRENT_GROUP_UPDATED](state, groupId) { state.currentGroupId = groupId diff --git a/src/views/BrokeringQuery.vue b/src/views/BrokeringQuery.vue index 170af6b..1d1c18a 100644 --- a/src/views/BrokeringQuery.vue +++ b/src/views/BrokeringQuery.vue @@ -4,7 +4,7 @@