@onehat/data 1.21.11 → 1.21.13
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.
|
@@ -325,14 +325,24 @@ describe('Repository Base', function() {
|
|
|
325
325
|
expect(filter.value).to.be.eq('1');
|
|
326
326
|
});
|
|
327
327
|
|
|
328
|
-
it('filter - object', function() {
|
|
328
|
+
it.only('filter - object', function() {
|
|
329
|
+
// two possible ways to call filter with an object
|
|
330
|
+
// 1. filter({ name: 'key', value: '1' });
|
|
329
331
|
this.repository.filter({
|
|
330
332
|
name: 'key',
|
|
331
333
|
value: '1',
|
|
332
334
|
});
|
|
333
|
-
const
|
|
334
|
-
expect(
|
|
335
|
-
expect(
|
|
335
|
+
const filter1 = this.repository.filters[0];
|
|
336
|
+
expect(filter1.name).to.be.eq('key');
|
|
337
|
+
expect(filter1.value).to.be.eq('1');
|
|
338
|
+
|
|
339
|
+
// 2. filter({ key: '1' });
|
|
340
|
+
this.repository.filter({
|
|
341
|
+
key: '1',
|
|
342
|
+
});
|
|
343
|
+
const filter2 = this.repository.filters[0];
|
|
344
|
+
expect(filter2.name).to.be.eq('key');
|
|
345
|
+
expect(filter2.value).to.be.eq('1');
|
|
336
346
|
});
|
|
337
347
|
|
|
338
348
|
it('filter - array', function() {
|
package/package.json
CHANGED
|
@@ -238,17 +238,26 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
238
238
|
*/
|
|
239
239
|
_processServerResponse(result) {
|
|
240
240
|
|
|
241
|
+
const retNull = {
|
|
242
|
+
root: null,
|
|
243
|
+
success: false,
|
|
244
|
+
total: 0,
|
|
245
|
+
message: null,
|
|
246
|
+
};
|
|
247
|
+
|
|
241
248
|
if (result === false) { // e.g. 401 error
|
|
242
|
-
return
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
249
|
+
return retNull;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// use try/catch in case the response is not JSON
|
|
253
|
+
let response;
|
|
254
|
+
try {
|
|
255
|
+
response = _.isPlainObject(result.data) ? result.data : this.reader.read(result.data);
|
|
256
|
+
} catch(e) {
|
|
257
|
+
return retNull;
|
|
248
258
|
}
|
|
249
259
|
|
|
250
260
|
const
|
|
251
|
-
response = _.isPlainObject(result.data) ? result.data : this.reader.read(result.data),
|
|
252
261
|
root = response[this.rootProperty],
|
|
253
262
|
success = response[this.successProperty],
|
|
254
263
|
total = response[this.totalProperty],
|
|
@@ -543,22 +552,22 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
543
552
|
return;
|
|
544
553
|
}
|
|
545
554
|
|
|
555
|
+
const data = {
|
|
556
|
+
url: 'Users/apiLogout',
|
|
557
|
+
method: 'POST',
|
|
558
|
+
baseURL: this.api.baseURL,
|
|
559
|
+
headers: _.merge({
|
|
560
|
+
'Content-Type': 'application/json',
|
|
561
|
+
Accept: 'application/json',
|
|
562
|
+
}, this.headers),
|
|
563
|
+
timeout: this.timeout,
|
|
564
|
+
};
|
|
565
|
+
|
|
546
566
|
if (this.debugMode) {
|
|
547
|
-
console.log('logout');
|
|
567
|
+
console.log('logout', data);
|
|
548
568
|
}
|
|
549
569
|
|
|
550
|
-
|
|
551
|
-
'Content-Type': 'application/json',
|
|
552
|
-
Accept: 'application/json',
|
|
553
|
-
}, this.headers);
|
|
554
|
-
|
|
555
|
-
return this.axios({
|
|
556
|
-
url: 'Users/apiLogout',
|
|
557
|
-
method: 'POST',
|
|
558
|
-
baseURL: this.api.baseURL,
|
|
559
|
-
headers,
|
|
560
|
-
timeout: this.timeout,
|
|
561
|
-
})
|
|
570
|
+
return this.axios(data)
|
|
562
571
|
.then((result) => {
|
|
563
572
|
if (this.debugMode) {
|
|
564
573
|
console.log('logout response', result);
|
|
@@ -729,7 +729,19 @@ export default class Repository extends EventEmitter {
|
|
|
729
729
|
}];
|
|
730
730
|
} else if (_.isArray(arg1)) {
|
|
731
731
|
newFilters = arg1;
|
|
732
|
-
} else if (_.
|
|
732
|
+
} else if (_.isPlainObject(arg1)) {
|
|
733
|
+
if (arg1.name) {
|
|
734
|
+
// like { name: 'first_name', value: 'Steve' }
|
|
735
|
+
newFilters = [arg1];
|
|
736
|
+
} else {
|
|
737
|
+
// like { first_name: 'Steve' }
|
|
738
|
+
const name = Object.keys(arg1)[0];
|
|
739
|
+
newFilters = [{
|
|
740
|
+
name,
|
|
741
|
+
value: arg1[name],
|
|
742
|
+
}];
|
|
743
|
+
}
|
|
744
|
+
} else if (_.isFunction(arg1)) {
|
|
733
745
|
newFilters = [arg1];
|
|
734
746
|
}
|
|
735
747
|
|