@autofleet/sadot 0.13.0-beta.6 → 0.13.0-beta.8
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
CHANGED
|
@@ -41,6 +41,7 @@ const ajv = new ajv_1.default({
|
|
|
41
41
|
allErrors: true,
|
|
42
42
|
strict: false, // Disable strict mode to avoid warnings
|
|
43
43
|
strictTypes: false, // Disable strict type checking
|
|
44
|
+
$data: true, // Enable $data references
|
|
44
45
|
});
|
|
45
46
|
(0, ajv_formats_1.default)(ajv);
|
|
46
47
|
/**
|
|
@@ -128,6 +129,16 @@ const validateModel = async (instance, options, scopeAttributes, isCreate = fals
|
|
|
128
129
|
...instance.customFields,
|
|
129
130
|
},
|
|
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
|
+
},
|
|
140
|
+
},
|
|
141
|
+
});
|
|
131
142
|
if (!isValid) {
|
|
132
143
|
const errorDetails = validateSchema.errors?.map((err) => `${err.instancePath || ''} ${err.message || 'Invalid value'}`).join(', ');
|
|
133
144
|
throw new errors_1.BadRequest([new Error(`Validation failed for ${modelType}: ${errorDetails}`)]);
|
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';
|
|
@@ -15,6 +15,7 @@ const ajv = new Ajv({
|
|
|
15
15
|
allErrors: true,
|
|
16
16
|
strict: false, // Disable strict mode to avoid warnings
|
|
17
17
|
strictTypes: false, // Disable strict type checking
|
|
18
|
+
$data: true, // Enable $data references
|
|
18
19
|
});
|
|
19
20
|
|
|
20
21
|
addFormats(ajv);
|
|
@@ -128,7 +129,18 @@ const validateModel = async (
|
|
|
128
129
|
before: originalValues,
|
|
129
130
|
after: {
|
|
130
131
|
...instance.dataValues,
|
|
131
|
-
|
|
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
|
+
},
|
|
132
144
|
},
|
|
133
145
|
});
|
|
134
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("--------------------");
|