not-node 5.1.17 → 5.1.20
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
package/src/auth/fields.js
CHANGED
package/src/form/form.js
CHANGED
|
@@ -9,6 +9,10 @@ const ValidationSession = require("not-validation").Session;
|
|
|
9
9
|
|
|
10
10
|
const { notValidationError, notError } = require("not-error");
|
|
11
11
|
|
|
12
|
+
const fromBody = require("./extractors/fromBody.js");
|
|
13
|
+
const fromQuery = require("./extractors/fromQuery.js");
|
|
14
|
+
const fromParams = require("./extractors/fromParams.js");
|
|
15
|
+
|
|
12
16
|
/**
|
|
13
17
|
* Generic form validation class
|
|
14
18
|
**/
|
|
@@ -26,12 +30,18 @@ class Form {
|
|
|
26
30
|
#FORM_NAME;
|
|
27
31
|
#PROTO_FIELDS;
|
|
28
32
|
#VALIDATOR;
|
|
33
|
+
#EXTRACTORS = {
|
|
34
|
+
fromQuery,
|
|
35
|
+
fromBody,
|
|
36
|
+
fromParams,
|
|
37
|
+
};
|
|
29
38
|
|
|
30
|
-
constructor({ FIELDS, FORM_NAME, app }) {
|
|
39
|
+
constructor({ FIELDS, FORM_NAME, app, EXTRACTORS = [] }) {
|
|
31
40
|
this.#FORM_NAME = FORM_NAME;
|
|
32
41
|
this.#PROTO_FIELDS = FIELDS;
|
|
33
42
|
this.#createValidationSchema(app);
|
|
34
43
|
this.#augmentValidationSchema();
|
|
44
|
+
this.#addExtractors(EXTRACTORS);
|
|
35
45
|
}
|
|
36
46
|
|
|
37
47
|
/**
|
|
@@ -207,6 +217,19 @@ class Form {
|
|
|
207
217
|
static fabric() {
|
|
208
218
|
return FormFabric;
|
|
209
219
|
}
|
|
220
|
+
|
|
221
|
+
#addExtractors(extractors) {
|
|
222
|
+
this.#EXTRACTORS = { ...this.#EXTRACTORS, ...extractors };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
extractByInstructions(req, instructions) {
|
|
226
|
+
const results = {};
|
|
227
|
+
for (let fieldName of instructions) {
|
|
228
|
+
const instruction = instructions[fieldName];
|
|
229
|
+
results[fieldName] = instruction(req, fieldName);
|
|
230
|
+
}
|
|
231
|
+
return results;
|
|
232
|
+
}
|
|
210
233
|
}
|
|
211
234
|
|
|
212
235
|
module.exports = Form;
|
package/src/generic/logic.js
CHANGED
|
@@ -422,7 +422,7 @@ module.exports = ({
|
|
|
422
422
|
if (!itm) {
|
|
423
423
|
throw new DBExceptionDocumentIsNotFound();
|
|
424
424
|
}
|
|
425
|
-
if (shouldOwn && !isOwner(itm, activeUser)) {
|
|
425
|
+
if (shouldOwn && !isOwner(itm, activeUser._id)) {
|
|
426
426
|
throw new DBExceptionDocumentIsNotOwnerByActiveUser({
|
|
427
427
|
params: {
|
|
428
428
|
targetId,
|