@opengis/fastify-table 1.0.90 → 1.0.91
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/Changelog.md +4 -0
- package/crud/controllers/deleteCrud.js +22 -19
- package/crud/controllers/insert.js +58 -54
- package/crud/controllers/update.js +61 -59
- package/crud/funcs/dataDelete.js +19 -15
- package/crud/funcs/dataInsert.js +30 -24
- package/crud/funcs/dataUpdate.js +29 -24
- package/crud/funcs/getAccess.js +53 -53
- package/crud/funcs/getOpt.js +10 -10
- package/crud/funcs/setOpt.js +16 -16
- package/crud/funcs/utils/logChanges.js +71 -0
- package/crud/index.js +36 -36
- package/helper.js +28 -28
- package/index.js +97 -97
- package/notification/controllers/userNotifications.js +19 -19
- package/notification/funcs/addNotification.js +8 -8
- package/package.json +1 -1
- package/pg/pgClients.js +20 -20
- package/policy/funcs/checkPolicy.js +83 -83
- package/policy/funcs/sqlInjection.js +33 -33
- package/policy/index.js +14 -14
- package/redis/client.js +8 -8
- package/redis/funcs/redisClients.js +2 -2
- package/redis/index.js +19 -19
- package/server/migrations/0.sql +78 -78
- package/server/migrations/log.sql +63 -26
- package/server/templates/form/test.dataset.form.json +411 -411
- package/server/templates/table/test.dataset.table.json +28 -28
- package/server/templates/table/test.gis.map.table.json +44 -44
- package/table/controllers/data.js +103 -103
- package/table/controllers/suggest.js +79 -79
- package/table/controllers/table.js +52 -49
- package/table/controllers/utils/gisIRColumn.js +68 -68
- package/table/funcs/getFilterSQL/index.js +75 -75
- package/table/funcs/getFilterSQL/util/formatValue.js +142 -142
- package/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
- package/table/funcs/getFilterSQL/util/getFilterQuery.js +73 -73
- package/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
- package/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
- package/table/funcs/metaFormat/getSelectVal.js +20 -20
- package/table/funcs/metaFormat/index.js +28 -28
- package/test/api/crud.test.js +88 -88
- package/test/api/table.test.js +89 -89
- package/test/api/widget.test.js +117 -114
- package/test/funcs/crud.test.js +122 -76
- package/util/controllers/properties.add.js +57 -51
- package/util/controllers/status.monitor.js +8 -8
- package/widget/controllers/utils/historyFormat.js +76 -76
- package/widget/controllers/utils/obj2db.js +13 -13
- package/widget/controllers/widget.del.js +44 -44
- package/widget/controllers/widget.get.js +98 -96
- package/widget/controllers/widget.set.js +76 -70
- package/widget/index.js +40 -40
|
@@ -1,70 +1,76 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
|
|
3
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
-
import dataInsert from '../../crud/funcs/dataInsert.js';
|
|
5
|
-
import dataUpdate from '../../crud/funcs/dataUpdate.js';
|
|
6
|
-
|
|
7
|
-
const tableList = {
|
|
8
|
-
comment: 'crm.communications',
|
|
9
|
-
checklist: 'crm.checklists',
|
|
10
|
-
};
|
|
11
|
-
const pkList = {
|
|
12
|
-
comment: 'communication_id',
|
|
13
|
-
checklist: 'checklist_id',
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const galleryExtList = ['png', 'svg', 'jpg', 'jpeg', 'gif', 'mp4', 'mov', 'avi'];
|
|
17
|
-
|
|
18
|
-
export default async function widgetSet(req) {
|
|
19
|
-
const {
|
|
20
|
-
pg, params = {}, session = {}, body = {}, funcs, log,
|
|
21
|
-
} = req;
|
|
22
|
-
const { user = {} } = session.passport || {};
|
|
23
|
-
const { type, id, objectid } = params;
|
|
24
|
-
if (!['comment', 'checklist', 'file', 'gallery'].includes(type)) return { error: 'param type not valid', status: 400 };
|
|
25
|
-
if (!objectid) return { error: 'id required', status: 400 };
|
|
26
|
-
|
|
27
|
-
const table = tableList[type];
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
if (['gallery', 'file'].includes(type)) {
|
|
31
|
-
const file = await funcs.uploadMultiPart(req);
|
|
32
|
-
const extName = path.extname(file.filepath).slice(1).toLowerCase();
|
|
33
|
-
|
|
34
|
-
const data = {
|
|
35
|
-
uploaded_name: file?.originalFilename?.toLocaleLowerCase()?.replace(/'/g, '\'\''),
|
|
36
|
-
file_path: file?.relativeFilepath?.replace(/\\/g, '/'),
|
|
37
|
-
ext: extName,
|
|
38
|
-
size: file?.size,
|
|
39
|
-
file_status: 1,
|
|
40
|
-
uid: user?.uid || 1,
|
|
41
|
-
entity_id: objectid,
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
if (type === 'gallery' && !galleryExtList.includes(extName.toLowerCase())) {
|
|
45
|
-
return { message: 'invalid file extension', status: 400 };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const { rows = [] } = await dataInsert({
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
|
|
70
|
-
}
|
|
1
|
+
import path from 'path';
|
|
2
|
+
|
|
3
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
+
import dataInsert from '../../crud/funcs/dataInsert.js';
|
|
5
|
+
import dataUpdate from '../../crud/funcs/dataUpdate.js';
|
|
6
|
+
|
|
7
|
+
const tableList = {
|
|
8
|
+
comment: 'crm.communications',
|
|
9
|
+
checklist: 'crm.checklists',
|
|
10
|
+
};
|
|
11
|
+
const pkList = {
|
|
12
|
+
comment: 'communication_id',
|
|
13
|
+
checklist: 'checklist_id',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const galleryExtList = ['png', 'svg', 'jpg', 'jpeg', 'gif', 'mp4', 'mov', 'avi'];
|
|
17
|
+
|
|
18
|
+
export default async function widgetSet(req) {
|
|
19
|
+
const {
|
|
20
|
+
pg, params = {}, session = {}, body = {}, funcs, log,
|
|
21
|
+
} = req;
|
|
22
|
+
const { user = {} } = session.passport || {};
|
|
23
|
+
const { type, id, objectid } = params;
|
|
24
|
+
if (!['comment', 'checklist', 'file', 'gallery'].includes(type)) return { error: 'param type not valid', status: 400 };
|
|
25
|
+
if (!objectid) return { error: 'id required', status: 400 };
|
|
26
|
+
|
|
27
|
+
const table = tableList[type];
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
if (['gallery', 'file'].includes(type)) {
|
|
31
|
+
const file = await funcs.uploadMultiPart(req);
|
|
32
|
+
const extName = path.extname(file.filepath).slice(1).toLowerCase();
|
|
33
|
+
|
|
34
|
+
const data = {
|
|
35
|
+
uploaded_name: file?.originalFilename?.toLocaleLowerCase()?.replace(/'/g, '\'\''),
|
|
36
|
+
file_path: file?.relativeFilepath?.replace(/\\/g, '/'),
|
|
37
|
+
ext: extName,
|
|
38
|
+
size: file?.size,
|
|
39
|
+
file_status: 1,
|
|
40
|
+
uid: user?.uid || 1,
|
|
41
|
+
entity_id: objectid,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
if (type === 'gallery' && !galleryExtList.includes(extName.toLowerCase())) {
|
|
45
|
+
return { message: 'invalid file extension', status: 400 };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const { rows = [] } = await dataInsert({
|
|
49
|
+
table: 'crm.files', data, uid: user?.uid,
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
rowCount: 1, data: 'ok', command: 'UPLOAD', id: rows[0]?.file_id, entity_id: rows[0]?.entity_id,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const { pk } = await getMeta({ pg, table });
|
|
56
|
+
if (!pk) return { message: 'table not found', status: 404 };
|
|
57
|
+
|
|
58
|
+
const data = { ...body, uid: user?.uid, entity_id: objectid };
|
|
59
|
+
|
|
60
|
+
const result = id
|
|
61
|
+
? await dataUpdate({
|
|
62
|
+
table, data, id, uid: user?.uid,
|
|
63
|
+
})
|
|
64
|
+
: await dataInsert({
|
|
65
|
+
table, data, uid: user?.uid,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
rowCount: result.rowCount, data: 'ok', command: result.command, id: result.rows?.[0]?.[pkList[type]] || result?.[pkList[type]],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
log.error('widget/upload', { error: err.toString(), params });
|
|
74
|
+
return { error: err.toString(), status: 500 };
|
|
75
|
+
}
|
|
76
|
+
}
|
package/widget/index.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import widgetDel from './controllers/widget.del.js';
|
|
2
|
-
import widgetSet from './controllers/widget.set.js';
|
|
3
|
-
import widgetGet from './controllers/widget.get.js';
|
|
4
|
-
|
|
5
|
-
const tableSchema = {
|
|
6
|
-
params: {
|
|
7
|
-
// type: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
8
|
-
objectid: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
9
|
-
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
10
|
-
},
|
|
11
|
-
querystring: {
|
|
12
|
-
debug: { type: 'string', pattern: '^(\\d+)$' },
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
async function route(fastify, opt) {
|
|
17
|
-
const prefix = opt.prefix || '/api';
|
|
18
|
-
fastify.route({
|
|
19
|
-
method: 'DELETE',
|
|
20
|
-
url: `${prefix}/widget/:type/:objectid/:id`,
|
|
21
|
-
schema: tableSchema,
|
|
22
|
-
handler: widgetDel,
|
|
23
|
-
});
|
|
24
|
-
fastify.route({
|
|
25
|
-
method: 'POST',
|
|
26
|
-
path: `${prefix}/widget/:type/:objectid/:id?`,
|
|
27
|
-
schema: tableSchema,
|
|
28
|
-
handler: widgetSet,
|
|
29
|
-
});
|
|
30
|
-
fastify.route({
|
|
31
|
-
method: 'GET',
|
|
32
|
-
path: `${prefix}/widget/:type/:objectid`,
|
|
33
|
-
config: {
|
|
34
|
-
policy: ['public'],
|
|
35
|
-
},
|
|
36
|
-
schema: tableSchema,
|
|
37
|
-
handler: widgetGet,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
export default route;
|
|
1
|
+
import widgetDel from './controllers/widget.del.js';
|
|
2
|
+
import widgetSet from './controllers/widget.set.js';
|
|
3
|
+
import widgetGet from './controllers/widget.get.js';
|
|
4
|
+
|
|
5
|
+
const tableSchema = {
|
|
6
|
+
params: {
|
|
7
|
+
// type: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
8
|
+
objectid: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
9
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
10
|
+
},
|
|
11
|
+
querystring: {
|
|
12
|
+
debug: { type: 'string', pattern: '^(\\d+)$' },
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
async function route(fastify, opt) {
|
|
17
|
+
const prefix = opt.prefix || '/api';
|
|
18
|
+
fastify.route({
|
|
19
|
+
method: 'DELETE',
|
|
20
|
+
url: `${prefix}/widget/:type/:objectid/:id`,
|
|
21
|
+
schema: tableSchema,
|
|
22
|
+
handler: widgetDel,
|
|
23
|
+
});
|
|
24
|
+
fastify.route({
|
|
25
|
+
method: 'POST',
|
|
26
|
+
path: `${prefix}/widget/:type/:objectid/:id?`,
|
|
27
|
+
schema: tableSchema,
|
|
28
|
+
handler: widgetSet,
|
|
29
|
+
});
|
|
30
|
+
fastify.route({
|
|
31
|
+
method: 'GET',
|
|
32
|
+
path: `${prefix}/widget/:type/:objectid`,
|
|
33
|
+
config: {
|
|
34
|
+
policy: ['public'],
|
|
35
|
+
},
|
|
36
|
+
schema: tableSchema,
|
|
37
|
+
handler: widgetGet,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export default route;
|