@autofleet/sadot 0.7.6-beta.4 → 0.7.6-beta.5

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.
@@ -12,31 +12,56 @@ const generateRandomString = (length = 5) => {
12
12
  return Array.from({ length }, () => characters.charAt((0, node_crypto_1.randomInt)(characters.length))).join('');
13
13
  };
14
14
  exports.generateRandomString = generateRandomString;
15
+ /*
16
+ LEFT JOIN (
17
+ SELECT
18
+ "cv"."model_id"
19
+ FROM
20
+ "custom_field_values" AS "cv"
21
+ INNER JOIN
22
+ "custom_field_definitions" AS "cd"
23
+ ON
24
+ "cd"."entity_id" = '152534e0-637e-44ad-aab6-3b758e43bb46'
25
+ AND "cv"."custom_field_definition_id" = "cd"."id"
26
+ AND "cd"."model_type" = 'Reservation'
27
+ AND "cd"."field_type" NOT IN ('date', 'datetime')
28
+ WHERE
29
+ "cv"."deleted_at" IS NULL
30
+ AND CAST("cv".value AS TEXT) ILIKE '%mat%'
31
+ GROUP BY "cv"."model_id"
32
+ ) AS "customFieldValue"
33
+ ON "customFieldValue"."model_id" = "Reservation"."id"
34
+
35
+ */
15
36
  const generateCustomFieldSearchQueryPayload = (searchTerm, model, entityId, customFieldsTypesToExclude = [
16
37
  constants_1.CustomFieldDefinitionType.DATETIME,
17
38
  constants_1.CustomFieldDefinitionType.DATE,
18
39
  ]) => ({
19
40
  include: [{
41
+ attributes: ['model_id', 'value'],
20
42
  model: models_1.CustomFieldValue,
21
43
  as: 'customFieldValue',
22
44
  required: false,
23
45
  include: [
24
46
  {
25
47
  model: models_1.CustomFieldDefinition,
26
- attributes: [],
48
+ as: 'customFieldDefinition',
27
49
  required: true,
50
+ on: {
51
+ entityId: sequelize_typescript_1.Sequelize.where(sequelize_typescript_1.Sequelize.col('entity_id'), { [sequelize_1.Op.eq]: `${entityId}` }),
52
+ modelType: sequelize_typescript_1.Sequelize.where(sequelize_typescript_1.Sequelize.col('model_type'), { [sequelize_1.Op.eq]: `${model.name}` }),
53
+ fieldType: sequelize_typescript_1.Sequelize.where(sequelize_typescript_1.Sequelize.col('field_type'), { [sequelize_1.Op.notIn]: customFieldsTypesToExclude }),
54
+ },
28
55
  where: {
29
- entityId,
30
- modelType: model.name,
31
- fieldType: { [sequelize_1.Op.notIn]: customFieldsTypesToExclude },
56
+ deleted_at: null,
32
57
  },
33
58
  },
34
59
  ],
35
- where: {
36
- deletedAt: null,
60
+ subQuery: true,
61
+ on: {
37
62
  value: sequelize_typescript_1.Sequelize.where(sequelize_typescript_1.Sequelize.cast(sequelize_typescript_1.Sequelize.col('value'), 'text'), { [sequelize_1.Op.iLike]: `%${searchTerm}%` }),
63
+ model_id: sequelize_typescript_1.Sequelize.where(sequelize_typescript_1.Sequelize.col('model_id'), { [sequelize_1.Op.eq]: sequelize_typescript_1.Sequelize.col(`${model.name}.id`) }),
38
64
  },
39
- subQuery: true,
40
65
  }],
41
66
  where: sequelize_typescript_1.Sequelize.where(sequelize_typescript_1.Sequelize.col('customFieldValue.model_id'), { [sequelize_1.Op.not]: null }),
42
67
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sadot",
3
- "version": "0.7.6-beta.4",
3
+ "version": "0.7.6-beta.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -34,6 +34,28 @@ export const generateRandomString = (length = 5): string => {
34
34
  return Array.from({ length }, () => characters.charAt(randomInt(characters.length))).join('');
35
35
  };
36
36
 
37
+ /*
38
+ LEFT JOIN (
39
+ SELECT
40
+ "cv"."model_id"
41
+ FROM
42
+ "custom_field_values" AS "cv"
43
+ INNER JOIN
44
+ "custom_field_definitions" AS "cd"
45
+ ON
46
+ "cd"."entity_id" = '152534e0-637e-44ad-aab6-3b758e43bb46'
47
+ AND "cv"."custom_field_definition_id" = "cd"."id"
48
+ AND "cd"."model_type" = 'Reservation'
49
+ AND "cd"."field_type" NOT IN ('date', 'datetime')
50
+ WHERE
51
+ "cv"."deleted_at" IS NULL
52
+ AND CAST("cv".value AS TEXT) ILIKE '%mat%'
53
+ GROUP BY "cv"."model_id"
54
+ ) AS "customFieldValue"
55
+ ON "customFieldValue"."model_id" = "Reservation"."id"
56
+
57
+ */
58
+
37
59
  export const generateCustomFieldSearchQueryPayload = (
38
60
  searchTerm: string,
39
61
  model: ModelStatic,
@@ -44,26 +66,30 @@ export const generateCustomFieldSearchQueryPayload = (
44
66
  ],
45
67
  ): CustomFieldsSearchPayload => ({
46
68
  include: [{
69
+ attributes: ['model_id', 'value'],
47
70
  model: CustomFieldValue,
48
71
  as: 'customFieldValue',
49
72
  required: false,
50
73
  include: [
51
74
  {
52
75
  model: CustomFieldDefinition,
53
- attributes: [],
76
+ as: 'customFieldDefinition',
54
77
  required: true,
78
+ on: {
79
+ entityId: Sequelize.where(Sequelize.col('entity_id'), { [Op.eq]: `${entityId}` }),
80
+ modelType: Sequelize.where(Sequelize.col('model_type'), { [Op.eq]: `${model.name}` }),
81
+ fieldType: Sequelize.where(Sequelize.col('field_type'), { [Op.notIn]: customFieldsTypesToExclude }),
82
+ },
55
83
  where: {
56
- entityId,
57
- modelType: model.name,
58
- fieldType: { [Op.notIn]: customFieldsTypesToExclude },
84
+ deleted_at: null,
59
85
  },
60
86
  },
61
87
  ],
62
- where: {
63
- deletedAt: null,
88
+ subQuery: true,
89
+ on: {
64
90
  value: Sequelize.where(Sequelize.cast(Sequelize.col('value'), 'text'), { [Op.iLike]: `%${searchTerm}%` }),
91
+ model_id: Sequelize.where(Sequelize.col('model_id'), { [Op.eq]: Sequelize.col(`${model.name}.id`) }),
65
92
  },
66
- subQuery: true,
67
93
  }],
68
94
  where: Sequelize.where(Sequelize.col('customFieldValue.model_id'), { [Op.not]: null }),
69
95
  });