orderiom-api-package 0.2.47 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orderiom-api-package",
3
- "version": "0.2.47",
3
+ "version": "0.2.48",
4
4
  "description": "this package will install all neccessary api calls for every orderiom restaurant",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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 ? {