@autofleet/sadot 0.5.5-beta.4 → 0.5.5-beta.6
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.
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import { WhereOptions } from 'sequelize';
|
|
2
|
+
/**
|
|
3
|
+
* This function builds a WHERE clause to be added to the main query.
|
|
4
|
+
* The WHERE clause enable free term search by custom fields.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} name - The model type name to be search for.
|
|
7
|
+
* @returns {WhereOptions} - A where clause to be added to the main query.
|
|
8
|
+
*/
|
|
2
9
|
export declare const buildCustomFieldsSearchWhereClause: (modelName: string) => WhereOptions;
|
|
@@ -4,18 +4,27 @@ exports.buildCustomFieldsSearchWhereClause = void 0;
|
|
|
4
4
|
/* eslint-disable import/prefer-default-export */
|
|
5
5
|
const sequelize_1 = require("sequelize");
|
|
6
6
|
const sequelize_typescript_1 = require("sequelize-typescript");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
/**
|
|
8
|
+
* This function builds a WHERE clause to be added to the main query.
|
|
9
|
+
* The WHERE clause enable free term search by custom fields.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} name - The model type name to be search for.
|
|
12
|
+
* @returns {WhereOptions} - A where clause to be added to the main query.
|
|
13
|
+
*/
|
|
14
|
+
const buildCustomFieldsSearchWhereClause = (modelName) => {
|
|
15
|
+
const subQuery = 'EXISTS ('
|
|
16
|
+
+ ' SELECT 1'
|
|
17
|
+
+ ' FROM "custom_field_values" AS "cv"'
|
|
18
|
+
+ ' INNER JOIN custom_field_definitions AS cd ON cv.custom_field_definition_id = cd.id '
|
|
19
|
+
+ ` AND cd.model_type = '${modelName}' `
|
|
20
|
+
+ ' WHERE'
|
|
21
|
+
+ ' "cv"."deleted_at" IS NULL'
|
|
22
|
+
+ ` AND "cv"."model_id" = "${modelName}"."id"`
|
|
23
|
+
+ ' AND CAST("cv"."value" AS TEXT) ILIKE :searchTerm)';
|
|
24
|
+
return {
|
|
25
|
+
[sequelize_1.Op.or]: [
|
|
26
|
+
sequelize_typescript_1.Sequelize.where(sequelize_typescript_1.Sequelize.literal(subQuery), true),
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
};
|
|
21
30
|
exports.buildCustomFieldsSearchWhereClause = buildCustomFieldsSearchWhereClause;
|
package/package.json
CHANGED
|
@@ -2,17 +2,27 @@
|
|
|
2
2
|
import { WhereOptions, Op } from 'sequelize';
|
|
3
3
|
import { Sequelize } from 'sequelize-typescript';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
5
|
+
/**
|
|
6
|
+
* This function builds a WHERE clause to be added to the main query.
|
|
7
|
+
* The WHERE clause enable free term search by custom fields.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} name - The model type name to be search for.
|
|
10
|
+
* @returns {WhereOptions} - A where clause to be added to the main query.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const buildCustomFieldsSearchWhereClause = (modelName: string): WhereOptions => {
|
|
14
|
+
const subQuery = 'EXISTS ('
|
|
15
|
+
+ ' SELECT 1'
|
|
16
|
+
+ ' FROM "custom_field_values" AS "cv"'
|
|
17
|
+
+ ' INNER JOIN custom_field_definitions AS cd ON cv.custom_field_definition_id = cd.id '
|
|
18
|
+
+ ` AND cd.model_type = '${modelName}' `
|
|
19
|
+
+ ' WHERE'
|
|
20
|
+
+ ' "cv"."deleted_at" IS NULL'
|
|
21
|
+
+ ` AND "cv"."model_id" = "${modelName}"."id"`
|
|
22
|
+
+ ' AND CAST("cv"."value" AS TEXT) ILIKE :searchTerm)';
|
|
23
|
+
return {
|
|
24
|
+
[Op.or]: [
|
|
25
|
+
Sequelize.where(Sequelize.literal(subQuery), true),
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
};
|