@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.
Files changed (74) hide show
  1. package/.eslintrc.cjs +42 -42
  2. package/Changelog.md +52 -47
  3. package/README.md +26 -26
  4. package/config.js +11 -11
  5. package/crud/controllers/deleteCrud.js +14 -14
  6. package/crud/controllers/insert.js +29 -29
  7. package/crud/controllers/update.js +31 -31
  8. package/crud/controllers/utils/checkXSS.js +45 -45
  9. package/crud/controllers/utils/xssInjection.js +72 -72
  10. package/crud/funcs/dataDelete.js +15 -15
  11. package/crud/funcs/dataInsert.js +24 -24
  12. package/crud/funcs/dataUpdate.js +20 -20
  13. package/crud/funcs/getToken.js +27 -27
  14. package/crud/funcs/isFileExists.js +13 -13
  15. package/crud/funcs/setToken.js +53 -53
  16. package/crud/index.js +29 -29
  17. package/helper.js +28 -28
  18. package/index.js +4 -0
  19. package/notification/controllers/userNotifications.js +19 -0
  20. package/notification/funcs/addNotification.js +8 -0
  21. package/notification/index.js +19 -0
  22. package/package.json +22 -22
  23. package/pg/funcs/autoIndex.js +89 -89
  24. package/pg/funcs/getMeta.js +27 -27
  25. package/pg/funcs/getPG.js +29 -29
  26. package/pg/funcs/init.js +42 -42
  27. package/pg/funcs/pgClients.js +2 -2
  28. package/pg/index.js +35 -35
  29. package/pg/pgClients.js +20 -20
  30. package/policy/funcs/checkPolicy.js +74 -74
  31. package/policy/funcs/sqlInjection.js +33 -33
  32. package/policy/index.js +14 -14
  33. package/redis/client.js +8 -8
  34. package/redis/funcs/getRedis.js +23 -23
  35. package/redis/funcs/redisClients.js +2 -2
  36. package/redis/index.js +19 -19
  37. package/server/migrations/crm.sql +55 -0
  38. package/server/migrations/log.sql +40 -0
  39. package/server/templates/form/test.dataset.form.json +411 -411
  40. package/server.js +14 -14
  41. package/table/controllers/data.js +57 -57
  42. package/table/controllers/filter.js +32 -32
  43. package/table/controllers/form.js +10 -10
  44. package/table/controllers/suggest.js +60 -60
  45. package/table/controllers/utils/getSelect.js +20 -20
  46. package/table/controllers/utils/getSelectMeta.js +66 -66
  47. package/table/funcs/getFilterSQL/index.js +75 -75
  48. package/table/funcs/getFilterSQL/util/formatValue.js +142 -142
  49. package/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
  50. package/table/funcs/getFilterSQL/util/getFilterQuery.js +73 -73
  51. package/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
  52. package/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
  53. package/table/funcs/metaFormat/getSelectVal.js +20 -20
  54. package/table/funcs/metaFormat/index.js +26 -26
  55. package/table/index.js +25 -25
  56. package/test/api/crud.test.js +50 -50
  57. package/test/api/crud.xss.test.js +68 -68
  58. package/test/api/notification.test.js +56 -0
  59. package/test/api/table.test.js +49 -49
  60. package/test/config.example +18 -18
  61. package/test/funcs/crud.test.js +76 -76
  62. package/test/funcs/pg.test.js +34 -34
  63. package/test/funcs/redis.test.js +19 -19
  64. package/test/templates/cls/test.json +9 -9
  65. package/test/templates/form/cp_building.form.json +32 -32
  66. package/test/templates/select/account_id.json +3 -3
  67. package/test/templates/select/storage.data.json +2 -2
  68. package/test/templates/table/gis.dataset.table.json +20 -20
  69. package/test/widget.test.js +39 -0
  70. package/widget/controllers/utils/obj2db.js +13 -0
  71. package/widget/controllers/widget.del.js +41 -0
  72. package/widget/controllers/widget.get.js +145 -0
  73. package/widget/controllers/widget.set.js +49 -0
  74. 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
+ }
@@ -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;