@autofleet/sadot 0.6.2-temp-file-4 → 0.6.2
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/.env +3 -0
- package/dist/api/v1/definition/validations.d.ts +2 -2
- package/dist/api/v1/definition/validations.js +6 -19
- package/dist/api/v1/errors.js +1 -1
- package/dist/hooks/create.d.ts +1 -2
- package/dist/hooks/create.js +4 -8
- package/dist/hooks/enrich.d.ts +1 -3
- package/dist/hooks/enrich.js +4 -22
- package/dist/hooks/update.d.ts +1 -2
- package/dist/hooks/update.js +3 -4
- package/dist/index.d.ts +2 -3
- package/dist/index.js +1 -3
- package/dist/models/CustomFieldDefinition.d.ts +1 -1
- package/dist/models/CustomFieldDefinition.js +6 -11
- package/dist/models/CustomFieldValue.js +8 -3
- package/dist/models/index.d.ts +1 -3
- package/dist/models/index.js +2 -8
- package/dist/repository/definition.d.ts +4 -7
- package/dist/repository/definition.js +15 -27
- package/dist/repository/value.d.ts +2 -6
- package/dist/repository/value.js +3 -13
- package/dist/scopes/filter.d.ts +1 -1
- package/dist/scopes/filter.js +4 -16
- package/dist/tests/helpers/database-config.d.ts +0 -1
- package/dist/tests/helpers/database-config.js +0 -1
- package/dist/tests/helpers/index.js +0 -2
- package/dist/tests/mocks/definition.mock.d.ts +3 -9
- package/dist/tests/mocks/definition.mock.js +10 -14
- package/dist/tests/mocks/testModel.d.ts +1 -1
- package/dist/types/index.d.ts +2 -20
- package/dist/utils/constants/index.d.ts +1 -18
- package/dist/utils/constants/index.js +3 -19
- package/dist/utils/init.d.ts +4 -5
- package/dist/utils/init.js +9 -16
- package/dist/utils/validations/custom-fields.d.ts +2 -0
- package/dist/utils/validations/{schema/custom-fields.js → custom-fields.js} +2 -1
- package/dist/utils/validations/custom.d.ts +15 -0
- package/dist/utils/validations/custom.js +42 -0
- package/dist/utils/validations/index.d.ts +2 -2
- package/dist/utils/validations/index.js +15 -15
- package/dist/utils/validations/type.d.ts +14 -10
- package/dist/utils/validations/type.js +48 -0
- package/dist/utils/validations/validators.d.ts +12 -0
- package/dist/utils/validations/validators.js +33 -0
- package/package.json +2 -2
- package/src/api/v1/definition/validations.ts +1 -1
- package/src/index.ts +1 -0
- package/src/models/CustomFieldDefinition.ts +7 -5
- package/src/utils/constants/index.ts +1 -15
- package/src/utils/helpers/index.ts +1 -1
- package/src/utils/validations/index.ts +1 -1
- package/src/utils/validations/type.ts +12 -13
- package/src/utils/validations/validators/index.ts +1 -11
- package/src/utils/validations/validators/select.validator.ts +3 -1
- package/src/utils/validations/validators/status.validator.ts +4 -2
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.d.ts +0 -10
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js +0 -55
- package/dist/models/tests/contextAwareModels/ContextTestModel.d.ts +0 -13
- package/dist/models/tests/contextAwareModels/ContextTestModel.js +0 -47
- package/dist/tests/functional/searching/index.d.ts +0 -8
- package/dist/tests/functional/searching/index.js +0 -44
- package/dist/utils/helpers/index.d.ts +0 -25
- package/dist/utils/helpers/index.js +0 -34
- package/dist/utils/scopeAttributes.d.ts +0 -2
- package/dist/utils/scopeAttributes.js +0 -11
- package/dist/utils/validations/schema/custom-fields.d.ts +0 -3
- package/dist/utils/validations/validators/index.d.ts +0 -14
- package/dist/utils/validations/validators/index.js +0 -41
- package/dist/utils/validations/validators/select.validator.d.ts +0 -5
- package/dist/utils/validations/validators/select.validator.js +0 -9
- package/dist/utils/validations/validators/status.validator.d.ts +0 -12
- package/dist/utils/validations/validators/status.validator.js +0 -9
|
@@ -6,6 +6,8 @@ import type { Validator } from '../type';
|
|
|
6
6
|
export const validateSelect: Validator<string, string[]> = (
|
|
7
7
|
value,
|
|
8
8
|
selectValues,
|
|
9
|
-
) => (
|
|
9
|
+
) => (selectValues
|
|
10
|
+
&& Array.isArray(selectValues)
|
|
11
|
+
&& selectValues.length > 0
|
|
10
12
|
&& selectValues.includes(value)
|
|
11
13
|
);
|
|
@@ -13,6 +13,8 @@ type StatusOption = {
|
|
|
13
13
|
export const validateStatus: Validator<StatusValue, StatusOption[]> = (
|
|
14
14
|
value,
|
|
15
15
|
statusValues,
|
|
16
|
-
) => (
|
|
17
|
-
&&
|
|
16
|
+
) => (statusValues
|
|
17
|
+
&& Array.isArray(statusValues)
|
|
18
|
+
&& statusValues.length > 0
|
|
19
|
+
&& statusValues.map((status) => status.value).includes(value)
|
|
18
20
|
);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Model } from 'sequelize-typescript';
|
|
2
|
-
import ContextTestModel from './ContextTestModel';
|
|
3
|
-
declare class ContextAwareTestModel extends Model {
|
|
4
|
-
id: string;
|
|
5
|
-
contextId: string;
|
|
6
|
-
coolAttribute?: boolean;
|
|
7
|
-
customFields?: any;
|
|
8
|
-
context: ContextTestModel;
|
|
9
|
-
}
|
|
10
|
-
export default ContextAwareTestModel;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
16
|
-
const sequelize_typescript_1 = require("sequelize-typescript");
|
|
17
|
-
const ContextTestModel_1 = __importDefault(require("./ContextTestModel"));
|
|
18
|
-
let ContextAwareTestModel = class ContextAwareTestModel extends sequelize_typescript_1.Model {
|
|
19
|
-
};
|
|
20
|
-
__decorate([
|
|
21
|
-
sequelize_typescript_1.PrimaryKey,
|
|
22
|
-
(0, sequelize_typescript_1.Column)({
|
|
23
|
-
type: sequelize_typescript_1.DataType.UUID,
|
|
24
|
-
defaultValue: sequelize_typescript_1.DataType.UUIDV4,
|
|
25
|
-
allowNull: false,
|
|
26
|
-
}),
|
|
27
|
-
__metadata("design:type", String)
|
|
28
|
-
], ContextAwareTestModel.prototype, "id", void 0);
|
|
29
|
-
__decorate([
|
|
30
|
-
(0, sequelize_typescript_1.ForeignKey)(() => ContextTestModel_1.default),
|
|
31
|
-
(0, sequelize_typescript_1.Column)({
|
|
32
|
-
type: sequelize_typescript_1.DataType.UUID,
|
|
33
|
-
}),
|
|
34
|
-
__metadata("design:type", String)
|
|
35
|
-
], ContextAwareTestModel.prototype, "contextId", void 0);
|
|
36
|
-
__decorate([
|
|
37
|
-
(0, sequelize_typescript_1.Column)({
|
|
38
|
-
type: sequelize_typescript_1.DataType.BOOLEAN,
|
|
39
|
-
}),
|
|
40
|
-
__metadata("design:type", Boolean)
|
|
41
|
-
], ContextAwareTestModel.prototype, "coolAttribute", void 0);
|
|
42
|
-
__decorate([
|
|
43
|
-
(0, sequelize_typescript_1.Column)({
|
|
44
|
-
type: sequelize_typescript_1.DataType.VIRTUAL,
|
|
45
|
-
}),
|
|
46
|
-
__metadata("design:type", Object)
|
|
47
|
-
], ContextAwareTestModel.prototype, "customFields", void 0);
|
|
48
|
-
__decorate([
|
|
49
|
-
(0, sequelize_typescript_1.BelongsTo)(() => ContextTestModel_1.default),
|
|
50
|
-
__metadata("design:type", ContextTestModel_1.default)
|
|
51
|
-
], ContextAwareTestModel.prototype, "context", void 0);
|
|
52
|
-
ContextAwareTestModel = __decorate([
|
|
53
|
-
(0, sequelize_typescript_1.Table)({ createdAt: false, updatedAt: false })
|
|
54
|
-
], ContextAwareTestModel);
|
|
55
|
-
exports.default = ContextAwareTestModel;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Model } from 'sequelize-typescript';
|
|
2
|
-
declare enum EEntityTypes {
|
|
3
|
-
BUSINESS_MODEL = "businessModel",
|
|
4
|
-
CONTEXT = "context",
|
|
5
|
-
DEMAND_SOURCE = "demandSource",
|
|
6
|
-
FLEET = "fleet"
|
|
7
|
-
}
|
|
8
|
-
declare class ContextTestModel extends Model {
|
|
9
|
-
id: string;
|
|
10
|
-
entityId: string;
|
|
11
|
-
entityType: EEntityTypes;
|
|
12
|
-
}
|
|
13
|
-
export default ContextTestModel;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
13
|
-
const sequelize_typescript_1 = require("sequelize-typescript");
|
|
14
|
-
// eslint-disable-next-line no-shadow
|
|
15
|
-
var EEntityTypes;
|
|
16
|
-
(function (EEntityTypes) {
|
|
17
|
-
EEntityTypes["BUSINESS_MODEL"] = "businessModel";
|
|
18
|
-
EEntityTypes["CONTEXT"] = "context";
|
|
19
|
-
EEntityTypes["DEMAND_SOURCE"] = "demandSource";
|
|
20
|
-
EEntityTypes["FLEET"] = "fleet";
|
|
21
|
-
})(EEntityTypes || (EEntityTypes = {}));
|
|
22
|
-
let ContextTestModel = class ContextTestModel extends sequelize_typescript_1.Model {
|
|
23
|
-
};
|
|
24
|
-
__decorate([
|
|
25
|
-
sequelize_typescript_1.PrimaryKey,
|
|
26
|
-
(0, sequelize_typescript_1.Column)({
|
|
27
|
-
defaultValue: sequelize_typescript_1.DataType.UUIDV4,
|
|
28
|
-
type: sequelize_typescript_1.DataType.UUID,
|
|
29
|
-
}),
|
|
30
|
-
__metadata("design:type", String)
|
|
31
|
-
], ContextTestModel.prototype, "id", void 0);
|
|
32
|
-
__decorate([
|
|
33
|
-
(0, sequelize_typescript_1.Column)({
|
|
34
|
-
type: sequelize_typescript_1.DataType.UUID,
|
|
35
|
-
}),
|
|
36
|
-
__metadata("design:type", String)
|
|
37
|
-
], ContextTestModel.prototype, "entityId", void 0);
|
|
38
|
-
__decorate([
|
|
39
|
-
(0, sequelize_typescript_1.Column)({
|
|
40
|
-
type: sequelize_typescript_1.DataType.ENUM(...Object.values(EEntityTypes)),
|
|
41
|
-
}),
|
|
42
|
-
__metadata("design:type", String)
|
|
43
|
-
], ContextTestModel.prototype, "entityType", void 0);
|
|
44
|
-
ContextTestModel = __decorate([
|
|
45
|
-
(0, sequelize_typescript_1.Table)({ createdAt: false, updatedAt: false })
|
|
46
|
-
], ContextTestModel);
|
|
47
|
-
exports.default = ContextTestModel;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
interface CustomFieldsSearchTestFlowInput {
|
|
2
|
-
fieldType: string;
|
|
3
|
-
fieldValue: string | number;
|
|
4
|
-
searchTerm: string;
|
|
5
|
-
expectedNumberOfQueryResults: number;
|
|
6
|
-
}
|
|
7
|
-
declare const customFieldsSearchTestFlow: ({ fieldType, fieldValue, searchTerm, expectedNumberOfQueryResults, }: CustomFieldsSearchTestFlowInput) => Promise<void>;
|
|
8
|
-
export default customFieldsSearchTestFlow;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const index_1 = require("../../../index");
|
|
27
|
-
const DefinitionRepo = __importStar(require("../../../repository/definition"));
|
|
28
|
-
const definition_mock_1 = require("../../mocks/definition.mock");
|
|
29
|
-
const testModel_1 = require("../../mocks/testModel");
|
|
30
|
-
const models_1 = require("../../../models");
|
|
31
|
-
const customFieldsSearchTestFlow = async ({ fieldType, fieldValue, searchTerm, expectedNumberOfQueryResults, }) => {
|
|
32
|
-
const definition = (0, definition_mock_1.createDefinition)({ fieldType, name: 'coolDefinition' });
|
|
33
|
-
await DefinitionRepo.create({ ...definition });
|
|
34
|
-
const [testModel1] = await (0, testModel_1.createTestModels)(definition.entityId, 2);
|
|
35
|
-
await testModel1.update({ customFields: { [definition.name]: fieldValue } });
|
|
36
|
-
const models = await models_1.TestModel.findAndCountAll({
|
|
37
|
-
...(0, index_1.generateCustomFieldSearchQueryPayload)(searchTerm, models_1.TestModel, definition.entityId),
|
|
38
|
-
});
|
|
39
|
-
expect(models.count).toBe(expectedNumberOfQueryResults);
|
|
40
|
-
if (expectedNumberOfQueryResults > 0) {
|
|
41
|
-
expect(models.rows[0].dataValues.id).toBe(testModel1.id);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
exports.default = customFieldsSearchTestFlow;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { type WhereOptions, type BindOrReplacements } from 'sequelize';
|
|
2
|
-
import { type ModelStatic } from 'sequelize-typescript';
|
|
3
|
-
import { CustomFieldDefinitionType } from '../constants';
|
|
4
|
-
/**
|
|
5
|
-
* Builds a WHERE clause and replacements for free-text search by custom fields.
|
|
6
|
-
*
|
|
7
|
-
* This function constructs a WHERE clause and replacement bindings that allow searching
|
|
8
|
-
* for a given term within custom fields associated with a specific model type and entity ID.
|
|
9
|
-
* The WHERE clause and replacements are designed to be added to the main query.
|
|
10
|
-
*
|
|
11
|
-
* @param {string} searchTerm - The term to search for within custom fields.
|
|
12
|
-
* @param {ModelStatic} model - The Sequelize model representing the entity type to search for.
|
|
13
|
-
* @param {string} entityId - The entity ID to filter the custom fields by.
|
|
14
|
-
* @param {CustomFieldDefinitionType[]} excludedCustomFieldsTypes - An array of custom field types
|
|
15
|
-
* to exclude from the search
|
|
16
|
-
*
|
|
17
|
-
* @returns {CustomFieldsSearchPayload} - An object containing the WHERE clause and replacements
|
|
18
|
-
* for Sequelize.
|
|
19
|
-
*/
|
|
20
|
-
interface CustomFieldsSearchPayload {
|
|
21
|
-
where: WhereOptions;
|
|
22
|
-
replacements: BindOrReplacements;
|
|
23
|
-
}
|
|
24
|
-
export declare const generateCustomFieldSearchQueryPayload: (searchTerm: string, model: ModelStatic, entityId: string, customFieldsTypesToExclude?: CustomFieldDefinitionType[]) => CustomFieldsSearchPayload;
|
|
25
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateCustomFieldSearchQueryPayload = void 0;
|
|
4
|
-
/* eslint-disable import/prefer-default-export */
|
|
5
|
-
const sequelize_1 = require("sequelize");
|
|
6
|
-
const sequelize_typescript_1 = require("sequelize-typescript");
|
|
7
|
-
const constants_1 = require("../constants");
|
|
8
|
-
const generateCustomFieldSearchQueryPayload = (searchTerm, model, entityId, customFieldsTypesToExclude = [
|
|
9
|
-
constants_1.CustomFieldDefinitionType.DATETIME,
|
|
10
|
-
constants_1.CustomFieldDefinitionType.DATE,
|
|
11
|
-
]) => {
|
|
12
|
-
const excludedTypesString = customFieldsTypesToExclude.map((type) => `'${type}'`).join(',');
|
|
13
|
-
const subQuery = 'EXISTS ('
|
|
14
|
-
+ ' SELECT 1'
|
|
15
|
-
+ ' FROM "custom_field_values" AS "cv"'
|
|
16
|
-
+ ' INNER JOIN custom_field_definitions AS cd '
|
|
17
|
-
+ ` ON cd.entity_id = '${entityId}'`
|
|
18
|
-
+ ' AND cv.custom_field_definition_id = cd.id'
|
|
19
|
-
+ ` AND cd.model_type = '${model.name}'`
|
|
20
|
-
+ ` ${excludedTypesString ? `AND cd.field_type NOT IN (${excludedTypesString})` : ''}`
|
|
21
|
-
+ ' WHERE'
|
|
22
|
-
+ ' "cv"."deleted_at" IS NULL'
|
|
23
|
-
+ ` AND "cv"."model_id" = "${model.name}"."id"`
|
|
24
|
-
+ ' AND CAST("cv"."value" AS TEXT) ILIKE :searchTerm)';
|
|
25
|
-
return {
|
|
26
|
-
where: {
|
|
27
|
-
[sequelize_1.Op.or]: [
|
|
28
|
-
sequelize_typescript_1.Sequelize.where(sequelize_typescript_1.Sequelize.literal(subQuery), true),
|
|
29
|
-
],
|
|
30
|
-
},
|
|
31
|
-
replacements: { searchTerm: `%${searchTerm}%` },
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
exports.generateCustomFieldSearchQueryPayload = generateCustomFieldSearchQueryPayload;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const mapAttributeToInstance = (scopeAttributes, instance) => scopeAttributes.map((attr) => instance[attr]);
|
|
4
|
-
const applyScopeToInstance = (instance, scopeAttributes) => {
|
|
5
|
-
const uniqueAttributes = Array.from(new Set(scopeAttributes));
|
|
6
|
-
if (Array.isArray(instance)) {
|
|
7
|
-
return instance.flatMap((ins) => mapAttributeToInstance(uniqueAttributes, ins));
|
|
8
|
-
}
|
|
9
|
-
return mapAttributeToInstance(uniqueAttributes, instance);
|
|
10
|
-
};
|
|
11
|
-
exports.default = applyScopeToInstance;
|
|
@@ -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,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.validators = exports.CustomValidationTypes = void 0;
|
|
7
|
-
const joi_1 = __importDefault(require("joi"));
|
|
8
|
-
const constants_1 = require("../../constants");
|
|
9
|
-
const select_validator_1 = require("./select.validator");
|
|
10
|
-
const status_validator_1 = require("./status.validator");
|
|
11
|
-
/**
|
|
12
|
-
* Custom field types that must have custom validation.
|
|
13
|
-
* TODO: remove this after moving to schema-based validation
|
|
14
|
-
*/
|
|
15
|
-
exports.CustomValidationTypes = {
|
|
16
|
-
[constants_1.CustomFieldDefinitionType.SELECT]: constants_1.CustomFieldDefinitionType.SELECT,
|
|
17
|
-
[constants_1.CustomFieldDefinitionType.STATUS]: constants_1.CustomFieldDefinitionType.STATUS,
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Validators for custom fields
|
|
21
|
-
*/
|
|
22
|
-
exports.validators = {
|
|
23
|
-
[constants_1.CustomFieldDefinitionType.SELECT]: select_validator_1.validateSelect,
|
|
24
|
-
[constants_1.CustomFieldDefinitionType.STATUS]: status_validator_1.validateStatus,
|
|
25
|
-
[constants_1.CustomFieldDefinitionType.TEXT]: (value) => (typeof value === 'string'),
|
|
26
|
-
[constants_1.CustomFieldDefinitionType.NUMBER]: (value) => (typeof value === 'number'),
|
|
27
|
-
[constants_1.CustomFieldDefinitionType.BOOLEAN]: (value) => (typeof value === 'boolean'),
|
|
28
|
-
[constants_1.CustomFieldDefinitionType.DATE]: (value) => (!joi_1.default.date().validate(value).error),
|
|
29
|
-
[constants_1.CustomFieldDefinitionType.DATETIME]: (value) => (!joi_1.default.date().validate(value).error),
|
|
30
|
-
[constants_1.CustomFieldDefinitionType.IMAGE]: (value) => (!joi_1.default.array().min(1).unique()
|
|
31
|
-
.items(joi_1.default.string().uri())
|
|
32
|
-
.validate(value).error),
|
|
33
|
-
[constants_1.CustomFieldDefinitionType.FILE]: (value) => (!joi_1.default.array().min(1).unique().items(joi_1.default.object({
|
|
34
|
-
id: joi_1.default.string().uuid().required(),
|
|
35
|
-
name: joi_1.default.string().required(),
|
|
36
|
-
link: joi_1.default.string().required(),
|
|
37
|
-
createdAt: joi_1.default.date(),
|
|
38
|
-
addedBy: joi_1.default.string().uuid(),
|
|
39
|
-
}))
|
|
40
|
-
.validate(value).error),
|
|
41
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateSelect = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Validate that the value is one of the select values
|
|
6
|
-
*/
|
|
7
|
-
const validateSelect = (value, selectValues) => (Array.isArray(selectValues)
|
|
8
|
-
&& selectValues.includes(value));
|
|
9
|
-
exports.validateSelect = validateSelect;
|
|
@@ -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 {};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateStatus = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Validate that the value is one of the status values
|
|
6
|
-
*/
|
|
7
|
-
const validateStatus = (value, statusValues) => (Array.isArray(statusValues)
|
|
8
|
-
&& statusValues.some((status) => status.value === value));
|
|
9
|
-
exports.validateStatus = validateStatus;
|