@autofleet/sheilta 1.0.1-aaron-test → 1.0.2-aaron-test

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.
@@ -18,7 +18,7 @@ const joi_1 = require("joi");
18
18
  const formatter_1 = __importDefault(require("../formatter"));
19
19
  const validations_1 = require("../validations");
20
20
  const querySchema = joi_1.object({
21
- query: joi_1.any(),
21
+ query: joi_1.object(joi_1.any()),
22
22
  attributes: joi_1.array().items(joi_1.string()),
23
23
  order: joi_1.array().items(joi_1.string()),
24
24
  page: joi_1.number(),
@@ -67,28 +67,33 @@ const validatePagination = ({ page, perPage, }) => {
67
67
  }
68
68
  };
69
69
  const validateIncludePayload = (include, associations) => {
70
- const associationsKeys = Object.keys(associations);
71
- include.forEach((i) => {
72
- var _a;
73
- validateQueryAttribute(i.model, associationsKeys);
74
- const target = (_a = associations[i.model]) === null || _a === void 0 ? void 0 : _a.target;
75
- if (!target) {
76
- utils_1.throwBadRequestError('model not found in associations');
77
- }
78
- const { rawAttributes } = target;
79
- if (include.where) {
80
- validateQueryPayload(i.where, rawAttributes);
81
- }
82
- if (include.order) {
83
- validateOrderAttributes(i.order, rawAttributes);
84
- }
85
- if (include.attributes) {
86
- validateAttributes(i.attributes, rawAttributes);
87
- }
88
- if (!lodash_1.default.isNil(include.required) && !lodash_1.default.isBoolean(include.required)) {
89
- utils_1.throwBadRequestError('include.required must be a boolean');
90
- }
91
- });
70
+ try {
71
+ const associationsKeys = Object.keys(associations);
72
+ include.forEach((i) => {
73
+ var _a;
74
+ validateQueryAttribute(i.model, associationsKeys);
75
+ const target = (_a = associations[i.model]) === null || _a === void 0 ? void 0 : _a.target;
76
+ if (!target) {
77
+ utils_1.throwBadRequestError('model not found in associations');
78
+ }
79
+ const { rawAttributes } = target;
80
+ if (include.where) {
81
+ validateQueryPayload(i.where, rawAttributes);
82
+ }
83
+ if (include.order) {
84
+ validateOrderAttributes(i.order, rawAttributes);
85
+ }
86
+ if (include.attributes) {
87
+ validateAttributes(i.attributes, rawAttributes);
88
+ }
89
+ if (!lodash_1.default.isNil(include.required) && !lodash_1.default.isBoolean(include.required)) {
90
+ utils_1.throwBadRequestError('include.required must be a boolean');
91
+ }
92
+ });
93
+ }
94
+ catch (e) {
95
+ utils_1.throwBadRequestError('there was a problem with the include payload');
96
+ }
92
97
  };
93
98
  exports.validatePayload = ({ query = {}, order = [], attributes = [], include = [], page = utils_1.PAGE_DEFAULT, perPage = utils_1.PER_PAGE_DEFAULT, }, model) => {
94
99
  const rawAttributes = Object.keys(model.rawAttributes);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sheilta",
3
- "version": "1.0.1-aaron-test",
3
+ "version": "1.0.2-aaron-test",
4
4
  "description": "manage cache",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",