Skip to content

Commit

Permalink
Added FilterUtilsr for filter parameter in list services methods
Browse files Browse the repository at this point in the history
  • Loading branch information
v-rudkovskiy committed Mar 27, 2018
1 parent 12b3c6d commit 553c43e
Show file tree
Hide file tree
Showing 15 changed files with 810 additions and 673 deletions.
1,426 changes: 765 additions & 661 deletions dist/netlicensing-client.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/netlicensing-client.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/netlicensing-client.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/netlicensing-client.min.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/netlicensing-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import ValidationResults from './vo/ValidationResults';
// Utils
import CastsUtils from './util/CastsUtils';
import CheckUtils from './util/CheckUtils';
import FilterUtils from './util/FilterUtils';


// Create the default instance to be exported
Expand Down Expand Up @@ -73,6 +74,7 @@ const NetLicensing = {
// Expose Utils
CastsUtils,
CheckUtils,
FilterUtils,
};

module.exports = NetLicensing;
Expand Down
3 changes: 2 additions & 1 deletion src/services/LicenseService.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import License from '../entities/License';
import CheckUtils from '../util/CheckUtils';
import Constants from '../Constants';
import Service from './Service';
import FilterUtils from '../util/FilterUtils';

/**
* JS representation of the License Service. See NetLicensingAPI for details:
Expand Down Expand Up @@ -121,7 +122,7 @@ export default {
if (!CheckUtils.isValid(filter)) {
throw new TypeError(`filter has bad value ${filter}`);
}
queryParams.filter = filter;
queryParams.filter = typeof filter === 'string' ? filter : FilterUtils.encode(filter);
}

return Service
Expand Down
3 changes: 2 additions & 1 deletion src/services/LicenseTemplateService.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import LicenseTemplate from '../entities/LicenseTemplate';
import CheckUtils from '../util/CheckUtils';
import Constants from '../Constants';
import Service from './Service';
import FilterUtils from '../util/FilterUtils';

/**
* JS representation of the ProductModule Service. See NetLicensingAPI for details:
Expand Down Expand Up @@ -107,7 +108,7 @@ export default {
if (!CheckUtils.isValid(filter)) {
throw new TypeError(`filter has bad value ${filter}`);
}
queryParams.filter = filter;
queryParams.filter = typeof filter === 'string' ? filter : FilterUtils.encode(filter);
}

return Service
Expand Down
3 changes: 2 additions & 1 deletion src/services/LicenseeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Context from '../vo/Context';
import Licensee from '../entities/Licensee';
import CheckUtils from '../util/CheckUtils';
import FilterUtils from '../util/FilterUtils';
import Constants from '../Constants';
import Service from './Service';
import ValidationParameters from '../vo/ValidationParameters';
Expand Down Expand Up @@ -105,7 +106,7 @@ export default {
if (!CheckUtils.isValid(filter)) {
throw new TypeError(`filter has bad value ${filter}`);
}
queryParams.filter = filter;
queryParams.filter = typeof filter === 'string' ? filter : FilterUtils.encode(filter);
}

return Service
Expand Down
3 changes: 2 additions & 1 deletion src/services/PaymentMethodService.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import PaymentMethod from '../entities/PaymentMethod';
import Constants from '../Constants';
import CheckUtils from '../util/CheckUtils';
import Service from './Service';
import FilterUtils from '../util/FilterUtils';

export default {
/**
Expand Down Expand Up @@ -64,7 +65,7 @@ export default {
if (!CheckUtils.isValid(filter)) {
throw new TypeError(`filter has bad value ${filter}`);
}
queryParams.filter = filter;
queryParams.filter = typeof filter === 'string' ? filter : FilterUtils.encode(filter);
}

return Service
Expand Down
3 changes: 2 additions & 1 deletion src/services/ProductModuleService.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ProductModule from '../entities/ProductModule';
import CheckUtils from '../util/CheckUtils';
import Constants from '../Constants';
import Service from './Service';
import FilterUtils from '../util/FilterUtils';

/**
* JS representation of the ProductModule Service. See NetLicensingAPI for details:
Expand Down Expand Up @@ -107,7 +108,7 @@ export default {
if (!CheckUtils.isValid(filter)) {
throw new TypeError(`filter has bad value ${filter}`);
}
queryParams.filter = filter;
queryParams.filter = typeof filter === 'string' ? filter : FilterUtils.encode(filter);
}

return Service
Expand Down
3 changes: 2 additions & 1 deletion src/services/ProductService.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Context from '../vo/Context';
import Product from '../entities/Product';
import Constants from '../Constants';
import CheckUtils from '../util/CheckUtils';
import FilterUtils from '../util/FilterUtils';

/**
* JS representation of the Product Service. See NetLicensingAPI for details:
Expand Down Expand Up @@ -101,7 +102,7 @@ export default {
if (!CheckUtils.isValid(filter)) {
throw new TypeError(`filter has bad value ${filter}`);
}
queryParams.filter = filter;
queryParams.filter = typeof filter === 'string' ? filter : FilterUtils.encode(filter);
}

return Service
Expand Down
3 changes: 2 additions & 1 deletion src/services/TokenService.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Token from '../entities/Token';
import Constants from '../Constants';
import Service from './Service';
import CheckUtils from '../util/CheckUtils';
import FilterUtils from '../util/FilterUtils';

/**
* JS representation of the Token Service. See NetLicensingAPI for details:
Expand Down Expand Up @@ -93,7 +94,7 @@ export default {
if (!CheckUtils.isValid(filter)) {
throw new TypeError(`filter has bad value ${filter}`);
}
queryParams.filter = filter;
queryParams.filter = typeof filter === 'string' ? filter : FilterUtils.encode(filter);
}

return Service
Expand Down
3 changes: 2 additions & 1 deletion src/services/TransactionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Transaction from '../entities/Transaction';
import Constants from '../Constants';
import Service from './Service';
import CheckUtils from '../util/CheckUtils';
import FilterUtils from '../util/FilterUtils';

/**
* JS representation of the Transaction Service. See NetLicensingAPI for details:
Expand Down Expand Up @@ -108,7 +109,7 @@ export default {
if (!CheckUtils.isValid(filter)) {
throw new TypeError(`filter has bad value ${filter}`);
}
queryParams.filter = filter;
queryParams.filter = typeof filter === 'string' ? filter : FilterUtils.encode(filter);
}

return Service
Expand Down
3 changes: 2 additions & 1 deletion src/services/UtilityService.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Constants from '../Constants';
import Service from './Service';
import CheckUtils from '../util/CheckUtils';
import Country from '../entities/Country';
import FilterUtils from '../util/FilterUtils';

/**
* JS representation of the Utility Service. See NetLicensingAPI for details:
Expand Down Expand Up @@ -87,7 +88,7 @@ export default {
if (!CheckUtils.isValid(filter)) {
throw new TypeError(`filter has bad value ${filter}`);
}
queryParams.filter = filter;
queryParams.filter = typeof filter === 'string' ? filter : FilterUtils.encode(filter);
}

return Service
Expand Down
22 changes: 22 additions & 0 deletions src/util/FilterUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default {
FILTER_DELIMITER: ';',
FILTER_PAIR_DELIMITER: '=',
encode(filter = {}) {
const query = [];
const has = Object.prototype.hasOwnProperty;
Object.keys(filter).forEach((key) => {
if (has.call(filter, key)) {
query.push(`${encodeURIComponent(key)}${this.FILTER_PAIR_DELIMITER}${encodeURIComponent(filter[key])}`);
}
});
return query.join(this.FILTER_DELIMITER);
},
decode(query = '') {
const filter = {};
query.split(this.FILTER_DELIMITER).forEach((v) => {
const [name, value] = v.split(this.FILTER_PAIR_DELIMITER);
filter[name] = value;
});
return filter;
},
};

0 comments on commit 553c43e

Please sign in to comment.