@autofleet/sadot 1.1.5-beta → 1.1.6-beta
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.
|
@@ -22,6 +22,7 @@ export declare const findAll: (where?: {}, options?: FindOptions & {
|
|
|
22
22
|
}) => Promise<CustomValidator[]>;
|
|
23
23
|
export declare const findAllByModelType: (modelType: string, entityId: string, options?: FindOptions & {
|
|
24
24
|
modelOptions?: ModelOptions;
|
|
25
|
+
withDisabled?: boolean;
|
|
25
26
|
}) => Promise<CustomValidator[]>;
|
|
26
27
|
export declare const update: (id: string, updates: Partial<ValidatorAttributes>, options?: Transactionable) => Promise<[number, CustomValidator[]]>;
|
|
27
28
|
export declare const disable: (id: string, options?: Transactionable) => Promise<[number, CustomValidator[]]>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export type ModelOptions = {
|
|
|
14
14
|
/**
|
|
15
15
|
* Include options for the model
|
|
16
16
|
*/
|
|
17
|
-
include?: (entityIds: string
|
|
17
|
+
include?: (entityIds: string | string[]) => IncludeOptions[];
|
|
18
18
|
/**
|
|
19
19
|
* Custom association for the model
|
|
20
20
|
* @param model - The model to associate with
|
package/package.json
CHANGED
package/src/hooks/hooks.ts
CHANGED
|
@@ -169,10 +169,7 @@ const validateModel = async (
|
|
|
169
169
|
{
|
|
170
170
|
transaction: options.transaction,
|
|
171
171
|
attributes: CUSTOM_VALIDATOR_ATTRIBUTES_TO_PULL,
|
|
172
|
-
|
|
173
|
-
include: modelOptions.include?.(entityId),
|
|
174
|
-
}),
|
|
175
|
-
raw: true,
|
|
172
|
+
modelOptions,
|
|
176
173
|
},
|
|
177
174
|
);
|
|
178
175
|
if (options.transaction) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { IncludeOptions, Transactionable } from 'sequelize';
|
|
1
|
+
import type { FindOptions, IncludeOptions, Transactionable } from 'sequelize';
|
|
2
2
|
import logger from '../utils/logger';
|
|
3
3
|
import { CustomValidator } from '../models';
|
|
4
|
+
import type { ModelOptions } from '../types';
|
|
4
5
|
|
|
5
6
|
export interface FindValidatorOptions extends Transactionable {
|
|
6
7
|
withDisabled?: boolean;
|
|
@@ -33,11 +34,16 @@ export const create = async (
|
|
|
33
34
|
|
|
34
35
|
export const findAll = async (
|
|
35
36
|
where = {},
|
|
36
|
-
options:
|
|
37
|
+
options: FindOptions & {
|
|
38
|
+
modelOptions?: ModelOptions,
|
|
39
|
+
withDisabled?: boolean
|
|
40
|
+
} = {},
|
|
37
41
|
): Promise<CustomValidator[]> => {
|
|
38
42
|
logger.debug('custom-validator - find all validators');
|
|
39
43
|
|
|
40
|
-
const {
|
|
44
|
+
const {
|
|
45
|
+
transaction, withDisabled, include, attributes, raw,
|
|
46
|
+
} = options;
|
|
41
47
|
|
|
42
48
|
let validators;
|
|
43
49
|
if (withDisabled) {
|
|
@@ -46,6 +52,9 @@ export const findAll = async (
|
|
|
46
52
|
validators = await CustomValidator.unscoped().scope('userScope').findAll({
|
|
47
53
|
where,
|
|
48
54
|
transaction,
|
|
55
|
+
include,
|
|
56
|
+
attributes,
|
|
57
|
+
raw,
|
|
49
58
|
});
|
|
50
59
|
} else {
|
|
51
60
|
// Use defaultScope and userScope to filter both disabled and by permissions
|
|
@@ -53,6 +62,9 @@ export const findAll = async (
|
|
|
53
62
|
validators = await CustomValidator.scope(['defaultScope', 'userScope']).findAll({
|
|
54
63
|
where,
|
|
55
64
|
transaction,
|
|
65
|
+
include,
|
|
66
|
+
attributes,
|
|
67
|
+
raw,
|
|
56
68
|
});
|
|
57
69
|
}
|
|
58
70
|
|
|
@@ -62,18 +74,21 @@ export const findAll = async (
|
|
|
62
74
|
export const findAllByModelType = async (
|
|
63
75
|
modelType: string,
|
|
64
76
|
entityId: string,
|
|
65
|
-
options:
|
|
77
|
+
options: FindOptions & {
|
|
78
|
+
modelOptions?: ModelOptions,
|
|
79
|
+
withDisabled?: boolean
|
|
80
|
+
} = {},
|
|
66
81
|
): Promise<CustomValidator[]> => {
|
|
67
82
|
logger.debug('custom-validator - find all validators by model type');
|
|
68
|
-
|
|
69
83
|
return findAll(
|
|
70
84
|
{
|
|
71
85
|
modelType,
|
|
72
|
-
...(!options
|
|
73
|
-
|
|
74
|
-
|
|
86
|
+
...(!options?.modelOptions?.useEntityIdFromInclude && { entityId }),
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
...options,
|
|
90
|
+
include: options?.modelOptions?.include?.(entityId),
|
|
75
91
|
},
|
|
76
|
-
options,
|
|
77
92
|
);
|
|
78
93
|
};
|
|
79
94
|
|
package/src/types/index.ts
CHANGED
|
@@ -17,7 +17,7 @@ export type ModelOptions = {
|
|
|
17
17
|
/**
|
|
18
18
|
* Include options for the model
|
|
19
19
|
*/
|
|
20
|
-
include?: (entityIds: string[]) => IncludeOptions[];
|
|
20
|
+
include?: (entityIds: string | string[]) => IncludeOptions[];
|
|
21
21
|
/**
|
|
22
22
|
* Custom association for the model
|
|
23
23
|
* @param model - The model to associate with
|
package/src/utils/init.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { CUSTOM_FIELDS_SORT_SCOPE } from '@autofleet/common-types/lib/custom-fie
|
|
|
5
5
|
import {
|
|
6
6
|
CustomFieldDefinition,
|
|
7
7
|
CustomFieldValue,
|
|
8
|
+
CustomValidator,
|
|
8
9
|
} from '../models';
|
|
9
10
|
import {
|
|
10
11
|
beforeFind,
|
|
@@ -116,5 +117,6 @@ export const addScopes = (models: Models[], getModel: ModelFetcher, options: Pic
|
|
|
116
117
|
export const applyCustomAssociation = (models: Models[]): void => {
|
|
117
118
|
models.forEach(({ modelOptions }) => {
|
|
118
119
|
modelOptions?.customAssociation?.(CustomFieldDefinition);
|
|
120
|
+
modelOptions?.customAssociation?.(CustomValidator);
|
|
119
121
|
});
|
|
120
122
|
};
|