@autofleet/sadot 0.5.4-beta.18 → 0.5.4-beta.19

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,3 +1,4 @@
1
+ import { ModelOptions } from '../types';
1
2
  /**
2
3
  * A hook to create the custom fields when updating a model (more then one instance).
3
4
  */
@@ -6,4 +7,4 @@ export declare const beforeBulkCreate: (options: any) => void;
6
7
  * A hook to create the custom fields when updating a model instance.
7
8
  * TODO - cleanup if update fail
8
9
  */
9
- export declare const beforeCreate: (scopeAttributes: string[], identifiersReplacer: any) => (instance: any, options: any) => Promise<void>;
10
+ export declare const beforeCreate: (scopeAttributes: string[], modelOptions: ModelOptions) => (instance: any, options: any) => Promise<void>;
@@ -31,7 +31,6 @@ const errors_1 = require("../errors");
31
31
  * A hook to create the custom fields when updating a model (more then one instance).
32
32
  */
33
33
  const beforeBulkCreate = (options) => {
34
- console.log('hooks - before bulk create');
35
34
  // This will activate the beforeCreate hook on each updating instance.
36
35
  // eslint-disable-next-line no-param-reassign
37
36
  options.individualHooks = true;
@@ -41,13 +40,13 @@ exports.beforeBulkCreate = beforeBulkCreate;
41
40
  * A hook to create the custom fields when updating a model instance.
42
41
  * TODO - cleanup if update fail
43
42
  */
44
- const beforeCreate = (scopeAttributes, identifiersReplacer) => async (instance, options) => {
43
+ const beforeCreate = (scopeAttributes, modelOptions) => async (instance, options) => {
45
44
  const { fields } = options;
46
45
  const modelType = instance.constructor.name;
47
- console.log('hooks - before create');
46
+ const { scopeAttributeReplacer } = modelOptions;
48
47
  let identifiers = scopeAttributes.map((attribute) => instance[attribute]);
49
- if (identifiersReplacer) {
50
- identifiers = await identifiersReplacer(identifiers);
48
+ if (scopeAttributeReplacer) {
49
+ identifiers = await scopeAttributeReplacer(identifiers);
51
50
  }
52
51
  // get all model's required definitions
53
52
  const requiredFieldsNames = await DefinitionRepo.getRequiredFields(modelType, instance.id, identifiers);
@@ -1,6 +1,7 @@
1
+ import { ModelOptions } from '../types';
1
2
  type SupportedHookTypes = 'afterFind' | 'afterCreate' | 'afterUpdate';
2
3
  /**
3
4
  * A hook to attach the custom fields when fetching a model instances.
4
5
  */
5
- declare const enrichResults: (modelType: string, scopeAttributes: string[], getScope: any, hookType?: SupportedHookTypes, identifiersReplacer?: any) => (instancesOrInstance: any | any[], options: any) => Promise<void>;
6
+ declare const enrichResults: (modelType: string, scopeAttributes: string[], getScope: any, hookType?: SupportedHookTypes, modelOptions?: ModelOptions) => (instancesOrInstance: any | any[], options: any) => Promise<void>;
6
7
  export default enrichResults;
@@ -44,8 +44,8 @@ const serializeCustomFields = (customFieldValues, customFieldDefinitionsHash) =>
44
44
  /**
45
45
  * A hook to attach the custom fields when fetching a model instances.
46
46
  */
47
- const enrichResults = (modelType, scopeAttributes, getScope, hookType, identifiersReplacer) => async (instancesOrInstance, options) => {
48
- console.log('hooks - enrichResults', modelType);
47
+ const enrichResults = (modelType, scopeAttributes, getScope, hookType, modelOptions) => async (instancesOrInstance, options) => {
48
+ const { scopeAttributeReplacer } = modelOptions;
49
49
  if (options.originalAttributes?.length > 0
50
50
  && !options.originalAttributes?.includes?.('customFields')) {
51
51
  return;
@@ -57,8 +57,8 @@ const enrichResults = (modelType, scopeAttributes, getScope, hookType, identifie
57
57
  instances = instances.filter(Boolean);
58
58
  let identifiers = instances.map((instance) => scopeAttributes
59
59
  .map((attr) => instance[attr])).flat();
60
- if (identifiersReplacer) {
61
- identifiers = await identifiersReplacer(identifiers);
60
+ if (scopeAttributeReplacer) {
61
+ identifiers = await scopeAttributeReplacer(identifiers);
62
62
  }
63
63
  logger_1.default.info('enrichResults - sadot - indentifiers: ', identifiers);
64
64
  const uniqueIdentifiers = [...new Set(identifiers)].filter(Boolean);
@@ -66,7 +66,6 @@ const enrichResults = (modelType, scopeAttributes, getScope, hookType, identifie
66
66
  ...map,
67
67
  [identifier]: [],
68
68
  }), {});
69
- console.log({ identifierCustomFieldDefinitionsMapping });
70
69
  const customFieldDefinitions = await DefinitionRepo.findByEntityIds(modelType, uniqueIdentifiers, { transaction: options.transaction, getScope });
71
70
  const definitionsMap = customFieldDefinitions.reduce((map, definition) => ({
72
71
  ...map,
@@ -98,9 +97,6 @@ const enrichResults = (modelType, scopeAttributes, getScope, hookType, identifie
98
97
  }
99
98
  scopeAttributes.forEach((attribute) => {
100
99
  const identifier = instance[attribute];
101
- console.log({
102
- identifier, attribute, instance, identifierCustomFieldDefinitionsMapping,
103
- });
104
100
  const entityCustomFieldDefinitions = identifierCustomFieldDefinitionsMapping[identifier];
105
101
  if (entityCustomFieldDefinitions?.length > 0) {
106
102
  entityCustomFieldDefinitions.forEach((customFieldDefinition) => {
@@ -1,3 +1,4 @@
1
+ import { ModelOptions } from '../types';
1
2
  /**
2
3
  * A hook to update the custom fields when updating a model (more then one instance).
3
4
  */
@@ -6,4 +7,4 @@ export declare const beforeBulkUpdate: (options: any) => void;
6
7
  * A hook to update the custom fields when updating a model instance.
7
8
  * TODO - cleanup if update fail
8
9
  */
9
- export declare const beforeUpdate: (scopeAttributes: string[], identifiersReplacer: any) => (instance: any, options: any) => Promise<void>;
10
+ export declare const beforeUpdate: (scopeAttributes: string[], modelOptions: ModelOptions) => (instance: any, options: any) => Promise<void>;
@@ -33,7 +33,6 @@ const ValueRepo = __importStar(require("../repository/value"));
33
33
  * A hook to update the custom fields when updating a model (more then one instance).
34
34
  */
35
35
  const beforeBulkUpdate = (options) => {
36
- console.log('hooks - beforeBulkUpdate');
37
36
  // This will activate the beforeUpdate hook on each updating instance.
38
37
  // eslint-disable-next-line no-param-reassign
39
38
  options.individualHooks = true;
@@ -43,14 +42,14 @@ exports.beforeBulkUpdate = beforeBulkUpdate;
43
42
  * A hook to update the custom fields when updating a model instance.
44
43
  * TODO - cleanup if update fail
45
44
  */
46
- const beforeUpdate = (scopeAttributes, identifiersReplacer) => async (instance, options) => {
45
+ const beforeUpdate = (scopeAttributes, modelOptions) => async (instance, options) => {
47
46
  logger_1.default.debug('sadot - before update hook');
48
- console.log('hooks - beforeUpdate');
49
47
  const { fields } = options;
48
+ const { scopeAttributeReplacer } = modelOptions;
50
49
  const modelType = instance.constructor.name;
51
50
  let identifiers = scopeAttributes.map((attribute) => instance[attribute]);
52
- if (identifiersReplacer) {
53
- identifiers = await identifiersReplacer(identifiers);
51
+ if (scopeAttributeReplacer) {
52
+ identifiers = await scopeAttributeReplacer(identifiers);
54
53
  }
55
54
  const customFieldsIdx = fields.indexOf('customFields');
56
55
  if (customFieldsIdx > -1) {
@@ -1,12 +1,11 @@
1
1
  import { WhereOptions } from 'sequelize';
2
2
  import { CustomFieldDefinition } from '../models';
3
3
  import type { CreateCustomFieldDefinition, UpdateCustomFieldDefinition } from '../types/definition';
4
- import { ModelOptions } from '../types';
5
4
  export declare const create: (data: CreateCustomFieldDefinition) => Promise<CustomFieldDefinition>;
6
5
  export declare const findAll: (where: WhereOptions, options?: any) => Promise<CustomFieldDefinition[]>;
7
6
  export declare const findByIds: (ids: string[], options?: any) => Promise<CustomFieldDefinition[]>;
8
7
  export declare const findById: (id: string, options?: any) => Promise<CustomFieldDefinition | null>;
9
- export declare const findByEntityIds: (modelType: string, entityIds: string[], options?: any, modelOptions?: ModelOptions) => Promise<CustomFieldDefinition[]>;
8
+ export declare const findByEntityIds: (modelType: string, entityIds: string[], options?: any) => Promise<CustomFieldDefinition[]>;
10
9
  export declare const findByWhere: (where: any) => Promise<CustomFieldDefinition | null>;
11
10
  export declare const findDefinitionsByModels: (modelTypes: string[], options?: any) => Promise<CustomFieldDefinition[]>;
12
11
  export declare const update: (id: string, data: UpdateCustomFieldDefinition) => Promise<CustomFieldDefinition>;
@@ -15,4 +14,4 @@ export declare const destroy: (id: string) => Promise<any>;
15
14
  /**
16
15
  * Return the names of the required fields for a given model
17
16
  */
18
- export declare const getRequiredFields: (modelType: string, modelId: string | string[], entityId: string | string[], modelOptions?: ModelOptions) => Promise<string[]>;
17
+ export declare const getRequiredFields: (modelType: string, modelId: string | string[], entityId: string | string[]) => Promise<string[]>;
@@ -17,8 +17,7 @@ const findAll = (where, options = { withDisabled: false }) => {
17
17
  return queryModel.scope('userScope').findAll({
18
18
  where,
19
19
  raw: true,
20
- logging: console.log,
21
- include: options.include,
20
+ logging: true,
22
21
  });
23
22
  };
24
23
  exports.findAll = findAll;
@@ -32,11 +31,10 @@ const findById = (id, options = { withDisabled: false }) => {
32
31
  return models_1.CustomFieldDefinition.scope('userScope').findByPk(id);
33
32
  };
34
33
  exports.findById = findById;
35
- const findByEntityIds = async (modelType, entityIds, options = {}, modelOptions = {}) => models_1.CustomFieldDefinition.findAll({
34
+ const findByEntityIds = async (modelType, entityIds, options = {}) => models_1.CustomFieldDefinition.findAll({
36
35
  where: {
37
36
  modelType,
38
37
  entityId: entityIds,
39
- ...modelOptions?.customEntityMapper?.(entityIds),
40
38
  },
41
39
  transaction: options.transaction,
42
40
  include: options.include,
@@ -71,14 +69,13 @@ exports.destroy = destroy;
71
69
  /**
72
70
  * Return the names of the required fields for a given model
73
71
  */
74
- const getRequiredFields = async (modelType, modelId, entityId, modelOptions = {}) => {
72
+ const getRequiredFields = async (modelType, modelId, entityId) => {
75
73
  const entityIds = Array.isArray(entityId) ? entityId : [entityId];
76
74
  const requiredFields = await models_1.CustomFieldDefinition.findAll({
77
75
  where: {
78
76
  required: true,
79
77
  modelType,
80
78
  entityId: { [sequelize_1.Op.in]: entityIds },
81
- ...modelOptions?.customEntityMapper?.(entityIds),
82
79
  },
83
80
  logging: true,
84
81
  });
@@ -102,7 +102,6 @@ const updateValues = async (modelType, modelId, identifiers, valuesToUpdate, opt
102
102
  return Promise.all(values.map(async (value) => {
103
103
  const [cfv] = await models_1.CustomFieldValue.upsert(value, {
104
104
  transaction: options.transaction,
105
- logging: console.log,
106
105
  });
107
106
  return cfv;
108
107
  }));
@@ -1,8 +1,6 @@
1
- import { Includeable } from 'sequelize';
2
1
  export type ModelFetcher = (name: string) => any;
3
2
  export type ModelOptions = {
4
- include?: Includeable[];
5
- customEntityMapper?: (identifiers: string[]) => any;
3
+ scopeAttributeReplacer?: (attributes?: string[]) => Promise<any>;
6
4
  };
7
5
  export type Models = {
8
6
  name: string;
@@ -11,7 +9,6 @@ export type Models = {
11
9
  creationWebhookHandler?: (instance: any) => any;
12
10
  updateWebhookHandler?: (instance: any) => any;
13
11
  deletionWebhookHandler?: (instance: any) => any;
14
- identifiersReplacer?: (...args: any[]) => Promise<any>;
15
12
  };
16
13
  export type CustomFieldOptions = {
17
14
  models: Models[];
@@ -12,7 +12,7 @@ const scopes_1 = require("../scopes");
12
12
  const logger_1 = __importDefault(require("./logger"));
13
13
  const { CUSTOM_FIELDS_FILTER_SCOPE } = common_types_1.customFields;
14
14
  const addHooks = (models, getModel) => {
15
- models.forEach(async ({ name, scopeAttributes, identifiersReplacer, }) => {
15
+ models.forEach(async ({ name, scopeAttributes, modelOptions, }) => {
16
16
  try {
17
17
  const model = getModel(name);
18
18
  if (!model) {
@@ -31,11 +31,11 @@ const addHooks = (models, getModel) => {
31
31
  model.addHook('beforeFind', 'sadot-beforeFind', (0, hooks_1.beforeFind)(scopeAttributes));
32
32
  model.addHook('beforeBulkCreate', 'sadot-beforeBulkCreate', hooks_1.beforeBulkCreate);
33
33
  model.addHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate', hooks_1.beforeBulkUpdate);
34
- model.addHook('beforeCreate', 'sadot-beforeCreate', (0, hooks_1.beforeCreate)(scopeAttributes, identifiersReplacer));
35
- model.addHook('beforeUpdate', 'sadot-beforeUpdate', (0, hooks_1.beforeUpdate)(scopeAttributes, identifiersReplacer));
36
- model.addHook('afterFind', 'sadot-afterFind', (0, hooks_1.enrichResults)(name, scopeAttributes, 'afterFind', null, identifiersReplacer));
37
- model.addHook('afterUpdate', 'sadot-afterUpdate', (0, hooks_1.enrichResults)(name, scopeAttributes, null, null, identifiersReplacer));
38
- model.addHook('afterCreate', 'sadot-afterCreate', (0, hooks_1.enrichResults)(name, scopeAttributes, null, null, identifiersReplacer));
34
+ model.addHook('beforeCreate', 'sadot-beforeCreate', (0, hooks_1.beforeCreate)(scopeAttributes, modelOptions));
35
+ model.addHook('beforeUpdate', 'sadot-beforeUpdate', (0, hooks_1.beforeUpdate)(scopeAttributes, modelOptions));
36
+ model.addHook('afterFind', 'sadot-afterFind', (0, hooks_1.enrichResults)(name, scopeAttributes, 'afterFind', null, modelOptions));
37
+ model.addHook('afterUpdate', 'sadot-afterUpdate', (0, hooks_1.enrichResults)(name, scopeAttributes, null, null, modelOptions));
38
+ model.addHook('afterCreate', 'sadot-afterCreate', (0, hooks_1.enrichResults)(name, scopeAttributes, null, null, modelOptions));
39
39
  }
40
40
  catch (e) {
41
41
  logger_1.default.error(`Could not add custom fields hook to model ${name}. `, e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sadot",
3
- "version": "0.5.4-beta.18",
3
+ "version": "0.5.4-beta.19",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,13 +1,12 @@
1
1
  import * as ValueRepo from '../repository/value';
2
2
  import * as DefinitionRepo from '../repository/definition';
3
3
  import { MissingRequiredCustomFieldError } from '../errors';
4
+ import { ModelOptions } from '../types';
4
5
 
5
6
  /**
6
7
  * A hook to create the custom fields when updating a model (more then one instance).
7
8
  */
8
9
  export const beforeBulkCreate = (options): void => {
9
- console.log('hooks - before bulk create');
10
-
11
10
  // This will activate the beforeCreate hook on each updating instance.
12
11
  // eslint-disable-next-line no-param-reassign
13
12
  options.individualHooks = true;
@@ -16,18 +15,17 @@ export const beforeBulkCreate = (options): void => {
16
15
  * A hook to create the custom fields when updating a model instance.
17
16
  * TODO - cleanup if update fail
18
17
  */
19
- export const beforeCreate = (scopeAttributes: string[], identifiersReplacer: any) => async (
18
+ export const beforeCreate = (scopeAttributes: string[], modelOptions: ModelOptions) => async (
20
19
  instance,
21
20
  options,
22
21
  ): Promise<void> => {
23
22
  const { fields } = options;
24
23
  const modelType = instance.constructor.name;
25
-
26
- console.log('hooks - before create');
24
+ const { scopeAttributeReplacer } = modelOptions;
27
25
 
28
26
  let identifiers = scopeAttributes.map((attribute) => instance[attribute]);
29
- if (identifiersReplacer) {
30
- identifiers = await identifiersReplacer(identifiers);
27
+ if (scopeAttributeReplacer) {
28
+ identifiers = await scopeAttributeReplacer(identifiers);
31
29
  }
32
30
  // get all model's required definitions
33
31
  const requiredFieldsNames = await DefinitionRepo.getRequiredFields(modelType,
@@ -5,6 +5,7 @@ import CustomFieldValue from '../models/CustomFieldValue';
5
5
  import CustomFieldDefinition from '../models/CustomFieldDefinition';
6
6
  import { SerializedCustomFields } from '../types/definition';
7
7
  import logger from '../utils/logger';
8
+ import { ModelOptions } from '../types';
8
9
 
9
10
  type SupportedHookTypes = 'afterFind' | 'afterCreate' | 'afterUpdate';
10
11
 
@@ -32,13 +33,12 @@ const enrichResults = (
32
33
  scopeAttributes: string[],
33
34
  getScope,
34
35
  hookType?: SupportedHookTypes,
35
- identifiersReplacer?: any,
36
+ modelOptions?: ModelOptions,
36
37
  ) => async (
37
38
  instancesOrInstance: any | any[],
38
39
  options,
39
40
  ): Promise<void> => {
40
- console.log('hooks - enrichResults', modelType);
41
-
41
+ const { scopeAttributeReplacer } = modelOptions;
42
42
  if (
43
43
  options.originalAttributes?.length > 0
44
44
  && !options.originalAttributes?.includes?.('customFields')
@@ -57,8 +57,8 @@ const enrichResults = (
57
57
  scopeAttributes
58
58
  .map((attr) => instance[attr])).flat();
59
59
 
60
- if (identifiersReplacer) {
61
- identifiers = await identifiersReplacer(identifiers);
60
+ if (scopeAttributeReplacer) {
61
+ identifiers = await scopeAttributeReplacer(identifiers);
62
62
  }
63
63
  logger.info('enrichResults - sadot - indentifiers: ', identifiers);
64
64
 
@@ -69,7 +69,6 @@ const enrichResults = (
69
69
  [identifier]: [],
70
70
 
71
71
  }), {});
72
- console.log({ identifierCustomFieldDefinitionsMapping });
73
72
 
74
73
  const customFieldDefinitions = await DefinitionRepo.findByEntityIds(
75
74
  modelType,
@@ -118,9 +117,6 @@ const enrichResults = (
118
117
 
119
118
  scopeAttributes.forEach((attribute) => {
120
119
  const identifier = instance[attribute];
121
- console.log({
122
- identifier, attribute, instance, identifierCustomFieldDefinitionsMapping,
123
- });
124
120
 
125
121
  const entityCustomFieldDefinitions = identifierCustomFieldDefinitionsMapping[identifier];
126
122
  if (entityCustomFieldDefinitions?.length > 0) {
@@ -6,8 +6,6 @@ import { ModelOptions } from '../types';
6
6
  * A hook to update the custom fields when updating a model (more then one instance).
7
7
  */
8
8
  export const beforeBulkUpdate = (options): void => {
9
- console.log('hooks - beforeBulkUpdate');
10
-
11
9
  // This will activate the beforeUpdate hook on each updating instance.
12
10
  // eslint-disable-next-line no-param-reassign
13
11
  options.individualHooks = true;
@@ -17,18 +15,17 @@ export const beforeBulkUpdate = (options): void => {
17
15
  * A hook to update the custom fields when updating a model instance.
18
16
  * TODO - cleanup if update fail
19
17
  */
20
- export const beforeUpdate = (scopeAttributes: string[], identifiersReplacer: any) => async (
18
+ export const beforeUpdate = (scopeAttributes: string[], modelOptions: ModelOptions) => async (
21
19
  instance,
22
20
  options,
23
21
  ): Promise<void> => {
24
22
  logger.debug('sadot - before update hook');
25
- console.log('hooks - beforeUpdate');
26
-
27
23
  const { fields } = options;
24
+ const { scopeAttributeReplacer } = modelOptions;
28
25
  const modelType = instance.constructor.name;
29
26
  let identifiers = scopeAttributes.map((attribute) => instance[attribute]);
30
- if (identifiersReplacer) {
31
- identifiers = await identifiersReplacer(identifiers);
27
+ if (scopeAttributeReplacer) {
28
+ identifiers = await scopeAttributeReplacer(identifiers);
32
29
  }
33
30
  const customFieldsIdx = fields.indexOf('customFields');
34
31
  if (customFieldsIdx > -1) {
@@ -4,7 +4,6 @@ import {
4
4
  import { CustomFieldDefinition } from '../models';
5
5
  import type { CreateCustomFieldDefinition, UpdateCustomFieldDefinition } from '../types/definition';
6
6
  import logger from '../utils/logger';
7
- import { ModelOptions } from '../types';
8
7
 
9
8
  export const create = (data: CreateCustomFieldDefinition): Promise<CustomFieldDefinition> =>
10
9
  CustomFieldDefinition.create(data);
@@ -21,9 +20,7 @@ export const findAll = (
21
20
  return queryModel.scope('userScope').findAll({
22
21
  where,
23
22
  raw: true,
24
- logging: console.log,
25
- include: options.include,
26
-
23
+ logging: true,
27
24
  });
28
25
  };
29
26
 
@@ -47,12 +44,10 @@ export const findByEntityIds = async (
47
44
  modelType: string,
48
45
  entityIds: string[],
49
46
  options: any = {},
50
- modelOptions: ModelOptions = {},
51
47
  ): Promise<CustomFieldDefinition[]> => CustomFieldDefinition.findAll({
52
48
  where: {
53
49
  modelType,
54
50
  entityId: entityIds,
55
- ...modelOptions?.customEntityMapper?.(entityIds),
56
51
  },
57
52
  transaction: options.transaction,
58
53
  include: options.include,
@@ -103,7 +98,6 @@ export const getRequiredFields = async (
103
98
  modelType: string,
104
99
  modelId: string | string[],
105
100
  entityId: string | string[],
106
- modelOptions: ModelOptions = {},
107
101
  ): Promise<string[]> => {
108
102
  const entityIds = Array.isArray(entityId) ? entityId : [entityId];
109
103
  const requiredFields = await CustomFieldDefinition.findAll({
@@ -111,7 +105,6 @@ export const getRequiredFields = async (
111
105
  required: true,
112
106
  modelType,
113
107
  entityId: { [Op.in]: entityIds },
114
- ...modelOptions?.customEntityMapper?.(entityIds),
115
108
  },
116
109
  logging: true,
117
110
  });
@@ -89,7 +89,6 @@ export const updateValues = async (
89
89
  return Promise.all(values.map(async (value) => {
90
90
  const [cfv] = await CustomFieldValue.upsert(value, {
91
91
  transaction: options.transaction,
92
- logging: console.log,
93
92
  });
94
93
  return cfv;
95
94
  }));
@@ -1,11 +1,7 @@
1
- import { Includeable } from 'sequelize';
2
- import { ModelCtor } from 'sequelize-typescript';
3
-
4
1
  export type ModelFetcher = (name: string) => any;
5
2
 
6
3
  export type ModelOptions = {
7
- include?: Includeable[];
8
- customEntityMapper?: (identifiers: string[]) => any;
4
+ scopeAttributeReplacer?: (attributes?: string[]) => Promise<any>;
9
5
  }
10
6
  export type Models = {
11
7
  name: string;
@@ -14,7 +10,6 @@ export type Models = {
14
10
  creationWebhookHandler?: (instance: any) => any;
15
11
  updateWebhookHandler?: (instance: any) => any;
16
12
  deletionWebhookHandler?: (instance: any) => any;
17
- identifiersReplacer?: (...args) => Promise<any>;
18
13
  }
19
14
 
20
15
  export type CustomFieldOptions = {
package/src/utils/init.ts CHANGED
@@ -20,7 +20,7 @@ const { CUSTOM_FIELDS_FILTER_SCOPE } = customFields;
20
20
 
21
21
  export const addHooks = (models: Models[], getModel: ModelFetcher): void => {
22
22
  models.forEach(async ({
23
- name, scopeAttributes, identifiersReplacer,
23
+ name, scopeAttributes, modelOptions,
24
24
  }) => {
25
25
  try {
26
26
  const model = getModel(name);
@@ -40,11 +40,11 @@ export const addHooks = (models: Models[], getModel: ModelFetcher): void => {
40
40
  model.addHook('beforeFind', 'sadot-beforeFind', beforeFind(scopeAttributes));
41
41
  model.addHook('beforeBulkCreate', 'sadot-beforeBulkCreate', beforeBulkCreate);
42
42
  model.addHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate', beforeBulkUpdate);
43
- model.addHook('beforeCreate', 'sadot-beforeCreate', beforeCreate(scopeAttributes, identifiersReplacer));
44
- model.addHook('beforeUpdate', 'sadot-beforeUpdate', beforeUpdate(scopeAttributes, identifiersReplacer));
45
- model.addHook('afterFind', 'sadot-afterFind', enrichResults(name, scopeAttributes, 'afterFind', null, identifiersReplacer));
46
- model.addHook('afterUpdate', 'sadot-afterUpdate', enrichResults(name, scopeAttributes, null, null, identifiersReplacer));
47
- model.addHook('afterCreate', 'sadot-afterCreate', enrichResults(name, scopeAttributes, null, null, identifiersReplacer));
43
+ model.addHook('beforeCreate', 'sadot-beforeCreate', beforeCreate(scopeAttributes, modelOptions));
44
+ model.addHook('beforeUpdate', 'sadot-beforeUpdate', beforeUpdate(scopeAttributes, modelOptions));
45
+ model.addHook('afterFind', 'sadot-afterFind', enrichResults(name, scopeAttributes, 'afterFind', null, modelOptions));
46
+ model.addHook('afterUpdate', 'sadot-afterUpdate', enrichResults(name, scopeAttributes, null, null, modelOptions));
47
+ model.addHook('afterCreate', 'sadot-afterCreate', enrichResults(name, scopeAttributes, null, null, modelOptions));
48
48
  } catch (e) {
49
49
  logger.error(`Could not add custom fields hook to model ${name}. `, e);
50
50
  }