Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Implemented support to use oms package for stock specific actions and added typings for stock(#85zrjb2n9) #102

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@capacitor/core": "^2.4.7",
"@capacitor/ios": "^2.5.0",
"@hotwax/apps-theme": "^1.1.0",
"@hotwax/oms-api": "^1.3.0",
"@ionic/core": "6.2.9",
"@ionic/vue": "6.2.9",
"@ionic/vue-router": "6.2.9",
Expand Down
13 changes: 12 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import OfflineHelper from "./offline-helper"
import { useStore } from "./store";
import emitter from "@/event-bus"
import { loadingController } from '@ionic/vue';
import { init, resetConfig } from '@/adapter'
import { mapGetters } from 'vuex'

export default defineComponent({
name: "App",
Expand All @@ -33,7 +35,8 @@ export default defineComponent({
},
data() {
return {
loader: null as any
loader: null as any,
maxAge: process.env.VUE_APP_CACHE_MAX_AGE ? parseInt(process.env.VUE_APP_CACHE_MAX_AGE) : 0
}
},
methods: {
Expand Down Expand Up @@ -64,10 +67,18 @@ export default defineComponent({
});
emitter.on('presentLoader', this.presentLoader);
emitter.on('dismissLoader', this.dismissLoader);
init(this.userToken, this.instanceUrl, this.maxAge)
},
unmounted() {
emitter.off('presentLoader', this.presentLoader);
emitter.off('dismissLoader', this.dismissLoader);
resetConfig();
},
computed: {
...mapGetters({
userToken: 'user/getUserToken',
instanceUrl: 'user/getInstanceUrl'
})
},
setup() {
const store = useStore();
Expand Down
11 changes: 11 additions & 0 deletions src/adapter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { fetchProductsStockAtFacility, init, resetConfig, Response, Stock, updateInstanceUrl, updateToken } from '@hotwax/oms-api'

export {
fetchProductsStockAtFacility,
init,
resetConfig,
Response,
Stock,
updateInstanceUrl,
updateToken
}
19 changes: 8 additions & 11 deletions src/store/modules/stock/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import RootState from '@/store/RootState'
import StockState from './StockState'
import * as types from './mutation-types'
import { hasError } from '@/utils'
import { fetchProductsStockAtFacility, Response, Stock } from '@/adapter'

const actions: ActionTree<StockState, RootState> = {

/**
* Add stocks of specific product
*/
// TODO: remove this action as not used
async addProduct ( { commit }, { productId }) {
const resp: any = await StockService.checkInventory({ productId });
if (resp.status === 200) {
Expand All @@ -24,17 +26,12 @@ const actions: ActionTree<StockState, RootState> = {
// There is a limitation at API level to handle only 100 records
// but as we will always fetch data for the fetched records which will be as per the viewSize
// assuming that the value will never be 100 to show
const resp: any = await StockService.checkInventory({
"viewSize": productIds.length,
"filters": {
"productId": productIds,
"productId_op": "in",
},
"fieldsToSelect": ["productId","atp"],
});
if (resp.status === 200 && !hasError(resp)) {
// Handled empty response in case of failed query
if (resp.data) commit(types.STOCK_ADD_PRODUCTS, { products: resp.data.docs })

try {
const resp: Array<Stock> | Response = await fetchProductsStockAtFacility(productIds);
commit(types.STOCK_ADD_PRODUCTS, resp)
} catch(err: Response) {
console.error(err.message)
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/store/modules/stock/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { MutationTree } from 'vuex'
import StockState from './StockState'
import * as types from './mutation-types'
import { Stock } from '@/adapter'

const mutations: MutationTree <StockState> = {
[types.STOCK_ADD_PRODUCT] (state, payload) {
state.products[payload.productId] = payload.stock
},
[types.STOCK_ADD_PRODUCTS] (state, payload) {
// TODO
payload.products.forEach((product: any) => {
state.products[product.productId] = product.atp
payload.forEach((productStock: Stock) => {
state.products[productStock.productId] = productStock.availableToPromiseTotal
});
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as types from './mutation-types'
import { hasError, showToast } from '@/utils'
import { translate } from '@/i18n'
import "moment-timezone";
import { resetConfig, updateInstanceUrl, updateToken } from '@/adapter'

const actions: ActionTree<UserState, RootState> = {

Expand All @@ -31,6 +32,7 @@ const actions: ActionTree<UserState, RootState> = {

if (checkPermissionResponse.status === 200 && !hasError(checkPermissionResponse) && checkPermissionResponse.data && checkPermissionResponse.data.hasPermission) {
commit(types.USER_TOKEN_CHANGED, { newToken: resp.data.token })
updateToken(resp.data.token)
dispatch('getProfile')
if (resp.data._EVENT_MESSAGE_ && resp.data._EVENT_MESSAGE_.startsWith("Alert:")) {
// TODO Internationalise text
Expand All @@ -45,6 +47,7 @@ const actions: ActionTree<UserState, RootState> = {
}
} else {
commit(types.USER_TOKEN_CHANGED, { newToken: resp.data.token })
updateToken(resp.data.token)
dispatch('getProfile')
return resp.data;
}
Expand Down Expand Up @@ -72,7 +75,7 @@ const actions: ActionTree<UserState, RootState> = {
async logout ({ commit }) {
// TODO add any other tasks if need
commit(types.USER_END_SESSION)

resetConfig()
},

/**
Expand Down Expand Up @@ -157,6 +160,7 @@ const actions: ActionTree<UserState, RootState> = {
*/
setUserInstanceUrl ({ commit }, payload){
commit(types.USER_INSTANCE_URL_UPDATED, payload)
updateInstanceUrl(payload)
},
}
export default actions;