@opengis/fastify-table 1.0.16 → 1.0.18
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/.eslintrc.cjs +42 -42
- package/Changelog.md +52 -47
- package/README.md +26 -26
- package/config.js +11 -11
- package/crud/controllers/deleteCrud.js +14 -14
- package/crud/controllers/insert.js +29 -29
- package/crud/controllers/update.js +31 -31
- package/crud/controllers/utils/checkXSS.js +45 -45
- package/crud/controllers/utils/xssInjection.js +72 -72
- package/crud/funcs/dataDelete.js +15 -15
- package/crud/funcs/dataInsert.js +24 -24
- package/crud/funcs/dataUpdate.js +20 -20
- package/crud/funcs/getToken.js +27 -27
- package/crud/funcs/isFileExists.js +13 -13
- package/crud/funcs/setToken.js +53 -53
- package/crud/index.js +29 -29
- package/helper.js +28 -28
- package/index.js +4 -0
- package/notification/controllers/userNotifications.js +19 -0
- package/notification/funcs/addNotification.js +8 -0
- package/notification/index.js +19 -0
- package/package.json +22 -22
- package/pg/funcs/autoIndex.js +89 -89
- package/pg/funcs/getMeta.js +27 -27
- package/pg/funcs/getPG.js +29 -29
- package/pg/funcs/init.js +42 -42
- package/pg/funcs/pgClients.js +2 -2
- package/pg/index.js +35 -35
- package/pg/pgClients.js +20 -20
- package/policy/funcs/checkPolicy.js +74 -74
- package/policy/funcs/sqlInjection.js +33 -33
- package/policy/index.js +14 -14
- package/redis/client.js +8 -8
- package/redis/funcs/getRedis.js +23 -23
- package/redis/funcs/redisClients.js +2 -2
- package/redis/index.js +19 -19
- package/server/migrations/crm.sql +55 -0
- package/server/migrations/log.sql +40 -0
- package/server/templates/form/test.dataset.form.json +411 -411
- package/server.js +14 -14
- package/table/controllers/data.js +57 -57
- package/table/controllers/filter.js +32 -32
- package/table/controllers/form.js +10 -10
- package/table/controllers/suggest.js +60 -60
- package/table/controllers/utils/getSelect.js +20 -20
- package/table/controllers/utils/getSelectMeta.js +66 -66
- 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 +26 -26
- package/table/index.js +25 -25
- package/test/api/crud.test.js +50 -50
- package/test/api/crud.xss.test.js +68 -68
- package/test/api/notification.test.js +56 -0
- package/test/api/table.test.js +49 -49
- package/test/config.example +18 -18
- package/test/funcs/crud.test.js +76 -76
- package/test/funcs/pg.test.js +34 -34
- package/test/funcs/redis.test.js +19 -19
- package/test/templates/cls/test.json +9 -9
- package/test/templates/form/cp_building.form.json +32 -32
- package/test/templates/select/account_id.json +3 -3
- package/test/templates/select/storage.data.json +2 -2
- package/test/templates/table/gis.dataset.table.json +20 -20
- package/test/widget.test.js +39 -0
- package/widget/controllers/utils/obj2db.js +13 -0
- package/widget/controllers/widget.del.js +41 -0
- package/widget/controllers/widget.get.js +145 -0
- package/widget/controllers/widget.set.js +49 -0
- package/widget/index.js +38 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import obj2db from './utils/obj2db.js';
|
|
2
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
+
|
|
4
|
+
const tableList = {
|
|
5
|
+
comment: 'crm.comment',
|
|
6
|
+
link: 'crm.link',
|
|
7
|
+
time: 'crm.elapsed_time',
|
|
8
|
+
checklist: 'crm.checklist',
|
|
9
|
+
};
|
|
10
|
+
const pkList = {
|
|
11
|
+
comment: 'comment_id',
|
|
12
|
+
link: 'link_id',
|
|
13
|
+
time: 'elapsed_time_id',
|
|
14
|
+
checklist: 'checklist_id',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default async function widgetSet({
|
|
18
|
+
pg, params = {}, session = {}, body = {},
|
|
19
|
+
}) {
|
|
20
|
+
const { user = {} } = session.passport || {};
|
|
21
|
+
const { type, id, objectid } = params;
|
|
22
|
+
if (!['comment', 'checklist', 'link', 'time'].includes(type)) return { error: 'param type not valid', status: 400 };
|
|
23
|
+
if (!objectid) return { error: 'id required', status: 400 };
|
|
24
|
+
|
|
25
|
+
const table = tableList[type];
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const { pk, columns: metaColumns } = await getMeta({ pg, table });
|
|
29
|
+
if (!pk) return { error: 'table not found', status: 404 };
|
|
30
|
+
|
|
31
|
+
const columnList = metaColumns.map((col) => col.name);
|
|
32
|
+
const nonexistCol = Object.keys(body).filter((key) => !columnList.includes(key));
|
|
33
|
+
const { columns, args } = obj2db({ ...body, uid: user?.uid, object_id: objectid }, nonexistCol);
|
|
34
|
+
|
|
35
|
+
const query = id
|
|
36
|
+
? `UPDATE ${table} SET ${columns?.map((key, index) => `"${key}"=$${++index}`).join(',')} WHERE ${pkList[type]} = '${id}' `
|
|
37
|
+
: `INSERT INTO ${table} (${columns?.join(',')}) VALUES (${columns?.map((el, index) => `$${++index}`).join(',')}) returning *;`;
|
|
38
|
+
|
|
39
|
+
console.log(query, args);
|
|
40
|
+
const result = await pg.query(query, args);
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
rowCount: result.rowCount, data: 'ok', command: result.command, id: result.rows?.[0]?.[pkList[type]],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
return { error: err.toString(), status: 500 };
|
|
48
|
+
}
|
|
49
|
+
}
|
package/widget/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const schema = {
|
|
2
|
+
params: {
|
|
3
|
+
type: { type: 'string' },
|
|
4
|
+
objectid: { type: 'string' },
|
|
5
|
+
id: { type: 'string' },
|
|
6
|
+
},
|
|
7
|
+
querystring: {
|
|
8
|
+
table: { type: 'string' },
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
import widgetDel from './controllers/widget.del.js';
|
|
13
|
+
import widgetSet from './controllers/widget.set.js';
|
|
14
|
+
import widgetGet from './controllers/widget.get.js';
|
|
15
|
+
|
|
16
|
+
async function route(fastify) {
|
|
17
|
+
fastify.route({
|
|
18
|
+
method: 'DELETE',
|
|
19
|
+
url: '/api-user/widget/:type/:objectid/:id',
|
|
20
|
+
schema,
|
|
21
|
+
handler: widgetDel,
|
|
22
|
+
});
|
|
23
|
+
fastify.route({
|
|
24
|
+
method: 'POST',
|
|
25
|
+
path: '/api-user/widget/:type/:objectid/:id?',
|
|
26
|
+
schema,
|
|
27
|
+
handler: widgetSet,
|
|
28
|
+
});
|
|
29
|
+
fastify.route({
|
|
30
|
+
method: 'GET',
|
|
31
|
+
path: '/api-user/widget/:type/:objectid',
|
|
32
|
+
config: {
|
|
33
|
+
policy: ['public'],
|
|
34
|
+
},
|
|
35
|
+
handler: widgetGet,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export default route;
|