@autofleet/sadot 0.13.0-beta.11 → 0.13.0-beta.3
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/api/v1/validator/validations.js +1 -0
- package/dist/hooks/hooks.js +5 -16
- package/dist/utils/validations/schema/validator-schema.js +0 -1
- package/package.json +1 -1
- package/src/api/v1/validator/validations.ts +1 -0
- package/src/hooks/hooks.ts +6 -18
- package/src/utils/validations/schema/validator-schema.ts +0 -1
- package/validator-test.js +0 -79
|
@@ -23,6 +23,7 @@ const validationSchemas = {
|
|
|
23
23
|
}),
|
|
24
24
|
update: joi_1.default.object({
|
|
25
25
|
entityId: joi_1.default.string().uuid(),
|
|
26
|
+
entityType: joi_1.default.string(),
|
|
26
27
|
schema: joi_1.default.object({
|
|
27
28
|
type: joi_1.default.string().valid('object'),
|
|
28
29
|
properties: joi_1.default.object({
|
package/dist/hooks/hooks.js
CHANGED
|
@@ -41,7 +41,6 @@ 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
|
|
45
44
|
});
|
|
46
45
|
(0, ajv_formats_1.default)(ajv);
|
|
47
46
|
/**
|
|
@@ -107,12 +106,12 @@ const validateModel = async (instance, options, scopeAttributes, isCreate = fals
|
|
|
107
106
|
after: typedSchema.properties.after,
|
|
108
107
|
},
|
|
109
108
|
});
|
|
110
|
-
const isValid = validateSchema(
|
|
109
|
+
const isValid = validateSchema({
|
|
111
110
|
after: {
|
|
112
111
|
...instance.dataValues,
|
|
113
|
-
|
|
112
|
+
...instance.customFields,
|
|
114
113
|
},
|
|
115
|
-
})
|
|
114
|
+
});
|
|
116
115
|
if (!isValid) {
|
|
117
116
|
const errorDetails = validateSchema.errors?.map((err) => `${err.instancePath || ''} ${err.message || 'Invalid value'}`).join(', ');
|
|
118
117
|
throw new errors_1.BadRequest([new Error(`Validation failed for ${modelType}: ${errorDetails}`)]);
|
|
@@ -122,21 +121,11 @@ const validateModel = async (instance, options, scopeAttributes, isCreate = fals
|
|
|
122
121
|
else {
|
|
123
122
|
// For update operations, we need both before and after
|
|
124
123
|
const validateSchema = ajv.compile(typedSchema);
|
|
125
|
-
const isValid = validateSchema(
|
|
124
|
+
const isValid = validateSchema({
|
|
126
125
|
before: originalValues,
|
|
127
126
|
after: {
|
|
128
127
|
...instance.dataValues,
|
|
129
|
-
|
|
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
|
-
},
|
|
128
|
+
...instance.customFields,
|
|
140
129
|
},
|
|
141
130
|
});
|
|
142
131
|
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';
|
|
@@ -15,7 +15,6 @@ 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
|
|
19
18
|
});
|
|
20
19
|
|
|
21
20
|
addFormats(ajv);
|
|
@@ -107,12 +106,12 @@ const validateModel = async (
|
|
|
107
106
|
},
|
|
108
107
|
});
|
|
109
108
|
|
|
110
|
-
const isValid = validateSchema(
|
|
109
|
+
const isValid = validateSchema({
|
|
111
110
|
after: {
|
|
112
111
|
...instance.dataValues,
|
|
113
|
-
|
|
112
|
+
...instance.customFields,
|
|
114
113
|
},
|
|
115
|
-
})
|
|
114
|
+
});
|
|
116
115
|
|
|
117
116
|
if (!isValid) {
|
|
118
117
|
const errorDetails = validateSchema.errors?.map((err) =>
|
|
@@ -125,22 +124,11 @@ const validateModel = async (
|
|
|
125
124
|
// For update operations, we need both before and after
|
|
126
125
|
const validateSchema = ajv.compile(typedSchema);
|
|
127
126
|
|
|
128
|
-
const isValid = validateSchema(
|
|
127
|
+
const isValid = validateSchema({
|
|
129
128
|
before: originalValues,
|
|
130
129
|
after: {
|
|
131
130
|
...instance.dataValues,
|
|
132
|
-
|
|
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
|
-
},
|
|
131
|
+
...instance.customFields,
|
|
144
132
|
},
|
|
145
133
|
});
|
|
146
134
|
|
package/validator-test.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
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("--------------------");
|