@autofleet/sadot 0.13.0-beta.7 → 0.13.0-beta.9
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/dist/hooks/hooks.js +12 -2
- package/package.json +1 -1
- package/src/hooks/hooks.ts +14 -3
- package/validator-test.js +79 -0
package/dist/hooks/hooks.js
CHANGED
|
@@ -110,7 +110,7 @@ const validateModel = async (instance, options, scopeAttributes, isCreate = fals
|
|
|
110
110
|
const isValid = validateSchema({
|
|
111
111
|
after: {
|
|
112
112
|
...instance.dataValues,
|
|
113
|
-
|
|
113
|
+
customFields: instance.customFields,
|
|
114
114
|
},
|
|
115
115
|
});
|
|
116
116
|
if (!isValid) {
|
|
@@ -126,7 +126,17 @@ const validateModel = async (instance, options, scopeAttributes, isCreate = fals
|
|
|
126
126
|
before: originalValues,
|
|
127
127
|
after: {
|
|
128
128
|
...instance.dataValues,
|
|
129
|
-
|
|
129
|
+
customFields: instance.customFields,
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
logger_1.default.info('sadot - validation result', {
|
|
133
|
+
isValid,
|
|
134
|
+
test: {
|
|
135
|
+
before: originalValues,
|
|
136
|
+
after: {
|
|
137
|
+
...instance.dataValues,
|
|
138
|
+
...instance.customFields,
|
|
139
|
+
},
|
|
130
140
|
},
|
|
131
141
|
});
|
|
132
142
|
if (!isValid) {
|
package/package.json
CHANGED
package/src/hooks/hooks.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { WhereOptions } from 'sequelize';
|
|
2
2
|
import Ajv from 'ajv';
|
|
3
|
-
import addFormats from
|
|
3
|
+
import addFormats from 'ajv-formats';
|
|
4
4
|
import { BadRequest } from '@autofleet/errors';
|
|
5
5
|
import logger from '../utils/logger';
|
|
6
6
|
import * as ValidatorRepo from '../repository/validator';
|
|
@@ -110,7 +110,7 @@ const validateModel = async (
|
|
|
110
110
|
const isValid = validateSchema({
|
|
111
111
|
after: {
|
|
112
112
|
...instance.dataValues,
|
|
113
|
-
|
|
113
|
+
customFields: instance.customFields,
|
|
114
114
|
},
|
|
115
115
|
});
|
|
116
116
|
|
|
@@ -129,7 +129,18 @@ const validateModel = async (
|
|
|
129
129
|
before: originalValues,
|
|
130
130
|
after: {
|
|
131
131
|
...instance.dataValues,
|
|
132
|
-
|
|
132
|
+
customFields: instance.customFields,
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
logger.info('sadot - validation result', {
|
|
137
|
+
isValid,
|
|
138
|
+
test: {
|
|
139
|
+
before: originalValues,
|
|
140
|
+
after: {
|
|
141
|
+
...instance.dataValues,
|
|
142
|
+
...instance.customFields,
|
|
143
|
+
},
|
|
133
144
|
},
|
|
134
145
|
});
|
|
135
146
|
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const Ajv = require("ajv");
|
|
2
|
+
const addFormats = require("ajv-formats");
|
|
3
|
+
const ajv = new Ajv({
|
|
4
|
+
allErrors: true,
|
|
5
|
+
strict: false, // Disable strict mode to avoid warnings
|
|
6
|
+
strictTypes: false, // Disable strict type checking
|
|
7
|
+
$data: true, // Enable $data references
|
|
8
|
+
}); // options can be passed, e.g. {allErrors: true}
|
|
9
|
+
addFormats(ajv);
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const schema = {
|
|
13
|
+
"type": "object",
|
|
14
|
+
"properties": {
|
|
15
|
+
"after": {
|
|
16
|
+
"type": "object",
|
|
17
|
+
"properties": {
|
|
18
|
+
"customFields": {
|
|
19
|
+
"type": "object",
|
|
20
|
+
"properties": {
|
|
21
|
+
"actualStartTime": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"format": "date-time"
|
|
24
|
+
},
|
|
25
|
+
"actualEndTime": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"format": "date-time",
|
|
28
|
+
"formatMinimum": {
|
|
29
|
+
"$data": "/after/customFields/actualStartTime"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const validate = ajv.compile(schema);
|
|
40
|
+
|
|
41
|
+
const data = {
|
|
42
|
+
"id": "c9c87cec-28c7-4a1f-9376-4d8a4ba0f49c",
|
|
43
|
+
"typeId": "4fcd7096-4c90-46a2-a20e-91bb5bff3ced",
|
|
44
|
+
"priorityId": null,
|
|
45
|
+
"statusId": "51d28a37-c042-429f-a9cd-fbc81bba2b39",
|
|
46
|
+
"subjectId": null,
|
|
47
|
+
"subjectType": null,
|
|
48
|
+
"title": "ff",
|
|
49
|
+
"description": null,
|
|
50
|
+
"dueTime": null,
|
|
51
|
+
"startTime": null,
|
|
52
|
+
"endTime": null,
|
|
53
|
+
"driverId": null,
|
|
54
|
+
"vendorId": null,
|
|
55
|
+
"userId": null,
|
|
56
|
+
"businessModelId": "72ecf740-42a1-46f4-81ca-8132b08c4f04",
|
|
57
|
+
"createdAt": "2025-03-12T12:58:05.529Z",
|
|
58
|
+
"updatedAt": "2025-03-12T12:58:05.529Z",
|
|
59
|
+
"deletedAt": null,
|
|
60
|
+
"actions": [],
|
|
61
|
+
"customFields": {
|
|
62
|
+
"actualStartTime": "2025-03-14T12:48:01.373Z",
|
|
63
|
+
"actualEndTime": "2025-03-01T12:51:46.685Z"
|
|
64
|
+
},
|
|
65
|
+
"isBlocker": false
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const valid = validate({after: data});
|
|
69
|
+
|
|
70
|
+
if (!valid) {
|
|
71
|
+
console.log("invalid, the errors is: ");
|
|
72
|
+
validate.errors.forEach((error) =>
|
|
73
|
+
console.log(error.instancePath, error.message)
|
|
74
|
+
);
|
|
75
|
+
} else {
|
|
76
|
+
console.log("valid");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
console.log("--------------------");
|