|
2 | 2 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
3 | 3 | typeof define === 'function' && define.amd ? define(factory) : |
4 | 4 | (global = global || self, global.VuexORMAxios = factory()); |
5 | | -}(this, function () { 'use strict'; |
| 5 | +}(this, (function () { 'use strict'; |
6 | 6 |
|
7 | 7 | /*! ***************************************************************************** |
8 | 8 | Copyright (c) Microsoft Corporation. All rights reserved. |
|
209 | 209 | Request.prototype.persistResponseData = function (response, config) { |
210 | 210 | return __awaiter(this, void 0, void 0, function () { |
211 | 211 | return __generator(this, function (_a) { |
212 | | - if (!config.save) { |
213 | | - return [2 /*return*/, null]; |
214 | | - } |
215 | | - if (config.delete !== undefined) { |
216 | | - return [2 /*return*/, this.model.delete(config.delete)]; |
| 212 | + switch (_a.label) { |
| 213 | + case 0: |
| 214 | + if (!config.save) { |
| 215 | + return [2 /*return*/, null]; |
| 216 | + } |
| 217 | + if (!(config.delete !== undefined)) return [3 /*break*/, 2]; |
| 218 | + return [4 /*yield*/, this.model.delete(config.delete)]; |
| 219 | + case 1: |
| 220 | + _a.sent(); |
| 221 | + return [2 /*return*/, null]; |
| 222 | + case 2: return [2 /*return*/, this.model.insertOrUpdate({ |
| 223 | + data: this.getDataFromResponse(response, config) |
| 224 | + })]; |
217 | 225 | } |
218 | | - return [2 /*return*/, this.model.insertOrUpdate({ |
219 | | - data: this.getDataFromResponse(response, config) |
220 | | - })]; |
221 | 226 | }); |
222 | 227 | }); |
223 | 228 | }; |
224 | 229 | /** |
225 | | - * Get data from the given response object. If the `dataKey` config is |
226 | | - * provided, it tries to fetch the data at that key. |
| 230 | + * Get data from the given response object. If the `dataTransformer` config is |
| 231 | + * provided, it tries to execute the method with the response as param. If the |
| 232 | + * `dataKey` config is provided, it tries to fetch the data at that key. |
227 | 233 | */ |
228 | 234 | Request.prototype.getDataFromResponse = function (response, config) { |
229 | | - if (!config.dataKey) { |
230 | | - return response.data; |
| 235 | + if (config.dataTransformer) { |
| 236 | + return config.dataTransformer(response); |
| 237 | + } |
| 238 | + if (config.dataKey) { |
| 239 | + return response.data[config.dataKey]; |
231 | 240 | } |
232 | | - return response.data[config.dataKey]; |
| 241 | + return response.data; |
233 | 242 | }; |
234 | 243 | return Request; |
235 | 244 | }()); |
|
286 | 295 |
|
287 | 296 | return index_cjs; |
288 | 297 |
|
289 | | -})); |
| 298 | +}))); |
0 commit comments