@autofleet/sadot 0.5.5-beta.0 → 0.5.5-beta.1

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/index.d.ts CHANGED
@@ -11,4 +11,4 @@ export * from './utils/constants';
11
11
  declare const useCustomFields: (app: Application | null, getModel: ModelFetcher, options: CustomFieldOptions) => Promise<Sequelize>;
12
12
  export default useCustomFields;
13
13
  export declare const disableCustomFields: (models: any, getModel: any) => void;
14
- export declare const buildCustomFieldsSearchLiteral: (modelName: string, searchTerm: string) => WhereOptions;
14
+ export declare const buildCustomFieldsSearchWhereClause: (searchTerm: string) => WhereOptions;
package/dist/index.js CHANGED
@@ -17,8 +17,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.buildCustomFieldsSearchLiteral = exports.disableCustomFields = void 0;
20
+ exports.buildCustomFieldsSearchWhereClause = exports.disableCustomFields = void 0;
21
21
  const sequelize_typescript_1 = require("sequelize-typescript");
22
+ const sequelize_1 = require("sequelize");
22
23
  const models_1 = require("./models");
23
24
  const api_1 = __importDefault(require("./api"));
24
25
  const db_1 = __importDefault(require("./utils/db"));
@@ -51,8 +52,11 @@ const disableCustomFields = (models, getModel) => {
51
52
  (0, init_1.removeHooks)(models, getModel);
52
53
  };
53
54
  exports.disableCustomFields = disableCustomFields;
54
- const buildCustomFieldsSearchLiteral = (modelName, searchTerm) => sequelize_typescript_1.Sequelize.literal(`EXISTS (SELECT 1 FROM "custom_field_values" AS "cv"
55
- WHERE "cv"."deleted_at" IS NULL
56
- AND "cv"."model_id" = "${modelName}"."id"
57
- AND CAST("cv"."value" AS TEXT) ILIKE '%${searchTerm}%')`);
58
- exports.buildCustomFieldsSearchLiteral = buildCustomFieldsSearchLiteral;
55
+ const buildCustomFieldsSearchWhereClause = (searchTerm) => ({
56
+ where: {
57
+ [sequelize_1.Op.or]: [
58
+ sequelize_typescript_1.Sequelize.where(sequelize_typescript_1.Sequelize.cast(sequelize_typescript_1.Sequelize.col('customFieldValue.value'), 'text'), { [sequelize_1.Op.iLike]: `%${searchTerm}%` }),
59
+ ],
60
+ },
61
+ });
62
+ exports.buildCustomFieldsSearchWhereClause = buildCustomFieldsSearchWhereClause;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sadot",
3
- "version": "0.5.5-beta.0",
3
+ "version": "0.5.5-beta.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Application } from 'express';
2
2
  import { Sequelize } from 'sequelize-typescript';
3
- import { WhereOptions } from 'sequelize';
3
+ import { WhereOptions, Op } from 'sequelize';
4
4
  import {
5
5
  initTables, initTestModels,
6
6
  } from './models';
@@ -45,10 +45,12 @@ export const disableCustomFields = (models, getModel): void => {
45
45
  removeHooks(models, getModel);
46
46
  };
47
47
 
48
- export const buildCustomFieldsSearchLiteral = (
49
- modelName: string,
48
+ export const buildCustomFieldsSearchWhereClause = (
50
49
  searchTerm: string,
51
- ) : WhereOptions => Sequelize.literal(`EXISTS (SELECT 1 FROM "custom_field_values" AS "cv"
52
- WHERE "cv"."deleted_at" IS NULL
53
- AND "cv"."model_id" = "${modelName}"."id"
54
- AND CAST("cv"."value" AS TEXT) ILIKE '%${searchTerm}%')`);
50
+ ) : WhereOptions => ({
51
+ where: {
52
+ [Op.or]: [
53
+ Sequelize.where(Sequelize.cast(Sequelize.col('customFieldValue.value'), 'text'), { [Op.iLike]: `%${searchTerm}%` }),
54
+ ],
55
+ },
56
+ });