@autofleet/sadot 0.5.4-beta.9 → 0.5.5-beta.0

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.
@@ -41,7 +41,6 @@ const toPascalCase = (str) => str.replace(/(^\w|-\w)/g, (subStr) => subStr.repla
41
41
  router.post('/', async (req, res) => {
42
42
  const { modelName } = req.params;
43
43
  const modelType = toPascalCase(modelName);
44
- logger_1.default.info('sadot Creating custom field definition', { modelName });
45
44
  try {
46
45
  const validatedPayload = await (0, validations_1.validateCustomFieldDefinitionCreation)(req.body);
47
46
  const customFieldDefinition = await DefinitionRepo.create({
@@ -84,9 +83,7 @@ router.get('/', async (req, res) => {
84
83
  if (entityIds?.length > 0) {
85
84
  where.entityId = entityIds;
86
85
  }
87
- logger_1.default.info('sadot Fetching custom field definitions', { modelType, entityIds, where });
88
- const customFieldDefinitions = await DefinitionRepo.findAll(where, { withDisabled: true });
89
- logger_1.default.info('sadot Fetched custom field definitions customFieldDefinitions', { customFieldDefinitions });
86
+ const customFieldDefinitions = await DefinitionRepo.findAll({ ...where }, { withDisabled: true });
90
87
  return res.json(customFieldDefinitions);
91
88
  }
92
89
  catch (err) {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Application } from 'express';
2
2
  import { Sequelize } from 'sequelize-typescript';
3
+ import { WhereOptions } from 'sequelize';
3
4
  import type { CustomFieldOptions, ModelFetcher } from './types';
4
5
  export * from './utils/validations/custom-fields';
5
6
  export * from './utils/constants';
@@ -10,3 +11,4 @@ export * from './utils/constants';
10
11
  declare const useCustomFields: (app: Application | null, getModel: ModelFetcher, options: CustomFieldOptions) => Promise<Sequelize>;
11
12
  export default useCustomFields;
12
13
  export declare const disableCustomFields: (models: any, getModel: any) => void;
14
+ export declare const buildCustomFieldsSearchLiteral: (modelName: string, searchTerm: string) => WhereOptions;
package/dist/index.js CHANGED
@@ -17,7 +17,8 @@ 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.disableCustomFields = void 0;
20
+ exports.buildCustomFieldsSearchLiteral = exports.disableCustomFields = void 0;
21
+ const sequelize_typescript_1 = require("sequelize-typescript");
21
22
  const models_1 = require("./models");
22
23
  const api_1 = __importDefault(require("./api"));
23
24
  const db_1 = __importDefault(require("./utils/db"));
@@ -32,7 +33,7 @@ __exportStar(require("./utils/constants"), exports);
32
33
  const useCustomFields = async (app, getModel, options) => {
33
34
  const { models } = options;
34
35
  if (app) {
35
- app.use('/api', options.middleware, api_1.default);
36
+ app.use('/api', api_1.default);
36
37
  }
37
38
  const sequelize = (0, db_1.default)(options.databaseConfig);
38
39
  if (process.env.NODE_ENV === 'test') {
@@ -50,3 +51,8 @@ const disableCustomFields = (models, getModel) => {
50
51
  (0, init_1.removeHooks)(models, getModel);
51
52
  };
52
53
  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;
@@ -31,7 +31,6 @@ const initTables = async (sequelize, getUser) => {
31
31
  CustomFieldDefinition_1.default.addScope('userScope', () => {
32
32
  const user = getUser();
33
33
  if (user?.permissions) {
34
- console.log('custom fields scope added', { user, permissions: user.permissions });
35
34
  return {
36
35
  where: {
37
36
  entityId: [
@@ -13,7 +13,6 @@ const findAll = (where, options = { withDisabled: false }) => {
13
13
  where,
14
14
  transaction: options.transaction,
15
15
  raw: true,
16
- logging: console.log,
17
16
  });
18
17
  };
19
18
  exports.findAll = findAll;
@@ -1,4 +1,3 @@
1
- import { RequestHandler } from 'express';
2
1
  export type ModelFetcher = (name: string) => any;
3
2
  export type ModelOptions = {
4
3
  name: string;
@@ -11,5 +10,4 @@ export type CustomFieldOptions = {
11
10
  models: ModelOptions[];
12
11
  databaseConfig: any;
13
12
  getUser: () => any;
14
- middleware?: RequestHandler;
15
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sadot",
3
- "version": "0.5.4-beta.9",
3
+ "version": "0.5.5-beta.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -9,24 +9,7 @@
9
9
  "linter": "./node_modules/.bin/eslint .",
10
10
  "test": "jest --forceExit --runInBand",
11
11
  "coverage": "jest --coverage --forceExit --runInBand && rm -rf ./coverage",
12
- "build-to-local-repo": "npm run build && cp -r dist/* ../$REPO/node_modules/$npm_package_name/dist",
13
- "dev": "nodemon",
14
- "watch": "npm-watch build-to-local-repo"
15
- },
16
- "watch": {
17
- "build-to-local-repo": {
18
- "extensions": [
19
- "js",
20
- "jsx",
21
- "ts",
22
- "tsx",
23
- "css"
24
- ],
25
- "patterns": [
26
- "src"
27
- ],
28
- "quiet": false
29
- }
12
+ "dev": "nodemon"
30
13
  },
31
14
  "dependencies": {
32
15
  "@autofleet/common-types": "^1.7.29",
@@ -35,7 +18,6 @@
35
18
  "@autofleet/logger": "^2.0.5",
36
19
  "express": "^4.18.2",
37
20
  "joi": "^17.7.0",
38
- "npm-watch": "^0.11.0",
39
21
  "pg": "^8.10.0",
40
22
  "reflect-metadata": "^0.1.13",
41
23
  "sequelize": "^6.31.1",
@@ -18,7 +18,6 @@ const toPascalCase = (str: string): string => str.replace(/(^\w|-\w)/g, (subStr)
18
18
  router.post('/', async (req: Request, res: Response) => {
19
19
  const { modelName } = req.params as any;
20
20
  const modelType = toPascalCase(modelName);
21
- logger.info('sadot Creating custom field definition', { modelName });
22
21
  try {
23
22
  const validatedPayload: CreateCustomFieldDefinition = await
24
23
  validateCustomFieldDefinitionCreation(req.body);
@@ -59,17 +58,17 @@ router.get('/:customFieldDefinitionId', async (req, res) => {
59
58
  router.get('/', async (req, res) => {
60
59
  const { modelName } = req.params as any;
61
60
  const { entityIds } = req.query as any;
61
+
62
62
  const modelType = toPascalCase(modelName);
63
63
  try {
64
64
  const where: any = { modelType };
65
65
  if (entityIds?.length > 0) {
66
66
  where.entityId = entityIds;
67
67
  }
68
-
69
- logger.info('sadot Fetching custom field definitions', { modelType, entityIds, where });
70
- const customFieldDefinitions = await DefinitionRepo.findAll(where,
71
- { withDisabled: true });
72
- logger.info('sadot Fetched custom field definitions customFieldDefinitions', { customFieldDefinitions });
68
+ const customFieldDefinitions = await DefinitionRepo.findAll(
69
+ { ...where },
70
+ { withDisabled: true },
71
+ );
73
72
  return res.json(customFieldDefinitions);
74
73
  } catch (err) {
75
74
  logger.error('Failed to fetch custom field definitions', err);
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Application } from 'express';
2
2
  import { Sequelize } from 'sequelize-typescript';
3
+ import { WhereOptions } from 'sequelize';
3
4
  import {
4
5
  initTables, initTestModels,
5
6
  } from './models';
@@ -24,7 +25,7 @@ const useCustomFields = async (
24
25
  ): Promise<Sequelize> => {
25
26
  const { models } = options;
26
27
  if (app) {
27
- app.use('/api', options.middleware, api);
28
+ app.use('/api', api);
28
29
  }
29
30
  const sequelize = initDB(options.databaseConfig);
30
31
  if (process.env.NODE_ENV === 'test') {
@@ -43,3 +44,11 @@ export default useCustomFields;
43
44
  export const disableCustomFields = (models, getModel): void => {
44
45
  removeHooks(models, getModel);
45
46
  };
47
+
48
+ export const buildCustomFieldsSearchLiteral = (
49
+ modelName: string,
50
+ 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}%')`);
@@ -26,7 +26,6 @@ const initTables = async (sequelize: Sequelize, getUser): Promise<void> => {
26
26
  CustomFieldDefinition.addScope('userScope', () => {
27
27
  const user = getUser();
28
28
  if (user?.permissions) {
29
- console.log('custom fields scope added', { user, permissions: user.permissions });
30
29
  return {
31
30
  where: {
32
31
  entityId: [
@@ -16,7 +16,6 @@ export const findAll = (
16
16
  where,
17
17
  transaction: options.transaction,
18
18
  raw: true,
19
- logging: console.log,
20
19
  });
21
20
  };
22
21
 
@@ -1,5 +1,3 @@
1
- import { RequestHandler } from 'express';
2
-
3
1
  export type ModelFetcher = (name: string) => any;
4
2
 
5
3
  export type ModelOptions = {
@@ -10,9 +8,8 @@ export type ModelOptions = {
10
8
  deletionWebhookHandler?: (instance: any) => any;
11
9
  }
12
10
 
13
- export type CustomFieldOptions = {
11
+ export type CustomFieldOptions= {
14
12
  models: ModelOptions[];
15
13
  databaseConfig: any;
16
14
  getUser: () => any;
17
- middleware?: RequestHandler
18
15
  };
package/.env DELETED
@@ -1,3 +0,0 @@
1
- DB_USERNAME=emiltayeb
2
- DB_PASSWORD=123456
3
- NODE_ENV=test