@autofleet/sadot 0.3.2 → 0.3.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/index.js +0 -1
- package/dist/api/v1/definition/index.js +19 -26
- package/dist/api/v1/definition/validations.js +0 -1
- package/dist/api/v1/errors.js +0 -1
- package/dist/api/v1/index.js +0 -1
- package/dist/errors/index.js +0 -1
- package/dist/events/index.js +1 -2
- package/dist/hooks/create.js +6 -16
- package/dist/hooks/enrich.js +23 -27
- package/dist/hooks/find.js +3 -5
- package/dist/hooks/index.js +0 -1
- package/dist/hooks/update.js +3 -13
- package/dist/hooks/workaround.js +3 -13
- package/dist/index.js +8 -18
- package/dist/models/CustomFieldDefinition.js +1 -2
- package/dist/models/CustomFieldValue.js +20 -34
- package/dist/models/index.js +13 -23
- package/dist/models/tests/AssociatedTestModel.js +0 -1
- package/dist/models/tests/TestModel.js +0 -1
- package/dist/repository/definition.js +19 -33
- package/dist/repository/value.js +18 -28
- package/dist/tests/api/test-api.js +12 -22
- package/dist/tests/helpers/database-config.d.ts +1 -1
- package/dist/tests/helpers/database-config.js +0 -1
- package/dist/tests/helpers/index.js +4 -14
- package/dist/tests/mocks/definition.mock.d.ts +14 -14
- package/dist/tests/mocks/definition.mock.js +18 -13
- package/dist/tests/mocks/events.mock.js +0 -1
- package/dist/tests/mocks/testModel.d.ts +1 -1
- package/dist/tests/mocks/testModel.js +4 -14
- package/dist/types/definition/index.js +0 -1
- package/dist/types/index.js +0 -1
- package/dist/types/value/index.js +0 -1
- package/dist/utils/constants/index.js +0 -1
- package/dist/utils/db/index.js +0 -1
- package/dist/utils/logger/index.js +0 -1
- package/dist/utils/validations/custom-fields.js +0 -1
- package/dist/utils/validations/custom.js +1 -2
- package/dist/utils/validations/index.js +0 -1
- package/dist/utils/validations/type.js +0 -1
- package/dist/utils/validations/validators.js +0 -1
- package/package.json +1 -2
- package/tsconfig.json +9 -26
- package/dist/api/index.js.map +0 -1
- package/dist/api/v1/definition/index.js.map +0 -1
- package/dist/api/v1/definition/validations.js.map +0 -1
- package/dist/api/v1/errors.js.map +0 -1
- package/dist/api/v1/index.js.map +0 -1
- package/dist/errors/index.js.map +0 -1
- package/dist/events/index.js.map +0 -1
- package/dist/hooks/create.js.map +0 -1
- package/dist/hooks/enrich.js.map +0 -1
- package/dist/hooks/find.js.map +0 -1
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/update.js.map +0 -1
- package/dist/hooks/workaround.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/models/CustomFieldDefinition.js.map +0 -1
- package/dist/models/CustomFieldValue.js.map +0 -1
- package/dist/models/index.js.map +0 -1
- package/dist/models/tests/AssociatedTestModel.js.map +0 -1
- package/dist/models/tests/TestModel.js.map +0 -1
- package/dist/repository/definition.js.map +0 -1
- package/dist/repository/value.js.map +0 -1
- package/dist/tests/api/test-api.js.map +0 -1
- package/dist/tests/helpers/database-config.js.map +0 -1
- package/dist/tests/helpers/index.js.map +0 -1
- package/dist/tests/mocks/definition.mock.js.map +0 -1
- package/dist/tests/mocks/events.mock.js.map +0 -1
- package/dist/tests/mocks/testModel.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types/definition/index.js.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/types/value/index.js.map +0 -1
- package/dist/utils/constants/index.js.map +0 -1
- package/dist/utils/db/index.js.map +0 -1
- package/dist/utils/logger/index.js.map +0 -1
- package/dist/utils/validations/custom-fields.js.map +0 -1
- package/dist/utils/validations/custom.js.map +0 -1
- package/dist/utils/validations/index.js.map +0 -1
- package/dist/utils/validations/type.js.map +0 -1
- package/dist/utils/validations/validators.js.map +0 -1
package/dist/models/index.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -29,7 +20,7 @@ const testModels = [TestModel_1.default, AssociatedTestModel_1.default];
|
|
|
29
20
|
const SADOT_MIGRATION_PREFIX = 'sadot-migration';
|
|
30
21
|
const SCHEMA_VERSION = 1;
|
|
31
22
|
const CUSTOM_FIELDS_SCHEMA_VERSION = `${SADOT_MIGRATION_PREFIX}_${SCHEMA_VERSION}`;
|
|
32
|
-
const initTables = (sequelize, getUser) =>
|
|
23
|
+
const initTables = async (sequelize, getUser) => {
|
|
33
24
|
logger_1.default.info('custom-fields: initialize custom-fields tables');
|
|
34
25
|
// Detect models and import them to the orm
|
|
35
26
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
@@ -39,7 +30,7 @@ const initTables = (sequelize, getUser) => __awaiter(void 0, void 0, void 0, fun
|
|
|
39
30
|
sequelize.addModels(productionModels);
|
|
40
31
|
CustomFieldDefinition_1.default.addScope('userScope', () => {
|
|
41
32
|
const user = getUser();
|
|
42
|
-
if (user
|
|
33
|
+
if (user?.permissions) {
|
|
43
34
|
return {
|
|
44
35
|
where: {
|
|
45
36
|
entityId: [
|
|
@@ -66,19 +57,19 @@ const initTables = (sequelize, getUser) => __awaiter(void 0, void 0, void 0, fun
|
|
|
66
57
|
timestamps: false,
|
|
67
58
|
schema: 'public',
|
|
68
59
|
});
|
|
69
|
-
const migrations =
|
|
60
|
+
const migrations = await SequelizeMeta.findAll({ raw: true });
|
|
70
61
|
const currentSadotSchemaVersion = migrations
|
|
71
62
|
.reverse().find((m) => m.name.includes(SADOT_MIGRATION_PREFIX));
|
|
72
63
|
if (!currentSadotSchemaVersion
|
|
73
64
|
|| currentSadotSchemaVersion.name !== CUSTOM_FIELDS_SCHEMA_VERSION) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
65
|
+
await CustomFieldDefinition_1.default.sync({ alter: true });
|
|
66
|
+
await CustomFieldValue_1.default.sync({ alter: true });
|
|
67
|
+
await SequelizeMeta.create({ name: CUSTOM_FIELDS_SCHEMA_VERSION });
|
|
77
68
|
logger_1.default.info('custom-fields: models synced');
|
|
78
69
|
}
|
|
79
|
-
}
|
|
70
|
+
};
|
|
80
71
|
exports.initTables = initTables;
|
|
81
|
-
const initTestModels = (sequelize) =>
|
|
72
|
+
const initTestModels = async (sequelize) => {
|
|
82
73
|
logger_1.default.info('custom-fields: initialize custom-fields test models');
|
|
83
74
|
// Detect models and import them to the orm
|
|
84
75
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
@@ -86,12 +77,11 @@ const initTestModels = (sequelize) => __awaiter(void 0, void 0, void 0, function
|
|
|
86
77
|
throw new Error('sequelize instance must have addModels function');
|
|
87
78
|
}
|
|
88
79
|
sequelize.addModels(testModels);
|
|
89
|
-
|
|
90
|
-
|
|
80
|
+
await sequelize.dropSchema('custom-fields', { logging: false });
|
|
81
|
+
await sequelize.createSchema('custom-fields', { logging: false });
|
|
91
82
|
logger_1.default.info('custom-fields: test models added');
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
await TestModel_1.default.sync({ alter: true });
|
|
84
|
+
await AssociatedTestModel_1.default.sync({ alter: true });
|
|
94
85
|
logger_1.default.info('custom-fields: test models synced');
|
|
95
|
-
}
|
|
86
|
+
};
|
|
96
87
|
exports.initTestModels = initTestModels;
|
|
97
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getRequiredFields = exports.destroy = exports.disable = exports.update = exports.findDefinitionsByModels = exports.findByWhere = exports.findByEntityIds = exports.findByEntityId = exports.findById = exports.findByIds = exports.findAll = exports.create = void 0;
|
|
13
4
|
const sequelize_1 = require("sequelize");
|
|
@@ -35,44 +26,40 @@ const findById = (id, options = { withDisabled: false }) => {
|
|
|
35
26
|
return models_1.CustomFieldDefinition.scope('userScope').findByPk(id);
|
|
36
27
|
};
|
|
37
28
|
exports.findById = findById;
|
|
38
|
-
const findByEntityId = (entityId, options = {}) =>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
transaction: options.transaction,
|
|
42
|
-
});
|
|
29
|
+
const findByEntityId = async (entityId, options = {}) => models_1.CustomFieldDefinition.findAll({
|
|
30
|
+
where: { entityId },
|
|
31
|
+
transaction: options.transaction,
|
|
43
32
|
});
|
|
44
33
|
exports.findByEntityId = findByEntityId;
|
|
45
|
-
const findByEntityIds = (modelType, entityIds, options = {}) =>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
raw: true,
|
|
53
|
-
});
|
|
34
|
+
const findByEntityIds = async (modelType, entityIds, options = {}) => models_1.CustomFieldDefinition.findAll({
|
|
35
|
+
where: {
|
|
36
|
+
modelType,
|
|
37
|
+
entityId: entityIds,
|
|
38
|
+
},
|
|
39
|
+
transaction: options.transaction,
|
|
40
|
+
raw: true,
|
|
54
41
|
});
|
|
55
42
|
exports.findByEntityIds = findByEntityIds;
|
|
56
43
|
const findByWhere = (where) => models_1.CustomFieldDefinition.scope('userScope').findOne({
|
|
57
44
|
where,
|
|
58
45
|
});
|
|
59
46
|
exports.findByWhere = findByWhere;
|
|
60
|
-
const findDefinitionsByModels = (modelTypes, options) =>
|
|
47
|
+
const findDefinitionsByModels = async (modelTypes, options) => {
|
|
61
48
|
const query = { modelType: { [sequelize_1.Op.in]: modelTypes } };
|
|
62
49
|
return models_1.CustomFieldDefinition.findAll({
|
|
63
50
|
where: query,
|
|
64
|
-
transaction: options
|
|
51
|
+
transaction: options?.transaction,
|
|
65
52
|
});
|
|
66
|
-
}
|
|
53
|
+
};
|
|
67
54
|
exports.findDefinitionsByModels = findDefinitionsByModels;
|
|
68
|
-
const update = (id, data) =>
|
|
69
|
-
const updatedDefinition = (
|
|
55
|
+
const update = async (id, data) => {
|
|
56
|
+
const updatedDefinition = (await models_1.CustomFieldDefinition.scope('userScope').update(data, {
|
|
70
57
|
where: { id },
|
|
71
58
|
returning: true,
|
|
72
59
|
individualHooks: true,
|
|
73
60
|
}))[1][0];
|
|
74
61
|
return updatedDefinition;
|
|
75
|
-
}
|
|
62
|
+
};
|
|
76
63
|
exports.update = update;
|
|
77
64
|
const disable = (id) => models_1.CustomFieldDefinition.update({ disabled: true }, { where: { id } });
|
|
78
65
|
exports.disable = disable;
|
|
@@ -81,14 +68,13 @@ exports.destroy = destroy;
|
|
|
81
68
|
/**
|
|
82
69
|
* Return the names of the required fields for a given model
|
|
83
70
|
*/
|
|
84
|
-
const getRequiredFields = (modelType, modelId, entityId) =>
|
|
71
|
+
const getRequiredFields = async (modelType, modelId, entityId) => {
|
|
85
72
|
const entityIds = Array.isArray(entityId) ? entityId : [entityId];
|
|
86
|
-
const requiredFields =
|
|
73
|
+
const requiredFields = await models_1.CustomFieldDefinition.findAll({
|
|
87
74
|
where: { required: true, modelType, entityId: { [sequelize_1.Op.in]: entityIds } },
|
|
88
75
|
logging: true,
|
|
89
76
|
});
|
|
90
77
|
const requiredFieldsNames = requiredFields.map((definition) => definition.name);
|
|
91
78
|
return [...new Set(requiredFieldsNames)];
|
|
92
|
-
}
|
|
79
|
+
};
|
|
93
80
|
exports.getRequiredFields = getRequiredFields;
|
|
94
|
-
//# sourceMappingURL=definition.js.map
|
package/dist/repository/value.js
CHANGED
|
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
27
|
};
|
|
@@ -41,32 +32,32 @@ const models_1 = require("../models");
|
|
|
41
32
|
const DefinitionRepo = __importStar(require("./definition"));
|
|
42
33
|
const logger_1 = __importDefault(require("../utils/logger"));
|
|
43
34
|
const errors_1 = require("../errors");
|
|
44
|
-
const findByModelIdAndDefinition = (modelId, customFieldDefinitionId) =>
|
|
35
|
+
const findByModelIdAndDefinition = async (modelId, customFieldDefinitionId) => models_1.CustomFieldValue.findAll({ where: { modelId, customFieldDefinitionId }, include: [models_1.CustomFieldDefinition] });
|
|
45
36
|
exports.findByModelIdAndDefinition = findByModelIdAndDefinition;
|
|
46
|
-
const create = (data, withAssociations = false) =>
|
|
47
|
-
const created =
|
|
37
|
+
const create = async (data, withAssociations = false) => {
|
|
38
|
+
const created = await models_1.CustomFieldValue.create(data);
|
|
48
39
|
if (withAssociations) {
|
|
49
|
-
const createdWithAssociations =
|
|
50
|
-
return createdWithAssociations
|
|
40
|
+
const createdWithAssociations = await (0, exports.findByModelIdAndDefinition)(created.modelId, created.customFieldDefinitionId);
|
|
41
|
+
return createdWithAssociations?.[0];
|
|
51
42
|
}
|
|
52
43
|
return created;
|
|
53
|
-
}
|
|
44
|
+
};
|
|
54
45
|
exports.create = create;
|
|
55
|
-
const findAllValues = () =>
|
|
46
|
+
const findAllValues = async () => models_1.CustomFieldValue.findAll({ include: [models_1.CustomFieldDefinition] });
|
|
56
47
|
exports.findAllValues = findAllValues;
|
|
57
48
|
/**
|
|
58
49
|
* Get all values for model instance id (with their definitions)
|
|
59
50
|
* @param modelId
|
|
60
51
|
* @returns CustomFieldValue[]
|
|
61
52
|
*/
|
|
62
|
-
const findValuesByModelId = (modelId) =>
|
|
53
|
+
const findValuesByModelId = async (modelId) => models_1.CustomFieldValue.findAll({ where: { modelId }, include: [models_1.CustomFieldDefinition] });
|
|
63
54
|
exports.findValuesByModelId = findValuesByModelId;
|
|
64
55
|
/**
|
|
65
56
|
* Retrieves custom field values for given model IDs
|
|
66
57
|
* @param modelIds - An array of model IDs to query custom field values for.
|
|
67
58
|
* @param options - Optional configuration object.
|
|
68
59
|
*/
|
|
69
|
-
const findValuesByModelIds = (modelIds, options) =>
|
|
60
|
+
const findValuesByModelIds = async (modelIds, options) => {
|
|
70
61
|
const { transaction } = options;
|
|
71
62
|
return models_1.CustomFieldValue.findAll({
|
|
72
63
|
where: { modelId: modelIds },
|
|
@@ -74,25 +65,25 @@ const findValuesByModelIds = (modelIds, options) => __awaiter(void 0, void 0, vo
|
|
|
74
65
|
raw: true,
|
|
75
66
|
nest: true,
|
|
76
67
|
});
|
|
77
|
-
}
|
|
68
|
+
};
|
|
78
69
|
exports.findValuesByModelIds = findValuesByModelIds;
|
|
79
70
|
/**
|
|
80
71
|
* Try to update custom field values for a model instance.
|
|
81
72
|
* Create new value record if not exists, but fails if value's definition not exist.
|
|
82
73
|
* Return the updated values
|
|
83
74
|
*/
|
|
84
|
-
const updateValues = (modelType, modelId, identifiers, valuesToUpdate, options = {}) =>
|
|
75
|
+
const updateValues = async (modelType, modelId, identifiers, valuesToUpdate, options = {}) => {
|
|
85
76
|
logger_1.default.info(`custom-fields: updating values for ${modelType} ${modelId}`, { valuesToUpdate });
|
|
86
77
|
const names = Object.keys(valuesToUpdate);
|
|
87
|
-
const fieldDefinitions =
|
|
78
|
+
const fieldDefinitions = await DefinitionRepo.findAll({ modelType, name: names, entityId: identifiers }, { withDisabled: true, transaction: options.transaction }) || [];
|
|
88
79
|
const disabledDefinitions = fieldDefinitions.filter((def) => def.disabled);
|
|
89
80
|
if (fieldDefinitions.length !== names.length) {
|
|
90
81
|
const missingDefinitions = names.filter((name) => !fieldDefinitions.some((def) => def.name === name));
|
|
91
82
|
throw new errors_1.MissingDefinitionError(missingDefinitions);
|
|
92
83
|
}
|
|
93
|
-
const disabledNames =
|
|
84
|
+
const disabledNames = disabledDefinitions?.map((def) => def.name) || [];
|
|
94
85
|
const valuesWithDisabledDefinitions = names.filter((name) => disabledNames.includes(name));
|
|
95
|
-
if (
|
|
86
|
+
if (valuesWithDisabledDefinitions?.length > 0) {
|
|
96
87
|
logger_1.default.warn(`custom-fields: trying to update disabled values: ${valuesWithDisabledDefinitions.join(', ')}`);
|
|
97
88
|
}
|
|
98
89
|
const values = names.map((name) => ({
|
|
@@ -101,17 +92,16 @@ const updateValues = (modelType, modelId, identifiers, valuesToUpdate, options =
|
|
|
101
92
|
updatedAt: new Date(),
|
|
102
93
|
customFieldDefinitionId: fieldDefinitions.find((def) => def.name === name).id,
|
|
103
94
|
}));
|
|
104
|
-
return Promise.all(values.map((value) =>
|
|
105
|
-
const [cfv] =
|
|
95
|
+
return Promise.all(values.map(async (value) => {
|
|
96
|
+
const [cfv] = await models_1.CustomFieldValue.upsert(value, {
|
|
106
97
|
transaction: options.transaction,
|
|
107
98
|
});
|
|
108
99
|
return cfv;
|
|
109
|
-
}))
|
|
110
|
-
}
|
|
100
|
+
}));
|
|
101
|
+
};
|
|
111
102
|
exports.updateValues = updateValues;
|
|
112
103
|
const deleteValue = (id, options = {}) => models_1.CustomFieldValue.update({ deletedAt: new Date() }, {
|
|
113
104
|
where: { id },
|
|
114
105
|
transaction: options.transaction,
|
|
115
106
|
});
|
|
116
107
|
exports.deleteValue = deleteValue;
|
|
117
|
-
//# sourceMappingURL=value.js.map
|
|
@@ -22,45 +22,35 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
26
|
const express_1 = __importStar(require("express"));
|
|
36
27
|
const models_1 = require("../../models");
|
|
37
28
|
const app = (0, express_1.default)();
|
|
38
29
|
app.use(express_1.default.json());
|
|
39
30
|
const api = (0, express_1.Router)();
|
|
40
|
-
api.get('/v1/test-models', (req, res) =>
|
|
41
|
-
const testModels =
|
|
31
|
+
api.get('/v1/test-models', async (req, res) => {
|
|
32
|
+
const testModels = await models_1.TestModel.findAll();
|
|
42
33
|
return res.json(testModels);
|
|
43
|
-
})
|
|
44
|
-
api.get('/v1/test-models/:testModelId', (req, res) =>
|
|
34
|
+
});
|
|
35
|
+
api.get('/v1/test-models/:testModelId', async (req, res) => {
|
|
45
36
|
const { params: { testModelId } } = req;
|
|
46
|
-
const testModel =
|
|
37
|
+
const testModel = await models_1.TestModel.findByPk(testModelId);
|
|
47
38
|
return res.json(testModel);
|
|
48
|
-
})
|
|
49
|
-
api.post('/v1/test-models', (req, res) =>
|
|
39
|
+
});
|
|
40
|
+
api.post('/v1/test-models', async (req, res) => {
|
|
50
41
|
const { body } = req;
|
|
51
|
-
const testModel =
|
|
42
|
+
const testModel = await models_1.TestModel.create(body);
|
|
52
43
|
return res.json(testModel);
|
|
53
|
-
})
|
|
54
|
-
api.patch('/v1/test-models/:testModelId', (req, res) =>
|
|
44
|
+
});
|
|
45
|
+
api.patch('/v1/test-models/:testModelId', async (req, res) => {
|
|
55
46
|
const { body, params: { testModelId } } = req;
|
|
56
|
-
const testModel =
|
|
47
|
+
const testModel = await models_1.TestModel.update(body, {
|
|
57
48
|
where: {
|
|
58
49
|
id: testModelId,
|
|
59
50
|
},
|
|
60
51
|
returning: true,
|
|
61
52
|
});
|
|
62
53
|
return res.json(testModel[1][0]);
|
|
63
|
-
})
|
|
54
|
+
});
|
|
64
55
|
app.use('/api', api);
|
|
65
56
|
exports.default = app;
|
|
66
|
-
//# sourceMappingURL=test-api.js.map
|
|
@@ -1,23 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getModel = exports.cleanup = void 0;
|
|
13
4
|
const models_1 = require("../../models");
|
|
14
5
|
// eslint-disable-next-line import/prefer-default-export
|
|
15
|
-
const cleanup = () =>
|
|
6
|
+
const cleanup = async () => {
|
|
16
7
|
if (process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'development') {
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
await models_1.CustomFieldDefinition.unscoped().destroy({ where: {} });
|
|
9
|
+
await models_1.TestModel.destroy({ where: {} });
|
|
19
10
|
}
|
|
20
|
-
}
|
|
11
|
+
};
|
|
21
12
|
exports.cleanup = cleanup;
|
|
22
13
|
const getModel = (name) => {
|
|
23
14
|
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
@@ -25,4 +16,3 @@ const getModel = (name) => {
|
|
|
25
16
|
return models[name];
|
|
26
17
|
};
|
|
27
18
|
exports.getModel = getModel;
|
|
28
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -2,33 +2,33 @@ import { CreateCustomFieldDefinition, CustomFieldDefinitionDTO } from '../../typ
|
|
|
2
2
|
export declare const coolFieldDefinition: CreateCustomFieldDefinition;
|
|
3
3
|
export declare const coolFieldDefinition2: {
|
|
4
4
|
name: string;
|
|
5
|
-
required?: boolean;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
required?: boolean | undefined;
|
|
6
|
+
disabled?: boolean | undefined;
|
|
7
|
+
description?: string | undefined;
|
|
8
|
+
createdAt?: Date | undefined;
|
|
9
|
+
updatedAt?: Date | undefined;
|
|
10
|
+
deletedAt?: Date | undefined;
|
|
11
|
+
displayName?: string | undefined;
|
|
11
12
|
validation?: any;
|
|
12
13
|
fieldType: string;
|
|
13
14
|
entityId: string;
|
|
14
15
|
entityType: string;
|
|
15
16
|
modelType: string;
|
|
16
|
-
description?: string;
|
|
17
17
|
};
|
|
18
18
|
export declare const coolFieldDefinition3: {
|
|
19
19
|
name: string;
|
|
20
|
-
required?: boolean;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
required?: boolean | undefined;
|
|
21
|
+
disabled?: boolean | undefined;
|
|
22
|
+
description?: string | undefined;
|
|
23
|
+
createdAt?: Date | undefined;
|
|
24
|
+
updatedAt?: Date | undefined;
|
|
25
|
+
deletedAt?: Date | undefined;
|
|
26
|
+
displayName?: string | undefined;
|
|
26
27
|
validation?: any;
|
|
27
28
|
fieldType: string;
|
|
28
29
|
entityId: string;
|
|
29
30
|
entityType: string;
|
|
30
31
|
modelType: string;
|
|
31
|
-
description?: string;
|
|
32
32
|
};
|
|
33
33
|
export declare const booleanField: (modelType: string) => CreateCustomFieldDefinition;
|
|
34
34
|
export declare const enumField: (modelType: string, options: any) => CreateCustomFieldDefinition;
|
|
@@ -9,8 +9,14 @@ exports.coolFieldDefinition = {
|
|
|
9
9
|
entityId: (0, uuid_1.v4)(),
|
|
10
10
|
entityType: 'fleetId',
|
|
11
11
|
};
|
|
12
|
-
exports.coolFieldDefinition2 =
|
|
13
|
-
exports.
|
|
12
|
+
exports.coolFieldDefinition2 = {
|
|
13
|
+
...exports.coolFieldDefinition,
|
|
14
|
+
name: 'cool field2',
|
|
15
|
+
};
|
|
16
|
+
exports.coolFieldDefinition3 = {
|
|
17
|
+
...exports.coolFieldDefinition,
|
|
18
|
+
name: 'cool field3',
|
|
19
|
+
};
|
|
14
20
|
const booleanField = (modelType) => ({
|
|
15
21
|
name: 'shapeless',
|
|
16
22
|
modelType,
|
|
@@ -41,19 +47,18 @@ const rangeField = (modelType) => ({
|
|
|
41
47
|
exports.rangeField = rangeField;
|
|
42
48
|
// eslint-disable-next-line max-len
|
|
43
49
|
const createDefinition = (defaults) => ({
|
|
44
|
-
name:
|
|
45
|
-
modelType:
|
|
46
|
-
fieldType:
|
|
47
|
-
entityId:
|
|
48
|
-
entityType:
|
|
50
|
+
name: defaults?.name || `def_${(0, uuid_1.v4)()}`,
|
|
51
|
+
modelType: defaults?.modelType || 'TestModel',
|
|
52
|
+
fieldType: defaults?.fieldType || 'boolean',
|
|
53
|
+
entityId: defaults?.entityId || (0, uuid_1.v4)(),
|
|
54
|
+
entityType: defaults?.entityType || 'fleetId',
|
|
49
55
|
});
|
|
50
56
|
exports.createDefinition = createDefinition;
|
|
51
57
|
const createDefinitions = (defaults, length = 1) => (Array(length).fill({}).map((_) => ({
|
|
52
|
-
name:
|
|
53
|
-
modelType:
|
|
54
|
-
fieldType:
|
|
55
|
-
entityId:
|
|
56
|
-
entityType:
|
|
58
|
+
name: defaults?.name || `def_${(0, uuid_1.v4)()}`,
|
|
59
|
+
modelType: defaults?.modelType || 'TestModel',
|
|
60
|
+
fieldType: defaults?.fieldType || 'boolean',
|
|
61
|
+
entityId: defaults?.entityId || (0, uuid_1.v4)(),
|
|
62
|
+
entityType: defaults?.entityType || 'fleetId',
|
|
57
63
|
})));
|
|
58
64
|
exports.createDefinitions = createDefinitions;
|
|
59
|
-
//# sourceMappingURL=definition.mock.js.map
|
|
@@ -17,4 +17,3 @@ const mockDimCustomFieldDefinitionEvent = (events, numberOfEvents) => (0, export
|
|
|
17
17
|
exports.mockDimCustomFieldDefinitionEvent = mockDimCustomFieldDefinitionEvent;
|
|
18
18
|
const mockDimCustomFieldValueEvent = (events, numberOfEvents) => (0, exports.mockEvent)(events, 'dim_custom_field_value', numberOfEvents);
|
|
19
19
|
exports.mockDimCustomFieldValueEvent = mockDimCustomFieldValueEvent;
|
|
20
|
-
//# sourceMappingURL=events.mock.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TestModel } from '../../models';
|
|
2
2
|
export declare const createTestModel: (payload?: {}) => Promise<TestModel>;
|
|
3
3
|
export declare const createTestModels: (fleetId: any, total: number) => Promise<TestModel[]>;
|
|
4
|
-
export declare const upsertTestModel: (payload: any) => Promise<[TestModel, boolean]>;
|
|
4
|
+
export declare const upsertTestModel: (payload: any) => Promise<[TestModel, boolean | null]>;
|
|
5
5
|
export declare const destroyTestModels: () => Promise<number>;
|
|
6
6
|
export declare const getTestModel: (id: string, options?: {}) => Promise<TestModel>;
|
|
7
7
|
export declare const getSomeTestModels: (options?: {
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getTestModelWithAssociation = exports.createTestModelWithAssociation = exports.updateTestModel = exports.getSomeTestModels = exports.getTestModel = exports.destroyTestModels = exports.upsertTestModel = exports.createTestModels = exports.createTestModel = void 0;
|
|
13
4
|
const models_1 = require("../../models");
|
|
@@ -32,14 +23,13 @@ exports.getSomeTestModels = getSomeTestModels;
|
|
|
32
23
|
const updateTestModel = (payload, query) => models_1.TestModel.update(payload, query);
|
|
33
24
|
exports.updateTestModel = updateTestModel;
|
|
34
25
|
// Associations
|
|
35
|
-
const createTestModelWithAssociation = () =>
|
|
36
|
-
const model =
|
|
37
|
-
|
|
26
|
+
const createTestModelWithAssociation = async () => {
|
|
27
|
+
const model = await models_1.TestModel.create({});
|
|
28
|
+
await models_1.AssociatedTestModel.create({ testModelId: model.id });
|
|
38
29
|
return model;
|
|
39
|
-
}
|
|
30
|
+
};
|
|
40
31
|
exports.createTestModelWithAssociation = createTestModelWithAssociation;
|
|
41
32
|
const getTestModelWithAssociation = (limit = 1) => models_1.TestModel.findAll({
|
|
42
33
|
limit, include: [models_1.AssociatedTestModel],
|
|
43
34
|
});
|
|
44
35
|
exports.getTestModelWithAssociation = getTestModelWithAssociation;
|
|
45
|
-
//# sourceMappingURL=testModel.js.map
|
package/dist/types/index.js
CHANGED
package/dist/utils/db/index.js
CHANGED
|
@@ -8,4 +8,3 @@ exports.CustomFieldsSchema = void 0;
|
|
|
8
8
|
const joi_1 = __importDefault(require("@hapi/joi"));
|
|
9
9
|
const CustomFieldsSchema = joi_1.default.object().pattern(joi_1.default.string(), joi_1.default.any());
|
|
10
10
|
exports.CustomFieldsSchema = CustomFieldsSchema;
|
|
11
|
-
//# sourceMappingURL=custom-fields.js.map
|
|
@@ -32,7 +32,7 @@ exports.validateValidation = validateValidation;
|
|
|
32
32
|
* @returns true if the value is valid according to the validation rules, false otherwise.
|
|
33
33
|
*/
|
|
34
34
|
const customValidation = (value, valueType, validation) => {
|
|
35
|
-
const validator = validators_1.default
|
|
35
|
+
const validator = validators_1.default?.[valueType];
|
|
36
36
|
if (!validation || !validator) {
|
|
37
37
|
return (0, exports.validateValidation)(valueType, validation);
|
|
38
38
|
}
|
|
@@ -40,4 +40,3 @@ const customValidation = (value, valueType, validation) => {
|
|
|
40
40
|
return value === null || validator(value, validation);
|
|
41
41
|
};
|
|
42
42
|
exports.default = customValidation;
|
|
43
|
-
//# sourceMappingURL=custom.js.map
|