From aca5732c397b7bb37f7f7ef1c339aa1a6aa24969 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Fri, 19 Jan 2024 12:17:29 +0530 Subject: [PATCH 1/9] Implemented: support to reorder route at UI level, and created action for updatingRoute and creating a new route --- src/services/RoutingService.ts | 31 +++--- src/store/modules/orderRouting/actions.ts | 114 ++++++++++++++++------ src/types/index.ts | 3 +- src/views/BrokeringRoute.vue | 82 ++++++++++++---- 4 files changed, 165 insertions(+), 65 deletions(-) diff --git a/src/services/RoutingService.ts b/src/services/RoutingService.ts index 27631ba..e0ec91a 100644 --- a/src/services/RoutingService.ts +++ b/src/services/RoutingService.ts @@ -35,6 +35,14 @@ const fetchOrderRoutings = async (payload: any): Promise => { }); } +const updateOrderRouting = async (payload: any): Promise => { + return api({ + url: `routings/${payload.orderRoutingId}`, + method: "POST", + data: payload + }) +} + const createRoutingRule = async (payload: any): Promise => { let routingRuleId = ''; try { @@ -56,23 +64,11 @@ const createRoutingRule = async (payload: any): Promise => { } const createOrderRouting = async (payload: any): Promise => { - let orderRoutingId = ''; - try { - const resp = await api({ - url: "routings", - method: "POST", - data: payload - }) - - if(!hasError(resp) && resp?.data.orderRoutingId) { - orderRoutingId = resp.data.orderRoutingId - } - } catch(err) { - showToast("Failed to create new route") - logger.error(err) - } - - return orderRoutingId + return await api({ + url: "routings", + method: "POST", + data: payload + }) } const fetchRoutingRules = async (payload: any): Promise => { @@ -117,5 +113,6 @@ export const OrderRoutingService = { fetchRoutingRules, fetchRuleActions, fetchRuleConditions, + updateOrderRouting, updateRoutingGroup } \ No newline at end of file diff --git a/src/store/modules/orderRouting/actions.ts b/src/store/modules/orderRouting/actions.ts index 82443cc..0ed1e32 100644 --- a/src/store/modules/orderRouting/actions.ts +++ b/src/store/modules/orderRouting/actions.ts @@ -5,7 +5,7 @@ import { OrderRoutingService } from "@/services/RoutingService" import { hasError, showToast, sortSequence } from "@/utils" import * as types from './mutation-types' import logger from "@/logger" -import { Group, RouteFilter } from "@/types" +import { Group, Route, RouteFilter } from "@/types" const actions: ActionTree = { async fetchOrderRoutingGroups({ commit }) { @@ -50,6 +50,33 @@ const actions: ActionTree = { } }, + async updateRoutingGroup({ commit, state }, payload) { + let routingGroups = JSON.parse(JSON.stringify(state.groups)) + + try { + const resp = await OrderRoutingService.updateRoutingGroup(payload); + + if(!hasError(resp) && resp.data.routingGroupId) { + routingGroups.map((group: Group) => { + if(group.routingGroupId === resp.data.routingGroupId) { + group.description = payload.description + } + }) + showToast("Rounting group information updated") + } else { + throw resp.data + } + } catch(err) { + logger.error(err); + } + + if(routingGroups.length) { + routingGroups = sortSequence(routingGroups) + } + + commit(types.ORDER_ROUTING_GROUPS_UPDATED, routingGroups) + }, + async setCurrentRoutingGroupId({ commit }, payload) { commit(types.ORDER_ROUTING_CURRENT_GROUP_UPDATED, payload) }, @@ -80,6 +107,64 @@ const actions: ActionTree = { commit(types.ORDER_ROUTINGS_UPDATED, orderRoutings) }, + async createOrderRouting({ commit, state }, payload) { + let orderRoutings = JSON.parse(JSON.stringify(state.routes)) + + try { + const resp = await OrderRoutingService.createOrderRouting(payload) + + if(!hasError(resp) && resp?.data.orderRoutingId) { + orderRoutings.push({ + ...payload, + orderRoutingId: resp.data.orderRoutingId + }) + showToast('New Order Routing Created') + } + } catch(err) { + showToast("Failed to create order routing") + logger.error('err', err) + } + + if(orderRoutings.length) { + orderRoutings = sortSequence(orderRoutings) + } + + commit(types.ORDER_ROUTINGS_UPDATED, orderRoutings) + }, + + async updateOrderRouting({ commit, state }, payload) { + let orderRoutings = JSON.parse(JSON.stringify(state.routes)) + const field: Route[keyof Route] = payload.fieldToUpdate + + const params = { + orderRoutingId: payload.orderRoutingId, + [field]: payload.value // only one field can be updated once for orderRouting + } + + try { + const resp = await OrderRoutingService.updateOrderRouting(params); + + if(!hasError(resp) && resp.data.orderRoutingId) { + orderRoutings.map((routing: Route) => { + if(routing.orderRoutingId === resp.data.orderRoutingId) { + routing[field] = payload.value + } + }) + showToast("Order routing information updated") + } else { + throw resp.data + } + } catch(err) { + logger.error(err); + } + + if(orderRoutings.length) { + orderRoutings = sortSequence(orderRoutings) + } + + commit(types.ORDER_ROUTINGS_UPDATED, orderRoutings) + }, + async fetchRoutingRules({ commit }, orderRoutingId) { let routingRules = [] as any; // filter groups on the basis of productStoreId @@ -144,33 +229,6 @@ const actions: ActionTree = { commit(types.ORDER_ROUTING_FILTERS_UPDATED, routingFilters) }, - async updateRoutingGroup({ commit, state }, payload) { - let routingGroups = JSON.parse(JSON.stringify(state.groups)) - - try { - const resp = await OrderRoutingService.updateRoutingGroup(payload); - - if(!hasError(resp) && resp.data.routingGroupId) { - routingGroups.map((group: Group) => { - if(group.routingGroupId === resp.data.routingGroupId) { - group.description = payload.description - } - }) - showToast("Rounting group information updated") - } else { - throw resp.data - } - } catch(err) { - logger.error(err); - } - - if(routingGroups.length) { - routingGroups = sortSequence(routingGroups) - } - - commit(types.ORDER_ROUTING_GROUPS_UPDATED, routingGroups) - }, - async fetchRuleConditions({ commit }, routingRuleId) { let ruleConditions = [] as any; // filter groups on the basis of productStoreId diff --git a/src/types/index.ts b/src/types/index.ts index a216dee..cd12740 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -34,7 +34,8 @@ type Route = { description: string, createdByUser: string, createdDate: string, - lastUpdatedStamp: string + lastUpdatedStamp: string, + [key: string]: string | number } type Rule = { diff --git a/src/views/BrokeringRoute.vue b/src/views/BrokeringRoute.vue index 7dae7e3..d5782ad 100644 --- a/src/views/BrokeringRoute.vue +++ b/src/views/BrokeringRoute.vue @@ -19,21 +19,26 @@ - - - -

{{ routing.routingName }}

-
- {{ `${routing.sequenceNum}/4` }} -
- - {{ routingStatus[routing.statusId]?.desc || routing.statusId }} - - {{ "Archive" }} - - - -
+ + + + +

{{ routing.routingName }}

+
+ + {{ `${routing.sequenceNum}/4` }} + + +
+ + {{ routingStatus[routing.statusId]?.desc || routing.statusId }} + + {{ "Archive" }} + + + +
+
@@ -89,13 +94,12 @@