orderiom-api-package 0.2.46 → 0.2.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/modules/auth.js +16 -8
- package/src/modules/order.js +42 -0
package/package.json
CHANGED
package/src/modules/auth.js
CHANGED
|
@@ -22,6 +22,12 @@ const mutations = {
|
|
|
22
22
|
storeUser(state, userData) {
|
|
23
23
|
state.user = userData
|
|
24
24
|
},
|
|
25
|
+
updateUser(state, userData){
|
|
26
|
+
state.user = {
|
|
27
|
+
...state.user,
|
|
28
|
+
...userData
|
|
29
|
+
};
|
|
30
|
+
},
|
|
25
31
|
clearAuthData(state) {
|
|
26
32
|
state.privateToken = null;
|
|
27
33
|
state.expires_at = null;
|
|
@@ -544,29 +550,31 @@ const actions = {
|
|
|
544
550
|
});
|
|
545
551
|
|
|
546
552
|
},
|
|
547
|
-
update({ }, userData) {
|
|
553
|
+
update({ commit }, userData) {
|
|
548
554
|
return axios.post('api/auth/user/update', null, {
|
|
549
555
|
params: userData
|
|
550
|
-
}).then(
|
|
556
|
+
}).then(result => {
|
|
557
|
+
commit('updateUser', {
|
|
558
|
+
...userData,
|
|
559
|
+
updated_at: new Date().toISOString() // has a little difference with server
|
|
560
|
+
});
|
|
551
561
|
return {
|
|
552
562
|
type: 'success',
|
|
553
563
|
msg: result.data.message.body
|
|
554
564
|
}
|
|
555
|
-
}).catch(
|
|
565
|
+
}).catch(error => {
|
|
556
566
|
if (error.response) {
|
|
557
|
-
|
|
567
|
+
const status = error.response.status;
|
|
568
|
+
if (status === 422) {
|
|
558
569
|
return {
|
|
559
570
|
type: 'error',
|
|
560
571
|
msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
|
|
561
|
-
|
|
562
572
|
}
|
|
563
573
|
}
|
|
564
|
-
if (
|
|
565
|
-
|
|
574
|
+
if ([401, 403, 404, 400].includes(status)) {
|
|
566
575
|
return {
|
|
567
576
|
type: 'error',
|
|
568
577
|
msg: error.response.data.message.body
|
|
569
|
-
|
|
570
578
|
}
|
|
571
579
|
}
|
|
572
580
|
|
package/src/modules/order.js
CHANGED
|
@@ -113,6 +113,48 @@ const actions = {
|
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
115
|
},
|
|
116
|
+
createBasketFromOrder({ dispatch }, data) {
|
|
117
|
+
const basketData = JSON.parse(localStorage.getItem("basket") || "[]");
|
|
118
|
+
return axios
|
|
119
|
+
.post("api/order/create-basket", data)
|
|
120
|
+
.then(async res => {
|
|
121
|
+
basketData.push({
|
|
122
|
+
restaurantId: restaurantId,
|
|
123
|
+
basketId: res.data.data.id,
|
|
124
|
+
});
|
|
125
|
+
localStorage.setItem("basket", JSON.stringify(basketData));
|
|
126
|
+
const result = await dispatch('product/getBasket', restaurantId, { root: true }) ;
|
|
127
|
+
return {
|
|
128
|
+
type: result ? 'success' : 'error',
|
|
129
|
+
msg: result ? 'Basket created' : 'There was an error in fetching the basket info',
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
.catch((error) => {
|
|
133
|
+
if(!error.response){
|
|
134
|
+
return {
|
|
135
|
+
type: 'error',
|
|
136
|
+
msg: 'There was an error in creating basket',
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const status = error.response.status;
|
|
140
|
+
if (status === 422) {
|
|
141
|
+
return {
|
|
142
|
+
type: 'error',
|
|
143
|
+
msg: Object.values(error.response.data.error.validation).map(m => { return m[0] }).toString()
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if ([401, 403, 404, 400].includes(status)) {
|
|
147
|
+
return {
|
|
148
|
+
type: 'error',
|
|
149
|
+
msg: error.response.data.message.body
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
type:'error',
|
|
154
|
+
msg:'There was an error in creating basket'
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
},
|
|
116
158
|
setTable({ rootState }, data) {
|
|
117
159
|
const basket = JSON.parse(localStorage.getItem("basket"));
|
|
118
160
|
const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
|