@autofleet/sadot 1.0.5 → 1.0.7
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/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.cjs +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.js +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.cjs +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.js +1 -0
- package/dist/_virtual/rolldown_runtime.cjs +1 -0
- package/dist/api/index.cjs +2 -0
- package/dist/api/index.cjs.map +1 -0
- package/dist/api/index.js +2 -12
- package/dist/api/index.js.map +1 -0
- package/dist/api/v1/definition/index.cjs +2 -0
- package/dist/api/v1/definition/index.cjs.map +1 -0
- package/dist/api/v1/definition/index.js +2 -116
- package/dist/api/v1/definition/index.js.map +1 -0
- package/dist/api/v1/definition/validations.cjs +2 -0
- package/dist/api/v1/definition/validations.cjs.map +1 -0
- package/dist/api/v1/definition/validations.js +2 -77
- package/dist/api/v1/definition/validations.js.map +1 -0
- package/dist/api/v1/errors.cjs +2 -0
- package/dist/api/v1/errors.cjs.map +1 -0
- package/dist/api/v1/errors.js +2 -12
- package/dist/api/v1/errors.js.map +1 -0
- package/dist/api/v1/index.cjs +2 -0
- package/dist/api/v1/index.cjs.map +1 -0
- package/dist/api/v1/index.js +2 -13
- package/dist/api/v1/index.js.map +1 -0
- package/dist/api/v1/validator/index.cjs +2 -0
- package/dist/api/v1/validator/index.cjs.map +1 -0
- package/dist/api/v1/validator/index.js +2 -143
- package/dist/api/v1/validator/index.js.map +1 -0
- package/dist/api/v1/validator/validations.cjs +2 -0
- package/dist/api/v1/validator/validations.cjs.map +1 -0
- package/dist/api/v1/validator/validations.js +2 -38
- package/dist/api/v1/validator/validations.js.map +1 -0
- package/dist/errors/index.cjs +3 -0
- package/dist/errors/index.cjs.map +1 -0
- package/dist/errors/index.js +3 -66
- package/dist/errors/index.js.map +1 -0
- package/dist/events/index.cjs +2 -0
- package/dist/events/index.cjs.map +1 -0
- package/dist/events/index.js +2 -54
- package/dist/events/index.js.map +1 -0
- package/dist/hooks/enrich.cjs +2 -0
- package/dist/hooks/enrich.cjs.map +1 -0
- package/dist/hooks/enrich.js +2 -198
- package/dist/hooks/enrich.js.map +1 -0
- package/dist/hooks/find.cjs +2 -0
- package/dist/hooks/find.cjs.map +1 -0
- package/dist/hooks/find.js +2 -29
- package/dist/hooks/find.js.map +1 -0
- package/dist/hooks/hooks.cjs +2 -0
- package/dist/hooks/hooks.cjs.map +1 -0
- package/dist/hooks/hooks.js +2 -388
- package/dist/hooks/hooks.js.map +1 -0
- package/dist/hooks/index.cjs +1 -0
- package/dist/hooks/index.js +1 -17
- package/dist/hooks/utils/updateInstanceValues.cjs +2 -0
- package/dist/hooks/utils/updateInstanceValues.cjs.map +1 -0
- package/dist/hooks/utils/updateInstanceValues.js +2 -50
- package/dist/hooks/utils/updateInstanceValues.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +19 -0
- package/dist/index.d.ts +18 -12
- package/dist/index.js +2 -67
- package/dist/index.js.map +1 -0
- package/dist/models/CustomFieldDefinition.cjs +2 -0
- package/dist/models/CustomFieldDefinition.cjs.map +1 -0
- package/dist/models/CustomFieldDefinition.js +2 -192
- package/dist/models/CustomFieldDefinition.js.map +1 -0
- package/dist/models/CustomFieldEntries.cjs +2 -0
- package/dist/models/CustomFieldEntries.cjs.map +1 -0
- package/dist/models/CustomFieldEntries.js +2 -123
- package/dist/models/CustomFieldEntries.js.map +1 -0
- package/dist/models/CustomFieldValue.cjs +2 -0
- package/dist/models/CustomFieldValue.cjs.map +1 -0
- package/dist/models/CustomFieldValue.js +2 -151
- package/dist/models/CustomFieldValue.js.map +1 -0
- package/dist/models/CustomValidator.cjs +2 -0
- package/dist/models/CustomValidator.cjs.map +1 -0
- package/dist/models/CustomValidator.js +2 -98
- package/dist/models/CustomValidator.js.map +1 -0
- package/dist/models/index.cjs +2 -0
- package/dist/models/index.cjs.map +1 -0
- package/dist/models/index.js +2 -131
- package/dist/models/index.js.map +1 -0
- package/dist/models/tests/AssociatedTestModel.cjs +2 -0
- package/dist/models/tests/AssociatedTestModel.cjs.map +1 -0
- package/dist/models/tests/AssociatedTestModel.js +2 -71
- package/dist/models/tests/AssociatedTestModel.js.map +1 -0
- package/dist/models/tests/TestModel.cjs +2 -0
- package/dist/models/tests/TestModel.cjs.map +1 -0
- package/dist/models/tests/TestModel.js +2 -69
- package/dist/models/tests/TestModel.js.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs +2 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js +2 -53
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.cjs +2 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.cjs.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.js +2 -47
- package/dist/models/tests/contextAwareModels/ContextTestModel.js.map +1 -0
- package/dist/repository/definition.cjs +2 -0
- package/dist/repository/definition.cjs.map +1 -0
- package/dist/repository/definition.js +2 -121
- package/dist/repository/definition.js.map +1 -0
- package/dist/repository/entries.cjs +2 -0
- package/dist/repository/entries.cjs.map +1 -0
- package/dist/repository/entries.js +2 -92
- package/dist/repository/entries.js.map +1 -0
- package/dist/repository/utils/formatValues.cjs +2 -0
- package/dist/repository/utils/formatValues.cjs.map +1 -0
- package/dist/repository/utils/formatValues.js +2 -16
- package/dist/repository/utils/formatValues.js.map +1 -0
- package/dist/repository/validator.cjs +2 -0
- package/dist/repository/validator.cjs.map +1 -0
- package/dist/repository/validator.js +2 -69
- package/dist/repository/validator.js.map +1 -0
- package/dist/repository/value.cjs +2 -0
- package/dist/repository/value.cjs.map +1 -0
- package/dist/repository/value.js +2 -124
- package/dist/repository/value.js.map +1 -0
- package/dist/scopes/filter.cjs +2 -0
- package/dist/scopes/filter.cjs.map +1 -0
- package/dist/scopes/filter.d.cts +23 -0
- package/dist/scopes/filter.d.ts +22 -29
- package/dist/scopes/filter.js +2 -75
- package/dist/scopes/filter.js.map +1 -0
- package/dist/scopes/helpers/filter.helpers.cjs +46 -0
- package/dist/scopes/helpers/filter.helpers.cjs.map +1 -0
- package/dist/scopes/helpers/filter.helpers.d.cts +17 -0
- package/dist/scopes/helpers/filter.helpers.d.ts +15 -40
- package/dist/scopes/helpers/filter.helpers.js +25 -183
- package/dist/scopes/helpers/filter.helpers.js.map +1 -0
- package/dist/scopes/index.cjs +1 -0
- package/dist/scopes/index.js +1 -6
- package/dist/types/index.d.cts +44 -0
- package/dist/types/index.d.ts +41 -44
- package/dist/utils/constants/index.cjs +2 -0
- package/dist/utils/constants/index.cjs.map +1 -0
- package/dist/utils/constants/index.d.cts +22 -0
- package/dist/utils/constants/index.d.ts +20 -17
- package/dist/utils/constants/index.js +2 -22
- package/dist/utils/constants/index.js.map +1 -0
- package/dist/utils/db/index.cjs +2 -0
- package/dist/utils/db/index.cjs.map +1 -0
- package/dist/utils/db/index.js +2 -24
- package/dist/utils/db/index.js.map +1 -0
- package/dist/utils/helpers/index.cjs +2 -0
- package/dist/utils/helpers/index.cjs.map +1 -0
- package/dist/utils/helpers/index.d.cts +31 -0
- package/dist/utils/helpers/index.d.ts +28 -23
- package/dist/utils/helpers/index.js +2 -40
- package/dist/utils/helpers/index.js.map +1 -0
- package/dist/utils/init.cjs +2 -0
- package/dist/utils/init.cjs.map +1 -0
- package/dist/utils/init.js +2 -112
- package/dist/utils/init.js.map +1 -0
- package/dist/utils/logger/index.cjs +2 -0
- package/dist/utils/logger/index.cjs.map +1 -0
- package/dist/utils/logger/index.js +2 -42
- package/dist/utils/logger/index.js.map +1 -0
- package/dist/utils/scopeAttributes.cjs +2 -0
- package/dist/utils/scopeAttributes.cjs.map +1 -0
- package/dist/utils/scopeAttributes.js +2 -11
- package/dist/utils/scopeAttributes.js.map +1 -0
- package/dist/utils/validations/index.cjs +2 -0
- package/dist/utils/validations/index.cjs.map +1 -0
- package/dist/utils/validations/index.js +2 -41
- package/dist/utils/validations/index.js.map +1 -0
- package/dist/utils/validations/schema/custom-fields.cjs +2 -0
- package/dist/utils/validations/schema/custom-fields.cjs.map +1 -0
- package/dist/utils/validations/schema/custom-fields.d.cts +7 -0
- package/dist/utils/validations/schema/custom-fields.d.ts +6 -2
- package/dist/utils/validations/schema/custom-fields.js +2 -9
- package/dist/utils/validations/schema/custom-fields.js.map +1 -0
- package/dist/utils/validations/schema/validator-schema.cjs +2 -0
- package/dist/utils/validations/schema/validator-schema.cjs.map +1 -0
- package/dist/utils/validations/schema/validator-schema.js +2 -95
- package/dist/utils/validations/schema/validator-schema.js.map +1 -0
- package/dist/utils/validations/validators/index.cjs +2 -0
- package/dist/utils/validations/validators/index.cjs.map +1 -0
- package/dist/utils/validations/validators/index.js +2 -40
- package/dist/utils/validations/validators/index.js.map +1 -0
- package/dist/utils/validations/validators/select.validator.cjs +2 -0
- package/dist/utils/validations/validators/select.validator.cjs.map +1 -0
- package/dist/utils/validations/validators/select.validator.js +2 -12
- package/dist/utils/validations/validators/select.validator.js.map +1 -0
- package/dist/utils/validations/validators/status.validator.cjs +2 -0
- package/dist/utils/validations/validators/status.validator.cjs.map +1 -0
- package/dist/utils/validations/validators/status.validator.js +2 -15
- package/dist/utils/validations/validators/status.validator.js.map +1 -0
- package/package.json +26 -23
- package/.nvmrc +0 -1
- package/dist/api/index.d.ts +0 -3
- package/dist/api/v1/definition/index.d.ts +0 -3
- package/dist/api/v1/definition/validations.d.ts +0 -2
- package/dist/api/v1/errors.d.ts +0 -4
- package/dist/api/v1/index.d.ts +0 -3
- package/dist/api/v1/validator/index.d.ts +0 -3
- package/dist/api/v1/validator/validations.d.ts +0 -6
- package/dist/errors/index.d.ts +0 -24
- package/dist/events/index.d.ts +0 -5
- package/dist/hooks/create.d.ts +0 -10
- package/dist/hooks/create.js +0 -95
- package/dist/hooks/enrich.d.ts +0 -25
- package/dist/hooks/find.d.ts +0 -1
- package/dist/hooks/hooks.d.ts +0 -17
- package/dist/hooks/index.d.ts +0 -5
- package/dist/hooks/update.d.ts +0 -10
- package/dist/hooks/update.js +0 -49
- package/dist/hooks/utils/updateInstanceValues.d.ts +0 -15
- package/dist/hooks/workaround.d.ts +0 -10
- package/dist/hooks/workaround.js +0 -37
- package/dist/models/CustomFieldDefinition.d.ts +0 -25
- package/dist/models/CustomFieldEntries.d.ts +0 -15
- package/dist/models/CustomFieldValue.d.ts +0 -16
- package/dist/models/CustomValidator.d.ts +0 -17
- package/dist/models/index.d.ts +0 -18
- package/dist/models/tests/AssociatedTestModel.d.ts +0 -12
- package/dist/models/tests/TestModel.d.ts +0 -12
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.d.ts +0 -10
- package/dist/models/tests/contextAwareModels/ContextTestModel.d.ts +0 -13
- package/dist/repository/definition.d.ts +0 -36
- package/dist/repository/entries.d.ts +0 -13
- package/dist/repository/utils/formatValues.d.ts +0 -3
- package/dist/repository/validator.d.ts +0 -28
- package/dist/repository/value.d.ts +0 -28
- package/dist/scopes/index.d.ts +0 -2
- package/dist/tests/api/test-api.d.ts +0 -2
- package/dist/tests/api/test-api.js +0 -38
- package/dist/tests/functional/searching/index.d.ts +0 -8
- package/dist/tests/functional/searching/index.js +0 -44
- package/dist/tests/helpers/commonHooks.d.ts +0 -6
- package/dist/tests/helpers/commonHooks.js +0 -62
- package/dist/tests/helpers/database-config.d.ts +0 -16
- package/dist/tests/helpers/database-config.js +0 -17
- package/dist/tests/helpers/index.d.ts +0 -7
- package/dist/tests/helpers/index.js +0 -33
- package/dist/tests/mocks/definition.mock.d.ts +0 -48
- package/dist/tests/mocks/definition.mock.js +0 -78
- package/dist/tests/mocks/events.mock.d.ts +0 -4
- package/dist/tests/mocks/events.mock.js +0 -21
- package/dist/tests/mocks/testModel.d.ts +0 -12
- package/dist/tests/mocks/testModel.js +0 -35
- package/dist/types/definition/index.d.ts +0 -25
- package/dist/types/definition/index.js +0 -2
- package/dist/types/entries/index.d.ts +0 -25
- package/dist/types/entries/index.js +0 -2
- package/dist/types/index.js +0 -2
- package/dist/types/value/index.d.ts +0 -15
- package/dist/types/value/index.js +0 -2
- package/dist/utils/db/index.d.ts +0 -4
- package/dist/utils/init.d.ts +0 -7
- package/dist/utils/logger/index.d.ts +0 -3
- package/dist/utils/scopeAttributes.d.ts +0 -2
- package/dist/utils/validations/index.d.ts +0 -8
- package/dist/utils/validations/schema/validator-schema.d.ts +0 -9
- package/dist/utils/validations/type.d.ts +0 -15
- package/dist/utils/validations/type.js +0 -2
- package/dist/utils/validations/validators/index.d.ts +0 -14
- package/dist/utils/validations/validators/select.validator.d.ts +0 -5
- package/dist/utils/validations/validators/status.validator.d.ts +0 -12
- package/src/api/index.ts +0 -10
- package/src/api/v1/definition/index.ts +0 -104
- package/src/api/v1/definition/validations.ts +0 -75
- package/src/api/v1/errors.ts +0 -13
- package/src/api/v1/index.ts +0 -11
- package/src/api/v1/validator/index.ts +0 -141
- package/src/api/v1/validator/validations.ts +0 -38
- package/src/errors/index.ts +0 -70
- package/src/events/index.ts +0 -63
- package/src/hooks/create.ts +0 -81
- package/src/hooks/enrich.ts +0 -255
- package/src/hooks/find.ts +0 -27
- package/src/hooks/hooks.ts +0 -479
- package/src/hooks/index.ts +0 -20
- package/src/hooks/update.ts +0 -55
- package/src/hooks/utils/updateInstanceValues.ts +0 -63
- package/src/hooks/workaround.ts +0 -47
- package/src/index.ts +0 -52
- package/src/models/CustomFieldDefinition.ts +0 -162
- package/src/models/CustomFieldEntries.ts +0 -81
- package/src/models/CustomFieldValue.ts +0 -118
- package/src/models/CustomValidator.ts +0 -78
- package/src/models/index.ts +0 -165
- package/src/models/tests/AssociatedTestModel.ts +0 -57
- package/src/models/tests/TestModel.ts +0 -54
- package/src/models/tests/contextAwareModels/ContextAwareTestModel.ts +0 -43
- package/src/models/tests/contextAwareModels/ContextTestModel.ts +0 -38
- package/src/repository/definition.ts +0 -175
- package/src/repository/entries.ts +0 -88
- package/src/repository/utils/formatValues.ts +0 -14
- package/src/repository/validator.ts +0 -119
- package/src/repository/value.ts +0 -116
- package/src/scopes/filter.ts +0 -100
- package/src/scopes/helpers/filter.helpers.ts +0 -227
- package/src/scopes/index.ts +0 -6
- package/src/tests/api/test-api.ts +0 -40
- package/src/tests/functional/searching/index.ts +0 -39
- package/src/tests/helpers/commonHooks.ts +0 -43
- package/src/tests/helpers/database-config.ts +0 -15
- package/src/tests/helpers/index.ts +0 -35
- package/src/tests/mocks/definition.mock.ts +0 -84
- package/src/tests/mocks/events.mock.ts +0 -21
- package/src/tests/mocks/testModel.ts +0 -37
- package/src/types/definition/index.ts +0 -24
- package/src/types/entries/index.ts +0 -27
- package/src/types/index.ts +0 -52
- package/src/types/value/index.ts +0 -14
- package/src/utils/constants/index.ts +0 -25
- package/src/utils/db/index.ts +0 -21
- package/src/utils/helpers/index.ts +0 -66
- package/src/utils/init.ts +0 -122
- package/src/utils/logger/index.ts +0 -14
- package/src/utils/scopeAttributes.ts +0 -12
- package/src/utils/validations/index.ts +0 -46
- package/src/utils/validations/schema/README.md +0 -93
- package/src/utils/validations/schema/custom-fields.ts +0 -8
- package/src/utils/validations/schema/validator-schema.ts +0 -106
- package/src/utils/validations/type.ts +0 -20
- package/src/utils/validations/validators/index.ts +0 -38
- package/src/utils/validations/validators/select.validator.ts +0 -12
- package/src/utils/validations/validators/status.validator.ts +0 -22
- package/tsconfig.build.json +0 -7
- package/tsconfig.json +0 -16
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { TestModel } from '../../models';
|
|
2
|
-
export declare const createTestModel: (payload?: {}) => Promise<TestModel>;
|
|
3
|
-
export declare const createTestModels: (fleetId: any, total: number) => Promise<TestModel[]>;
|
|
4
|
-
export declare const upsertTestModel: (payload: any) => Promise<[TestModel, boolean]>;
|
|
5
|
-
export declare const destroyTestModels: () => Promise<number>;
|
|
6
|
-
export declare const getTestModel: (id: string, options?: {}) => Promise<TestModel | null>;
|
|
7
|
-
export declare const getSomeTestModels: (options?: {
|
|
8
|
-
limit: number;
|
|
9
|
-
}) => Promise<TestModel[]>;
|
|
10
|
-
export declare const updateTestModel: (payload: any, query: any) => Promise<[affectedCount: number, affectedRows: TestModel[]]>;
|
|
11
|
-
export declare const createTestModelWithAssociation: () => Promise<TestModel>;
|
|
12
|
-
export declare const getTestModelWithAssociation: (limit?: number) => Promise<TestModel[]>;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTestModelWithAssociation = exports.createTestModelWithAssociation = exports.updateTestModel = exports.getSomeTestModels = exports.getTestModel = exports.destroyTestModels = exports.upsertTestModel = exports.createTestModels = exports.createTestModel = void 0;
|
|
4
|
-
const models_1 = require("../../models");
|
|
5
|
-
const createTestModel = (payload = {}) => models_1.TestModel.create(payload);
|
|
6
|
-
exports.createTestModel = createTestModel;
|
|
7
|
-
const createTestModels = (fleetId, total) => {
|
|
8
|
-
const models = [];
|
|
9
|
-
for (let i = 0; i < total; i += 1) {
|
|
10
|
-
models.push((0, exports.createTestModel)({ fleetId }));
|
|
11
|
-
}
|
|
12
|
-
return Promise.all(models);
|
|
13
|
-
};
|
|
14
|
-
exports.createTestModels = createTestModels;
|
|
15
|
-
const upsertTestModel = (payload) => models_1.TestModel.upsert(payload);
|
|
16
|
-
exports.upsertTestModel = upsertTestModel;
|
|
17
|
-
const destroyTestModels = () => models_1.TestModel.destroy({ truncate: true });
|
|
18
|
-
exports.destroyTestModels = destroyTestModels;
|
|
19
|
-
const getTestModel = (id, options = {}) => models_1.TestModel.findByPk(id, options);
|
|
20
|
-
exports.getTestModel = getTestModel;
|
|
21
|
-
const getSomeTestModels = (options = { limit: 1 }) => models_1.TestModel.findAll(options);
|
|
22
|
-
exports.getSomeTestModels = getSomeTestModels;
|
|
23
|
-
const updateTestModel = (payload, query) => models_1.TestModel.update(payload, query);
|
|
24
|
-
exports.updateTestModel = updateTestModel;
|
|
25
|
-
// Associations
|
|
26
|
-
const createTestModelWithAssociation = async () => {
|
|
27
|
-
const model = await models_1.TestModel.create({});
|
|
28
|
-
await models_1.AssociatedTestModel.create({ testModelId: model.id });
|
|
29
|
-
return model;
|
|
30
|
-
};
|
|
31
|
-
exports.createTestModelWithAssociation = createTestModelWithAssociation;
|
|
32
|
-
const getTestModelWithAssociation = (limit = 1) => models_1.TestModel.findAll({
|
|
33
|
-
limit, include: [models_1.AssociatedTestModel],
|
|
34
|
-
});
|
|
35
|
-
exports.getTestModelWithAssociation = getTestModelWithAssociation;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export interface CustomFieldDefinitionDTO {
|
|
2
|
-
id: string;
|
|
3
|
-
name: string;
|
|
4
|
-
displayName?: string;
|
|
5
|
-
validation?: any;
|
|
6
|
-
defaultValue?: any;
|
|
7
|
-
fieldType: string;
|
|
8
|
-
entityId: string;
|
|
9
|
-
entityType: string;
|
|
10
|
-
modelType: string;
|
|
11
|
-
required?: boolean;
|
|
12
|
-
description?: string;
|
|
13
|
-
disabled?: boolean;
|
|
14
|
-
createdAt?: Date;
|
|
15
|
-
updatedAt?: Date;
|
|
16
|
-
deletedAt?: Date;
|
|
17
|
-
blockEditingFromUI?: boolean;
|
|
18
|
-
}
|
|
19
|
-
export type CreateCustomFieldDefinition = Omit<CustomFieldDefinitionDTO, 'id'>;
|
|
20
|
-
export type UpdateCustomFieldDefinition = Partial<CreateCustomFieldDefinition>;
|
|
21
|
-
export type SerializedCustomFields = {
|
|
22
|
-
[name: string]: CustomFieldDefinitionDTO & {
|
|
23
|
-
value: any;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { ValidationError } from 'joi';
|
|
2
|
-
export interface CustomFieldEntriesDTO {
|
|
3
|
-
modelId: string;
|
|
4
|
-
entityId: string;
|
|
5
|
-
modelType: string;
|
|
6
|
-
/**
|
|
7
|
-
* A collection of custom fields where each key is the name of a CustomFieldDefinition and
|
|
8
|
-
* each value is the value of that custom field for this specific `modelId`.
|
|
9
|
-
*
|
|
10
|
-
* Example:
|
|
11
|
-
* {
|
|
12
|
-
* "vehicleColor": "Red",
|
|
13
|
-
* "vehicleType": "premium",
|
|
14
|
-
* "isActive": true
|
|
15
|
-
* }
|
|
16
|
-
*/
|
|
17
|
-
customFields: Record<string, any>;
|
|
18
|
-
createdAt?: Date;
|
|
19
|
-
updatedAt?: Date;
|
|
20
|
-
}
|
|
21
|
-
export interface EntriesValidationError {
|
|
22
|
-
value: any;
|
|
23
|
-
fieldDefinitionName: string;
|
|
24
|
-
joiValidationError: ValidationError;
|
|
25
|
-
}
|
package/dist/types/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface CustomFieldValueDTO {
|
|
2
|
-
id?: string;
|
|
3
|
-
modelId: string;
|
|
4
|
-
customFieldDefinitionId: string;
|
|
5
|
-
value: any;
|
|
6
|
-
createdAt?: Date;
|
|
7
|
-
updatedAt?: Date;
|
|
8
|
-
deletedAt?: Date;
|
|
9
|
-
}
|
|
10
|
-
export type ValuesToUpdate = {
|
|
11
|
-
[name: string]: any;
|
|
12
|
-
};
|
|
13
|
-
export type CreateCustomFieldValue = Omit<CustomFieldValueDTO, 'id'>;
|
|
14
|
-
export type UpdateCustomFieldValue = ValuesToUpdate;
|
|
15
|
-
export type BulkUpdateCustomFieldValue = Partial<CustomFieldValueDTO>[];
|
package/dist/utils/db/index.d.ts
DELETED
package/dist/utils/init.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { CustomFieldOptions, ModelFetcher, Models } from '../types';
|
|
2
|
-
export declare const addHooks: (models: Models[], getModel: ModelFetcher, sadotOptions?: {
|
|
3
|
-
useCustomFieldsEntries: boolean;
|
|
4
|
-
}) => void;
|
|
5
|
-
export declare const removeHooks: (models: Models[], getModel: ModelFetcher) => void;
|
|
6
|
-
export declare const addScopes: (models: Models[], getModel: ModelFetcher, options?: Pick<CustomFieldOptions, 'useCustomFieldsEntries'>) => void;
|
|
7
|
-
export declare const applyCustomAssociation: (models: Models[]) => void;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { CustomFieldDefinition } from '../../models';
|
|
2
|
-
import type { CustomFieldEntriesDTO } from '../../types/entries';
|
|
3
|
-
import type { CustomFieldDefinitionType } from '../constants';
|
|
4
|
-
export declare const validateFieldType: (type: CustomFieldDefinitionType) => boolean;
|
|
5
|
-
export declare const validateValue: (value: unknown, valueType: CustomFieldDefinitionType, validation?: unknown) => import("joi").ValidationResult;
|
|
6
|
-
export declare const validateInstanceCustomFieldEntries: (instance: CustomFieldEntriesDTO, definitionsByName: {
|
|
7
|
-
[defName: string]: CustomFieldDefinition;
|
|
8
|
-
}) => void;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validates that a given schema is a valid Ajv schema
|
|
3
|
-
* This function is used to validate schemas passed to custom validators
|
|
4
|
-
*
|
|
5
|
-
* @param schema The schema to validate
|
|
6
|
-
* @returns true if valid, throws an error if invalid
|
|
7
|
-
*/
|
|
8
|
-
export declare const validateValidatorSchema: (schema: Record<string, unknown>) => boolean;
|
|
9
|
-
export default validateValidatorSchema;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { ValidationResult } from 'joi';
|
|
2
|
-
import type { CustomFieldDefinitionType } from '../constants';
|
|
3
|
-
/**
|
|
4
|
-
* Validator is a function that validates a custom-field `value`,
|
|
5
|
-
* against a custom-field definition `validation object`.
|
|
6
|
-
* @returns `true` if the value is valid, `false` otherwise.
|
|
7
|
-
*/
|
|
8
|
-
export type Validator<Value, DefinitionValidationObject> = (value: Value, validation?: DefinitionValidationObject) => ValidationResult;
|
|
9
|
-
/**
|
|
10
|
-
* Validators is a map of custom-field types to their respective validators.
|
|
11
|
-
* The key is the custom-field type, and the value is the validator function.
|
|
12
|
-
*/
|
|
13
|
-
export type Validators = {
|
|
14
|
-
[K in CustomFieldDefinitionType]: Validator<unknown, unknown>;
|
|
15
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { CustomFieldDefinitionType } from '../../constants';
|
|
2
|
-
import type { Validators } from '../type';
|
|
3
|
-
/**
|
|
4
|
-
* Custom field types that must have custom validation.
|
|
5
|
-
* TODO: remove this after moving to schema-based validation
|
|
6
|
-
*/
|
|
7
|
-
export declare const CustomValidationTypes: {
|
|
8
|
-
readonly select: CustomFieldDefinitionType.SELECT;
|
|
9
|
-
readonly status: CustomFieldDefinitionType.STATUS;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Validators for custom fields
|
|
13
|
-
*/
|
|
14
|
-
export declare const validators: Validators;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Validator } from '../type';
|
|
2
|
-
type StatusColor = string | null;
|
|
3
|
-
type StatusValue = string;
|
|
4
|
-
type StatusOption = {
|
|
5
|
-
value: StatusValue;
|
|
6
|
-
color: StatusColor;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Validate that the value is one of the status values
|
|
10
|
-
*/
|
|
11
|
-
export declare const validateStatus: Validator<StatusValue, StatusOption[]>;
|
|
12
|
-
export {};
|
package/src/api/index.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { ResourceNotFoundError } from '@autofleet/errors';
|
|
2
|
-
import { Router } from '@autofleet/node-common';
|
|
3
|
-
import handleError from '../errors';
|
|
4
|
-
import * as DefinitionRepo from '../../../repository/definition';
|
|
5
|
-
import type { CreateCustomFieldDefinition, UpdateCustomFieldDefinition } from '../../../types/definition';
|
|
6
|
-
import { validateCustomFieldDefinitionCreation, validateCustomFieldDefinitionUpdate } from './validations';
|
|
7
|
-
import logger from '../../../utils/logger';
|
|
8
|
-
import type { CustomFieldDefinition } from '../../../models';
|
|
9
|
-
|
|
10
|
-
const router = Router({ logger });
|
|
11
|
-
const ENTITY = 'CustomFieldDefinition';
|
|
12
|
-
|
|
13
|
-
const toPascalCase = (str: string): string => str.replace(/(^\w|-\w)/g, (subStr) => subStr.replace(/-/, '').toUpperCase());
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Create
|
|
17
|
-
*/
|
|
18
|
-
router.post<{ modelName: string; }>('/', async (req, res) => {
|
|
19
|
-
const { modelName } = req.params;
|
|
20
|
-
const modelType = toPascalCase(modelName);
|
|
21
|
-
try {
|
|
22
|
-
const validatedPayload: CreateCustomFieldDefinition = await validateCustomFieldDefinitionCreation(req.body);
|
|
23
|
-
|
|
24
|
-
const customFieldDefinition = await DefinitionRepo.create({
|
|
25
|
-
...validatedPayload,
|
|
26
|
-
modelType,
|
|
27
|
-
});
|
|
28
|
-
return res.status(201).json(customFieldDefinition);
|
|
29
|
-
} catch (err) {
|
|
30
|
-
logger.error('Failed to create custom field definition', err);
|
|
31
|
-
return handleError(err, res, { logger, message: `Error in create ${ENTITY} request` });
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Get by id
|
|
37
|
-
*/
|
|
38
|
-
router.get<{ modelName: string; customFieldDefinitionId: string; }, CustomFieldDefinition>('/:customFieldDefinitionId', async (req, res) => {
|
|
39
|
-
const { customFieldDefinitionId } = req.params;
|
|
40
|
-
try {
|
|
41
|
-
const customFieldDefinition = await DefinitionRepo.findById(customFieldDefinitionId);
|
|
42
|
-
|
|
43
|
-
if (!customFieldDefinition) {
|
|
44
|
-
throw new ResourceNotFoundError();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return res.json(customFieldDefinition);
|
|
48
|
-
} catch (err) {
|
|
49
|
-
logger.error('Failed to fetch custom field definition', err);
|
|
50
|
-
return handleError(err, res, { logger, message: `Error in get ${ENTITY} request` });
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Get all
|
|
56
|
-
*/
|
|
57
|
-
router.get<{ modelName: string; }, CustomFieldDefinition[], never, { entityIds?: string[]; }>('/', async (req, res) => {
|
|
58
|
-
const { params: { modelName }, query: { entityIds } } = req;
|
|
59
|
-
|
|
60
|
-
const modelType = toPascalCase(modelName);
|
|
61
|
-
try {
|
|
62
|
-
const where = {
|
|
63
|
-
modelType,
|
|
64
|
-
...(entityIds?.length > 0 && { entityId: entityIds }),
|
|
65
|
-
};
|
|
66
|
-
const customFieldDefinitions = await DefinitionRepo.findAll(where, { withDisabled: true });
|
|
67
|
-
return res.json(customFieldDefinitions);
|
|
68
|
-
} catch (err) {
|
|
69
|
-
logger.error('Failed to fetch custom field definitions', err);
|
|
70
|
-
return handleError(err, res, { logger, message: `Error in get all ${ENTITY} request` });
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Update
|
|
76
|
-
*/
|
|
77
|
-
router.patch<{ modelName: string; customFieldDefinitionId: string; }, CustomFieldDefinition>('/:customFieldDefinitionId', async (req, res) => {
|
|
78
|
-
const { customFieldDefinitionId, modelName } = req.params;
|
|
79
|
-
const modelType = toPascalCase(modelName);
|
|
80
|
-
try {
|
|
81
|
-
const validatedPayload: UpdateCustomFieldDefinition = await validateCustomFieldDefinitionUpdate(req.body);
|
|
82
|
-
|
|
83
|
-
const customFieldDefinition = await DefinitionRepo.findByWhere({
|
|
84
|
-
id: customFieldDefinitionId,
|
|
85
|
-
modelType,
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
if (!customFieldDefinition) {
|
|
89
|
-
throw new ResourceNotFoundError();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const updatedCustomFieldDefinition = await DefinitionRepo.update(
|
|
93
|
-
customFieldDefinitionId,
|
|
94
|
-
{ ...validatedPayload, modelType },
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
return res.status(200).json(updatedCustomFieldDefinition);
|
|
98
|
-
} catch (err) {
|
|
99
|
-
logger.error('Failed to patch custom field definition', err);
|
|
100
|
-
return handleError(err, res, { logger, message: `Error in update ${ENTITY} request` });
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
export default router;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/* eslint-disable newline-per-chained-call */
|
|
2
|
-
import Joi from 'joi';
|
|
3
|
-
import { CustomFieldDefinitionType } from '../../../utils/constants';
|
|
4
|
-
|
|
5
|
-
const FileValidationSchema = Joi.object({
|
|
6
|
-
name: Joi.string().required(),
|
|
7
|
-
type: Joi.string(),
|
|
8
|
-
size: Joi.string(),
|
|
9
|
-
addedBy: Joi.string().uuid(),
|
|
10
|
-
});
|
|
11
|
-
const statusValidationObject = Joi.object({
|
|
12
|
-
value: Joi.string().required(),
|
|
13
|
-
color: Joi.string().required(),
|
|
14
|
-
});
|
|
15
|
-
/**
|
|
16
|
-
* Schema for the validation of custom field definition
|
|
17
|
-
* The only custom validation is for
|
|
18
|
-
* {@link CustomFieldDefinitionType.SELECT SELECT}
|
|
19
|
-
* and
|
|
20
|
-
* {@link CustomFieldDefinitionType.STATUS STATUS}
|
|
21
|
-
* field types.
|
|
22
|
-
* The rest of the field types are validated by Joi
|
|
23
|
-
*/
|
|
24
|
-
const ValidationSchema = Joi.when('fieldType', {
|
|
25
|
-
is: CustomFieldDefinitionType.SELECT,
|
|
26
|
-
then: Joi.array().required().items(Joi.string()).min(1).unique(),
|
|
27
|
-
otherwise: Joi.when('fieldType', {
|
|
28
|
-
is: CustomFieldDefinitionType.STATUS,
|
|
29
|
-
then: Joi.array().required().items(statusValidationObject).min(1).unique('value'),
|
|
30
|
-
otherwise: Joi.forbidden(),
|
|
31
|
-
}),
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const DefaultValueSchema = Joi.when('fieldType', {
|
|
35
|
-
switch: [
|
|
36
|
-
{ is: CustomFieldDefinitionType.BOOLEAN, then: Joi.boolean().allow(null) },
|
|
37
|
-
{ is: CustomFieldDefinitionType.DATE, then: Joi.date().allow(null) },
|
|
38
|
-
{ is: CustomFieldDefinitionType.DATETIME, then: Joi.date().allow(null) },
|
|
39
|
-
{ is: CustomFieldDefinitionType.FILE, then: Joi.array().items(FileValidationSchema).allow(null) },
|
|
40
|
-
{ is: CustomFieldDefinitionType.IMAGE, then: Joi.array().items(Joi.string().uri()).allow(null) },
|
|
41
|
-
{ is: CustomFieldDefinitionType.NUMBER, then: Joi.number().allow(null) },
|
|
42
|
-
{ is: CustomFieldDefinitionType.SELECT, then: Joi.string().allow(null) },
|
|
43
|
-
{ is: CustomFieldDefinitionType.STATUS, then: Joi.string().allow(null) },
|
|
44
|
-
{ is: CustomFieldDefinitionType.TEXT, then: Joi.string().allow(null) },
|
|
45
|
-
],
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const CustomFieldDefinitionCreationSchema = Joi.object({
|
|
49
|
-
name: Joi.string().required(),
|
|
50
|
-
displayName: Joi.string().required(),
|
|
51
|
-
validation: ValidationSchema,
|
|
52
|
-
defaultValue: DefaultValueSchema,
|
|
53
|
-
fieldType: Joi.string().valid(...Object.values(CustomFieldDefinitionType)).required(),
|
|
54
|
-
entityId: Joi.string().guid().required(),
|
|
55
|
-
entityType: Joi.string().required(),
|
|
56
|
-
description: Joi.string(),
|
|
57
|
-
required: Joi.boolean(),
|
|
58
|
-
disabled: Joi.boolean(),
|
|
59
|
-
blockEditingFromUI: Joi.boolean(),
|
|
60
|
-
}).oxor('required', 'blockEditingFromUI', { isPresent: (value) => value === true });
|
|
61
|
-
|
|
62
|
-
const CustomFieldDefinitionUpdateSchema = Joi.object({
|
|
63
|
-
displayName: Joi.string(),
|
|
64
|
-
validation: ValidationSchema,
|
|
65
|
-
defaultValue: DefaultValueSchema,
|
|
66
|
-
fieldType: Joi.string().valid(...Object.values(CustomFieldDefinitionType)),
|
|
67
|
-
description: Joi.string().allow(null),
|
|
68
|
-
required: Joi.boolean(),
|
|
69
|
-
disabled: Joi.boolean(),
|
|
70
|
-
blockEditingFromUI: Joi.boolean(),
|
|
71
|
-
}).oxor('required', 'blockEditingFromUI', { isPresent: (value) => value === true });
|
|
72
|
-
|
|
73
|
-
export const validateCustomFieldDefinitionCreation = (payload) => CustomFieldDefinitionCreationSchema.validateAsync(payload, { abortEarly: false });
|
|
74
|
-
|
|
75
|
-
export const validateCustomFieldDefinitionUpdate = (payload) => CustomFieldDefinitionUpdateSchema.validateAsync(payload, { abortEarly: false });
|
package/src/api/v1/errors.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Response } from 'express';
|
|
2
|
-
import { handleError, BadRequest, type LogPayload } from '@autofleet/errors';
|
|
3
|
-
import { ValidationError as InputValidationError } from 'joi';
|
|
4
|
-
import { ValidationError as DatabaseValidationError } from 'sequelize';
|
|
5
|
-
|
|
6
|
-
export default (err, res: Response, additionalData: LogPayload = undefined) => {
|
|
7
|
-
let error = err;
|
|
8
|
-
if ([InputValidationError, DatabaseValidationError].some((ErrClass) => err instanceof ErrClass)) {
|
|
9
|
-
error = new BadRequest([err], null);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return handleError(error, res, additionalData);
|
|
13
|
-
};
|
package/src/api/v1/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Router } from '@autofleet/node-common';
|
|
2
|
-
import logger from '../../utils/logger';
|
|
3
|
-
import definitionRouter from './definition';
|
|
4
|
-
import validatorRouter from './validator';
|
|
5
|
-
|
|
6
|
-
const router = Router({ logger });
|
|
7
|
-
|
|
8
|
-
router.use('/custom-field-definitions/:modelName', definitionRouter);
|
|
9
|
-
router.use('/custom-validators/:modelName', validatorRouter);
|
|
10
|
-
|
|
11
|
-
export default router;
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { ResourceNotFoundError } from '@autofleet/errors';
|
|
2
|
-
import { Router } from '@autofleet/node-common';
|
|
3
|
-
import { StatusCodes } from 'http-status-codes';
|
|
4
|
-
import handleError from '../errors';
|
|
5
|
-
import * as ValidatorRepo from '../../../repository/validator';
|
|
6
|
-
import validations from './validations';
|
|
7
|
-
import logger from '../../../utils/logger';
|
|
8
|
-
import { validateValidatorSchema } from '../../../utils/validations/schema/validator-schema';
|
|
9
|
-
import type { CustomValidator } from '../../../models';
|
|
10
|
-
|
|
11
|
-
const router = Router({ logger });
|
|
12
|
-
const ENTITY = 'CustomValidator';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Create
|
|
16
|
-
*/
|
|
17
|
-
router.post<{ modelName: string }>('/', async (req, res) => {
|
|
18
|
-
const { modelName } = req.params;
|
|
19
|
-
try {
|
|
20
|
-
// Validate the request body
|
|
21
|
-
const validatedPayload = await validations.create.validateAsync(req.body);
|
|
22
|
-
|
|
23
|
-
// Validate that the schema is a valid AJV schema
|
|
24
|
-
validateValidatorSchema(validatedPayload.schema);
|
|
25
|
-
|
|
26
|
-
const validator = await ValidatorRepo.create({
|
|
27
|
-
...validatedPayload,
|
|
28
|
-
modelType: modelName,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
return res.status(StatusCodes.CREATED).json(validator);
|
|
32
|
-
} catch (err) {
|
|
33
|
-
return handleError(err, res, { logger, message: `Error in create ${ENTITY} request` });
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Get all
|
|
39
|
-
*/
|
|
40
|
-
router.get<
|
|
41
|
-
{ modelName: string },
|
|
42
|
-
{ validators: CustomValidator[] },
|
|
43
|
-
never,
|
|
44
|
-
{ entityId?: string; entityType?: string }
|
|
45
|
-
>('/', async (req, res) => {
|
|
46
|
-
try {
|
|
47
|
-
const { modelName } = req.params;
|
|
48
|
-
const { entityId, entityType } = req.query;
|
|
49
|
-
|
|
50
|
-
const where = {
|
|
51
|
-
modelType: modelName,
|
|
52
|
-
...(entityId && { entityId }),
|
|
53
|
-
...(entityType && { entityType }),
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const validators = await ValidatorRepo.findAll(where);
|
|
57
|
-
|
|
58
|
-
return res.status(StatusCodes.OK).json({ validators });
|
|
59
|
-
} catch (err) {
|
|
60
|
-
return handleError(err, res, { logger, message: `Error in get all ${ENTITY} request` });
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Get by id
|
|
66
|
-
*/
|
|
67
|
-
router.get<{ modelName: string; validatorId: string }, CustomValidator>('/:validatorId', async (req, res) => {
|
|
68
|
-
try {
|
|
69
|
-
const { validatorId, modelName } = req.params;
|
|
70
|
-
// Include disabled validators when fetching by ID
|
|
71
|
-
const validators = await ValidatorRepo.findAll({ id: validatorId, modelType: modelName }, { withDisabled: true });
|
|
72
|
-
|
|
73
|
-
if (!validators.length) {
|
|
74
|
-
throw new ResourceNotFoundError('Validator not found');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return res.status(StatusCodes.OK).json(validators[0]);
|
|
78
|
-
} catch (err) {
|
|
79
|
-
return handleError(err, res, { logger, message: `Error in get ${ENTITY} request` });
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Update
|
|
85
|
-
*/
|
|
86
|
-
router.patch<{ modelName: string; validatorId: string }, CustomValidator>('/:validatorId', async (req, res) => {
|
|
87
|
-
try {
|
|
88
|
-
const { validatorId } = req.params;
|
|
89
|
-
|
|
90
|
-
// Validate the request body
|
|
91
|
-
const validatedPayload = await validations.update.validateAsync(req.body);
|
|
92
|
-
|
|
93
|
-
// If schema is included in the update, validate that it's a valid AJV schema
|
|
94
|
-
if (validatedPayload.schema) {
|
|
95
|
-
validateValidatorSchema(validatedPayload.schema);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// First verify the validator exists, including disabled ones
|
|
99
|
-
const existingValidators = await ValidatorRepo.findAll({ id: validatorId }, { withDisabled: true });
|
|
100
|
-
if (!existingValidators.length) {
|
|
101
|
-
throw new ResourceNotFoundError('Validator not found');
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const [count, validators] = await ValidatorRepo.update(validatorId, validatedPayload);
|
|
105
|
-
|
|
106
|
-
if (!count) {
|
|
107
|
-
throw new ResourceNotFoundError('Validator not found');
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return res.status(StatusCodes.OK).json(validators[0]);
|
|
111
|
-
} catch (err) {
|
|
112
|
-
return handleError(err, res, { logger, message: `Error in update ${ENTITY} request` });
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Delete (disable)
|
|
118
|
-
*/
|
|
119
|
-
router.delete<{ modelName: string; validatorId: string }>('/:validatorId', async (req, res) => {
|
|
120
|
-
try {
|
|
121
|
-
const { validatorId } = req.params;
|
|
122
|
-
|
|
123
|
-
// First verify the validator exists, including disabled ones
|
|
124
|
-
const existingValidators = await ValidatorRepo.findAll({ id: validatorId }, { withDisabled: true });
|
|
125
|
-
if (!existingValidators.length) {
|
|
126
|
-
throw new ResourceNotFoundError('Validator not found');
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const [count] = await ValidatorRepo.disable(validatorId);
|
|
130
|
-
|
|
131
|
-
if (!count) {
|
|
132
|
-
throw new ResourceNotFoundError('Validator failed to be disabled');
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return res.status(StatusCodes.NO_CONTENT).send();
|
|
136
|
-
} catch (err) {
|
|
137
|
-
return handleError(err, res, { logger, message: `Error in delete ${ENTITY} request` });
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
export default router;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import Joi from 'joi';
|
|
2
|
-
|
|
3
|
-
const jsonSchemaValidation = Joi.object().unknown(true);
|
|
4
|
-
|
|
5
|
-
const schemaObject = Joi.object({
|
|
6
|
-
type: Joi.string().valid('object'),
|
|
7
|
-
properties: Joi.object({
|
|
8
|
-
before: jsonSchemaValidation,
|
|
9
|
-
after: jsonSchemaValidation,
|
|
10
|
-
}).required(),
|
|
11
|
-
required: Joi.array().items(Joi.string()),
|
|
12
|
-
allOf: Joi.array().items(Joi.object()),
|
|
13
|
-
anyOf: Joi.array().items(Joi.object()),
|
|
14
|
-
oneOf: Joi.array().items(Joi.object()),
|
|
15
|
-
additionalProperties: Joi.alternatives().try(Joi.boolean(), Joi.object()),
|
|
16
|
-
$id: Joi.string(),
|
|
17
|
-
$schema: Joi.string(),
|
|
18
|
-
if: Joi.object(),
|
|
19
|
-
then: Joi.object(),
|
|
20
|
-
else: Joi.object(),
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const validationSchemas = {
|
|
24
|
-
create: Joi.object({
|
|
25
|
-
entityId: Joi.string().uuid().required(),
|
|
26
|
-
entityType: Joi.string().required(),
|
|
27
|
-
schema: schemaObject.required(),
|
|
28
|
-
}),
|
|
29
|
-
|
|
30
|
-
update: Joi.object({
|
|
31
|
-
entityId: Joi.string().uuid(),
|
|
32
|
-
entityType: Joi.string(),
|
|
33
|
-
schema: schemaObject,
|
|
34
|
-
disabled: Joi.boolean(),
|
|
35
|
-
}).min(1),
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export default validationSchemas;
|