Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/hotwax/facilities into faci…
Browse files Browse the repository at this point in the history
…lities/#4
  • Loading branch information
amansinghbais committed Nov 17, 2023
2 parents 360a959 + 0cba592 commit b8d2a72
Show file tree
Hide file tree
Showing 9 changed files with 383 additions and 313 deletions.
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"Facility ID": "Facility ID",
"Facility name": "Facility name",
"Facility Management": "Facility Management",
"Failed to fetch facility information": "Failed to fetch facility information",
"Fetching TimeZones": "Fetching TimeZones",
"Find Facilities": "Find Facilities",
"Friday": "Friday",
Expand Down
4 changes: 2 additions & 2 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import mutations from './mutations'
import getters from './getters'
import actions from './actions'
import RootState from './RootState'
import createPersistedState from "vuex-persistedstate";
import createPersistedState from 'vuex-persistedstate';
import userModule from './modules/user';
import { setPermissions } from '@/authorization'
import facilityModule from "./modules/facility"
import facilityModule from './modules/facility'
import utilModule from "./modules/util"


Expand Down
1 change: 1 addition & 0 deletions src/store/modules/facility/FacilityState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export default interface FacilityState {
list: Array<object>,
total: number
};
current: any;
}
42 changes: 41 additions & 1 deletion src/store/modules/facility/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const actions: ActionTree<FacilityState, RootState> = {
"entityName": "FacilityAndProductStore",
"noConditionFind": "Y",
"distinct": "Y",
"fieldList": ['facilityId', 'facilityName', 'facilityTypeId', 'maximumOrderLimit'],
"fieldList": ['defaultDaysToShip', 'facilityId', 'facilityName', 'facilityTypeId', 'maximumOrderLimit'],
...payload
}

Expand Down Expand Up @@ -90,6 +90,46 @@ const actions: ActionTree<FacilityState, RootState> = {
commit(types.FACILITY_LIST_UPDATED , { facilities, total });
},

async fetchCurrentFacility({ commit, state }, payload) {
// checking that if the list contains basic information for facility then not fetching the same information again
const cachedFacilities = JSON.parse(JSON.stringify(state.facilities.list))
const current = cachedFacilities.find((facility: any) => facility.facilityId === payload.facilityId)
if(current?.facilityId) {
commit(types.FACILITY_CURRENT_UPDATED, current);
return;
}

emitter.emit("presentLoader");

const params = {
inputFields: {
facilityId: payload.facilityId
},
entityName: "FacilityAndProductStore",
noConditionFind: "Y",
distinct: "Y",
fieldList: ['defaultDaysToShip', 'facilityId', 'facilityName', 'facilityTypeId', 'maximumOrderLimit'],
viewSize: 1
}

let facility = {};

try {
const resp = await FacilityService.fetchFacilities(params)

if(!hasError(resp) && resp.data.count > 0) {
facility = resp.data.docs[0]
} else {
throw resp.data
}
} catch(error) {
logger.error(error)
}

emitter.emit("dismissLoader");
commit(types.FACILITY_CURRENT_UPDATED, facility);
},

updateQuery({ commit }, query) {
commit(types.FACILITY_QUERY_UPDATED, query)
},
Expand Down
3 changes: 3 additions & 0 deletions src/store/modules/facility/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ const getters: GetterTree <FacilityState, RootState> = {
state.facilities.list?.length > 0 && state.facilities.list?.length < state.facilities.total
);
},
getCurrent(state) {
return state.current ? JSON.parse(JSON.stringify(state.current)) : {}
}
}
export default getters;
3 changes: 2 additions & 1 deletion src/store/modules/facility/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const facilityModule: Module<FacilityState, RootState> = {
facilities: {
list: [],
total: 0
}
},
current: {}
},
getters,
actions,
Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/facility/mutation-types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const SN_FACILITY = 'facility'
export const FACILITY_LIST_UPDATED = SN_FACILITY + '/LIST_UPDATED'
export const FACILITY_QUERY_UPDATED = SN_FACILITY + '/QUERY_UPDATED'
export const FACILITY_QUERY_UPDATED = SN_FACILITY + '/QUERY_UPDATED'
export const FACILITY_CURRENT_UPDATED = SN_FACILITY + '/CURRENT_UPDATED'
3 changes: 3 additions & 0 deletions src/store/modules/facility/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const mutations: MutationTree <FacilityState> = {
},
[types.FACILITY_QUERY_UPDATED](state, payload) {
state.query = payload
},
[types.FACILITY_CURRENT_UPDATED](state, payload) {
state.current = payload
}
}
export default mutations;
Loading

0 comments on commit b8d2a72

Please sign in to comment.