@autofleet/sadot 0.5.5-beta.3 → 0.5.5-beta.4
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.
|
@@ -34,13 +34,13 @@ const customFieldsSearchTestFlow = async ({ fieldType, fieldValue, searchTerm, e
|
|
|
34
34
|
await DefinitionRepo.create({ ...definition });
|
|
35
35
|
const [testModel1] = await (0, testModel_1.createTestModels)(definition.entityId, 2);
|
|
36
36
|
await testModel1.update({ customFields: { [definition.name]: fieldValue } });
|
|
37
|
-
const models = await models_1.TestModel.
|
|
38
|
-
where: { [sequelize_1.Op.or]: [(0, index_1.buildCustomFieldsSearchWhereClause)(
|
|
39
|
-
|
|
37
|
+
const models = await models_1.TestModel.findAndCountAll({
|
|
38
|
+
where: { [sequelize_1.Op.or]: [(0, index_1.buildCustomFieldsSearchWhereClause)('TestModel')] },
|
|
39
|
+
replacements: { searchTerm: `%${searchTerm}%` },
|
|
40
40
|
});
|
|
41
|
-
expect(models.
|
|
41
|
+
expect(models.count).toBe(expectedNumberOfQueryResults);
|
|
42
42
|
if (expectedNumberOfQueryResults > 0) {
|
|
43
|
-
expect(models[0].id).toBe(testModel1.id);
|
|
43
|
+
expect(models.rows[0].dataValues.id).toBe(testModel1.id);
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
46
|
exports.default = customFieldsSearchTestFlow;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { WhereOptions } from 'sequelize';
|
|
2
|
-
export declare const buildCustomFieldsSearchWhereClause: (
|
|
2
|
+
export declare const buildCustomFieldsSearchWhereClause: (modelName: string) => WhereOptions;
|
|
@@ -4,11 +4,18 @@ 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
|
-
const buildCustomFieldsSearchWhereClause = (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
const buildCustomFieldsSearchWhereClause = (modelName) => ({
|
|
8
|
+
[sequelize_1.Op.or]: [
|
|
9
|
+
sequelize_typescript_1.Sequelize.where(sequelize_typescript_1.Sequelize.literal(`
|
|
10
|
+
EXISTS (
|
|
11
|
+
SELECT 1
|
|
12
|
+
FROM "custom_field_values" AS "cv"
|
|
13
|
+
WHERE
|
|
14
|
+
"cv"."deleted_at" IS NULL
|
|
15
|
+
AND "cv"."model_id" = "${modelName}"."id"
|
|
16
|
+
AND CAST("cv"."value" AS TEXT) ILIKE :searchTerm
|
|
17
|
+
)
|
|
18
|
+
`), true),
|
|
19
|
+
],
|
|
13
20
|
});
|
|
14
21
|
exports.buildCustomFieldsSearchWhereClause = buildCustomFieldsSearchWhereClause;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@ import { buildCustomFieldsSearchWhereClause } from '../../../index';
|
|
|
3
3
|
import * as DefinitionRepo from '../../../repository/definition';
|
|
4
4
|
import { createDefinition } from '../../mocks/definition.mock';
|
|
5
5
|
import { createTestModels } from '../../mocks/testModel';
|
|
6
|
-
import {
|
|
6
|
+
import { TestModel } from '../../../models';
|
|
7
7
|
|
|
8
8
|
interface CustomFieldsSearchTestFlowInput {
|
|
9
9
|
fieldType: string;
|
|
@@ -22,15 +22,15 @@ const customFieldsSearchTestFlow = async ({
|
|
|
22
22
|
await DefinitionRepo.create({ ...definition });
|
|
23
23
|
const [testModel1] = await createTestModels(definition.entityId, 2);
|
|
24
24
|
await testModel1.update({ customFields: { [definition.name]: fieldValue } });
|
|
25
|
-
const models = await TestModel.
|
|
25
|
+
const models = await TestModel.findAndCountAll(
|
|
26
26
|
{
|
|
27
|
-
where: { [Op.or]: [buildCustomFieldsSearchWhereClause(
|
|
28
|
-
|
|
27
|
+
where: { [Op.or]: [buildCustomFieldsSearchWhereClause('TestModel')] },
|
|
28
|
+
replacements: { searchTerm: `%${searchTerm}%` },
|
|
29
29
|
},
|
|
30
30
|
);
|
|
31
|
-
expect(models.
|
|
31
|
+
expect(models.count).toBe(expectedNumberOfQueryResults);
|
|
32
32
|
if (expectedNumberOfQueryResults > 0) {
|
|
33
|
-
expect(models[0].id).toBe(testModel1.id);
|
|
33
|
+
expect(models.rows[0].dataValues.id).toBe(testModel1.id);
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
|
|
@@ -2,12 +2,17 @@
|
|
|
2
2
|
import { WhereOptions, Op } from 'sequelize';
|
|
3
3
|
import { Sequelize } from 'sequelize-typescript';
|
|
4
4
|
|
|
5
|
-
export const buildCustomFieldsSearchWhereClause = (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
export const buildCustomFieldsSearchWhereClause = (modelName: string): WhereOptions => ({
|
|
6
|
+
[Op.or]: [
|
|
7
|
+
Sequelize.where(Sequelize.literal(`
|
|
8
|
+
EXISTS (
|
|
9
|
+
SELECT 1
|
|
10
|
+
FROM "custom_field_values" AS "cv"
|
|
11
|
+
WHERE
|
|
12
|
+
"cv"."deleted_at" IS NULL
|
|
13
|
+
AND "cv"."model_id" = "${modelName}"."id"
|
|
14
|
+
AND CAST("cv"."value" AS TEXT) ILIKE :searchTerm
|
|
15
|
+
)
|
|
16
|
+
`), true),
|
|
17
|
+
],
|
|
13
18
|
});
|