@autofleet/sadot 0.5.4-beta.9 → 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/api/v1/definition/index.js +1 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.js +12 -2
- package/dist/models/index.js +0 -1
- package/dist/repository/definition.js +0 -1
- package/dist/types/index.d.ts +0 -2
- package/package.json +2 -20
- package/src/api/v1/definition/index.ts +5 -6
- package/src/index.ts +12 -1
- package/src/models/index.ts +0 -1
- package/src/repository/definition.ts +0 -1
- package/src/types/index.ts +1 -4
- package/.env +0 -3
|
@@ -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
|
-
|
|
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 buildCustomFieldsSearchWhereClause: (searchTerm: string) => WhereOptions;
|
package/dist/index.js
CHANGED
|
@@ -17,7 +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.disableCustomFields = void 0;
|
|
20
|
+
exports.buildCustomFieldsSearchWhereClause = exports.disableCustomFields = void 0;
|
|
21
|
+
const sequelize_typescript_1 = require("sequelize-typescript");
|
|
22
|
+
const sequelize_1 = require("sequelize");
|
|
21
23
|
const models_1 = require("./models");
|
|
22
24
|
const api_1 = __importDefault(require("./api"));
|
|
23
25
|
const db_1 = __importDefault(require("./utils/db"));
|
|
@@ -32,7 +34,7 @@ __exportStar(require("./utils/constants"), exports);
|
|
|
32
34
|
const useCustomFields = async (app, getModel, options) => {
|
|
33
35
|
const { models } = options;
|
|
34
36
|
if (app) {
|
|
35
|
-
app.use('/api',
|
|
37
|
+
app.use('/api', api_1.default);
|
|
36
38
|
}
|
|
37
39
|
const sequelize = (0, db_1.default)(options.databaseConfig);
|
|
38
40
|
if (process.env.NODE_ENV === 'test') {
|
|
@@ -50,3 +52,11 @@ const disableCustomFields = (models, getModel) => {
|
|
|
50
52
|
(0, init_1.removeHooks)(models, getModel);
|
|
51
53
|
};
|
|
52
54
|
exports.disableCustomFields = disableCustomFields;
|
|
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/dist/models/index.js
CHANGED
|
@@ -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: [
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.5.5-beta.1",
|
|
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
|
-
"
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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, Op } 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',
|
|
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,13 @@ export default useCustomFields;
|
|
|
43
44
|
export const disableCustomFields = (models, getModel): void => {
|
|
44
45
|
removeHooks(models, getModel);
|
|
45
46
|
};
|
|
47
|
+
|
|
48
|
+
export const buildCustomFieldsSearchWhereClause = (
|
|
49
|
+
searchTerm: string,
|
|
50
|
+
) : WhereOptions => ({
|
|
51
|
+
where: {
|
|
52
|
+
[Op.or]: [
|
|
53
|
+
Sequelize.where(Sequelize.cast(Sequelize.col('customFieldValue.value'), 'text'), { [Op.iLike]: `%${searchTerm}%` }),
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
});
|
package/src/models/index.ts
CHANGED
|
@@ -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: [
|
package/src/types/index.ts
CHANGED
|
@@ -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