@autofleet/sadot 0.5.4-beta.12 → 0.5.4-beta.14

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.
@@ -31,13 +31,15 @@ const initTables = async (sequelize, getUser, enrichUserPermissions) => {
31
31
  CustomFieldDefinition_1.default.addScope('userScope', (entityIds) => {
32
32
  const user = getUser();
33
33
  if (user?.permissions) {
34
- logger_1.default.info('custom fields scope added', { entityIds, permissions: user.permissions });
34
+ logger_1.default.info('custom fields scope added', { entityIds, permissions: user.permissions, enrichUserPermissions: !!enrichUserPermissions });
35
35
  const entityId = [
36
36
  ...Object.keys(user.permissions.fleets),
37
37
  ...Object.keys(user.permissions.businessModels),
38
38
  ...Object.keys(user.permissions.demandSources),
39
- ...enrichUserPermissions?.(entityIds),
40
39
  ];
40
+ if (enrichUserPermissions && entityIds && Array.isArray(entityIds)) {
41
+ entityId.push(...entityIds);
42
+ }
41
43
  logger_1.default.info('custom fields scope added updated entity:', { entityId });
42
44
  return {
43
45
  where: {
@@ -9,7 +9,7 @@ const findAll = (where, options = { withDisabled: false }) => {
9
9
  const queryModel = options.withDisabled
10
10
  ? models_1.CustomFieldDefinition.unscoped()
11
11
  : models_1.CustomFieldDefinition;
12
- return queryModel.scope({ method: ['userScope', where] }).findAll({
12
+ return queryModel.scope({ method: ['userScope', where.entityId] }).findAll({
13
13
  where,
14
14
  transaction: options.transaction,
15
15
  raw: true,
@@ -41,7 +41,7 @@ const findByEntityIds = async (modelType, entityIds, options = {}) => models_1.C
41
41
  raw: true,
42
42
  });
43
43
  exports.findByEntityIds = findByEntityIds;
44
- const findByWhere = (where) => models_1.CustomFieldDefinition.scope('userScope').findOne({
44
+ const findByWhere = (where) => models_1.CustomFieldDefinition.scope(where.entityId).findOne({
45
45
  where,
46
46
  });
47
47
  exports.findByWhere = findByWhere;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sadot",
3
- "version": "0.5.4-beta.12",
3
+ "version": "0.5.4-beta.14",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -26,13 +26,15 @@ const initTables = async (sequelize: Sequelize, getUser, enrichUserPermissions):
26
26
  CustomFieldDefinition.addScope('userScope', (entityIds) => {
27
27
  const user = getUser();
28
28
  if (user?.permissions) {
29
- logger.info('custom fields scope added', { entityIds, permissions: user.permissions });
29
+ logger.info('custom fields scope added', { entityIds, permissions: user.permissions, enrichUserPermissions: !!enrichUserPermissions });
30
30
  const entityId = [
31
31
  ...Object.keys(user.permissions.fleets),
32
32
  ...Object.keys(user.permissions.businessModels),
33
33
  ...Object.keys(user.permissions.demandSources),
34
- ...enrichUserPermissions?.(entityIds),
35
34
  ];
35
+ if (enrichUserPermissions && entityIds && Array.isArray(entityIds)) {
36
+ entityId.push(...entityIds);
37
+ }
36
38
  logger.info('custom fields scope added updated entity:', { entityId });
37
39
  return {
38
40
  where: {
@@ -12,7 +12,7 @@ export const findAll = (
12
12
  const queryModel = options.withDisabled
13
13
  ? CustomFieldDefinition.unscoped()
14
14
  : CustomFieldDefinition;
15
- return queryModel.scope({ method: ['userScope', where] }).findAll({
15
+ return queryModel.scope({ method: ['userScope', where.entityId] }).findAll({
16
16
  where,
17
17
  transaction: options.transaction,
18
18
  raw: true,
@@ -58,7 +58,7 @@ export const findByEntityIds = async (
58
58
  });
59
59
 
60
60
  export const findByWhere = (where): Promise<CustomFieldDefinition | null> =>
61
- CustomFieldDefinition.scope('userScope').findOne({
61
+ CustomFieldDefinition.scope(where.entityId).findOne({
62
62
  where,
63
63
  });
64
64