@autofleet/sadot 0.5.5-beta.26 → 0.5.5-beta.28
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.
|
@@ -11,6 +11,8 @@ import { CustomFieldDefinitionType } from '../validations/type';
|
|
|
11
11
|
* @param {string} searchTerm - The term to search for within custom fields.
|
|
12
12
|
* @param {ModelStatic} model - The Sequelize model representing the entity type to search for.
|
|
13
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
|
|
14
16
|
*
|
|
15
17
|
* @returns {CustomFieldsSearchPayload} - An object containing the WHERE clause and replacements
|
|
16
18
|
* for Sequelize.
|
|
@@ -19,5 +21,5 @@ interface CustomFieldsSearchPayload {
|
|
|
19
21
|
where: WhereOptions;
|
|
20
22
|
replacements: BindOrReplacements;
|
|
21
23
|
}
|
|
22
|
-
export declare const generateCustomFieldSearchQueryPayload: (searchTerm: string, model: ModelStatic, entityId: string,
|
|
24
|
+
export declare const generateCustomFieldSearchQueryPayload: (searchTerm: string, model: ModelStatic, entityId: string, customFieldsTypesToExclude?: CustomFieldDefinitionType[]) => CustomFieldsSearchPayload;
|
|
23
25
|
export {};
|
|
@@ -5,8 +5,11 @@ exports.generateCustomFieldSearchQueryPayload = void 0;
|
|
|
5
5
|
const sequelize_1 = require("sequelize");
|
|
6
6
|
const sequelize_typescript_1 = require("sequelize-typescript");
|
|
7
7
|
const type_1 = require("../validations/type");
|
|
8
|
-
const generateCustomFieldSearchQueryPayload = (searchTerm, model, entityId,
|
|
9
|
-
|
|
8
|
+
const generateCustomFieldSearchQueryPayload = (searchTerm, model, entityId, customFieldsTypesToExclude = [
|
|
9
|
+
type_1.CustomFieldDefinitionType.DATETIME,
|
|
10
|
+
type_1.CustomFieldDefinitionType.DATE,
|
|
11
|
+
]) => {
|
|
12
|
+
const excludedTypesString = customFieldsTypesToExclude.map((type) => `'${type}'`).join(',');
|
|
10
13
|
const subQuery = 'EXISTS ('
|
|
11
14
|
+ ' SELECT 1'
|
|
12
15
|
+ ' FROM "custom_field_values" AS "cv"'
|
|
@@ -14,7 +17,7 @@ const generateCustomFieldSearchQueryPayload = (searchTerm, model, entityId, excl
|
|
|
14
17
|
+ ` ON cd.entity_id = '${entityId}'`
|
|
15
18
|
+ ' AND cv.custom_field_definition_id = cd.id'
|
|
16
19
|
+ ` AND cd.model_type = '${model.name}'`
|
|
17
|
-
+ ` AND cd.field_type NOT IN (${excludedTypesString})`
|
|
20
|
+
+ ` ${excludedTypesString ? `AND cd.field_type NOT IN (${excludedTypesString})` : ''}`
|
|
18
21
|
+ ' WHERE'
|
|
19
22
|
+ ' "cv"."deleted_at" IS NULL'
|
|
20
23
|
+ ` AND "cv"."model_id" = "${model.name}"."id"`
|
package/package.json
CHANGED
|
@@ -13,6 +13,8 @@ import { CustomFieldDefinitionType } from '../validations/type';
|
|
|
13
13
|
* @param {string} searchTerm - The term to search for within custom fields.
|
|
14
14
|
* @param {ModelStatic} model - The Sequelize model representing the entity type to search for.
|
|
15
15
|
* @param {string} entityId - The entity ID to filter the custom fields by.
|
|
16
|
+
* @param {CustomFieldDefinitionType[]} excludedCustomFieldsTypes - An array of custom field types
|
|
17
|
+
* to exclude from the search
|
|
16
18
|
*
|
|
17
19
|
* @returns {CustomFieldsSearchPayload} - An object containing the WHERE clause and replacements
|
|
18
20
|
* for Sequelize.
|
|
@@ -27,9 +29,12 @@ export const generateCustomFieldSearchQueryPayload = (
|
|
|
27
29
|
searchTerm: string,
|
|
28
30
|
model: ModelStatic,
|
|
29
31
|
entityId : string,
|
|
30
|
-
|
|
32
|
+
customFieldsTypesToExclude : CustomFieldDefinitionType[] = [
|
|
33
|
+
CustomFieldDefinitionType.DATETIME,
|
|
34
|
+
CustomFieldDefinitionType.DATE,
|
|
35
|
+
],
|
|
31
36
|
): CustomFieldsSearchPayload => {
|
|
32
|
-
const excludedTypesString =
|
|
37
|
+
const excludedTypesString = customFieldsTypesToExclude.map((type) => `'${type}'`).join(',');
|
|
33
38
|
|
|
34
39
|
const subQuery = 'EXISTS ('
|
|
35
40
|
+ ' SELECT 1'
|
|
@@ -38,7 +43,7 @@ export const generateCustomFieldSearchQueryPayload = (
|
|
|
38
43
|
+ ` ON cd.entity_id = '${entityId}'`
|
|
39
44
|
+ ' AND cv.custom_field_definition_id = cd.id'
|
|
40
45
|
+ ` AND cd.model_type = '${model.name}'`
|
|
41
|
-
+ ` AND cd.field_type NOT IN (${excludedTypesString})`
|
|
46
|
+
+ ` ${excludedTypesString ? `AND cd.field_type NOT IN (${excludedTypesString})` : ''}`
|
|
42
47
|
+ ' WHERE'
|
|
43
48
|
+ ' "cv"."deleted_at" IS NULL'
|
|
44
49
|
+ ` AND "cv"."model_id" = "${model.name}"."id"`
|