@opengis/fastify-table 1.0.38 → 1.0.39
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 +113 -109
- package/README.md +26 -26
- package/config.js +12 -12
- package/crud/controllers/deleteCrud.js +14 -14
- 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 +24 -24
- package/crud/funcs/getToken.js +27 -27
- package/crud/funcs/isFileExists.js +13 -13
- package/crud/funcs/setToken.js +53 -53
- package/index.js +12 -1
- package/package.json +22 -22
- package/pg/funcs/getPG.js +29 -29
- package/redis/funcs/getRedis.js +23 -23
- package/server/migrations/crm.sql +95 -95
- package/server/migrations/log.sql +41 -41
- package/server.js +14 -14
- package/table/controllers/data.js +57 -57
- package/table/controllers/filter.js +37 -37
- package/table/controllers/search.js +41 -41
- package/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
- package/test/api/notification.test.js +37 -37
- package/test/api/table.test.js +57 -57
- package/test/api/widget.test.js +114 -114
- package/test/config.example +18 -18
- package/test/funcs/crud.test.js +76 -76
- package/test/funcs/notification.test.js +31 -31
- 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
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
-- crm.notifications
|
|
2
|
-
-- DROP TABLE IF EXISTS crm.notifications;
|
|
3
|
-
CREATE TABLE IF NOT EXISTS crm.notifications();
|
|
4
|
-
ALTER TABLE crm.notifications DROP CONSTRAINT IF EXISTS crm_notifications_pkey;
|
|
5
|
-
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS notification_id text NOT NULL DEFAULT admin.next_id();
|
|
6
|
-
|
|
7
|
-
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS notification_user_id text;
|
|
8
|
-
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS notification_type text DEFAULT 'notify'::text;
|
|
9
|
-
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS notification_status text DEFAULT 'not sent'::text;
|
|
10
|
-
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS subject text;
|
|
11
|
-
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS body text;
|
|
12
|
-
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS link text;
|
|
13
|
-
|
|
14
|
-
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS uid text;
|
|
15
|
-
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS files json;
|
|
16
|
-
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS cdate timestamp without time zone DEFAULT (now())::timestamp without time zone;
|
|
17
|
-
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS editor_id text;
|
|
18
|
-
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
|
|
19
|
-
ALTER TABLE crm.notifications ADD CONSTRAINT crm_notifications_pkey PRIMARY KEY (notification_id);
|
|
20
|
-
|
|
21
|
-
-- crm.files
|
|
22
|
-
-- DROP TABLE IF EXISTS crm.files;
|
|
23
|
-
CREATE TABLE IF NOT EXISTS crm.files();
|
|
24
|
-
ALTER TABLE crm.files DROP CONSTRAINT IF EXISTS crm_files_pkey;
|
|
25
|
-
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS file_id text NOT NULL DEFAULT admin.next_id();
|
|
26
|
-
|
|
27
|
-
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS uploaded_name text;
|
|
28
|
-
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS entity_id text; -- object_id
|
|
29
|
-
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS entity_type text; -- table_name
|
|
30
|
-
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS file_type text;
|
|
31
|
-
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS file_status numeric;
|
|
32
|
-
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS doc_type text;
|
|
33
|
-
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS subject text; -- title
|
|
34
|
-
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS size numeric;
|
|
35
|
-
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS ext text;
|
|
36
|
-
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS tags text[];
|
|
37
|
-
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS file_path text;
|
|
38
|
-
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS ismain boolean default false;
|
|
39
|
-
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS isverified boolean default false;
|
|
40
|
-
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS uid text;
|
|
41
|
-
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS files json;
|
|
42
|
-
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS cdate timestamp without time zone DEFAULT (now())::timestamp without time zone;
|
|
43
|
-
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS editor_id text;
|
|
44
|
-
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
|
|
45
|
-
ALTER TABLE crm.files ADD CONSTRAINT crm_files_pkey PRIMARY KEY (file_id);
|
|
46
|
-
|
|
47
|
-
-- crm.communications
|
|
48
|
-
-- DROP TABLE IF EXISTS crm.communications;
|
|
49
|
-
CREATE TABLE IF NOT EXISTS crm.communications();
|
|
50
|
-
ALTER TABLE crm.communications DROP CONSTRAINT IF EXISTS crm_communications_pkey;
|
|
51
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS communication_id text NOT NULL DEFAULT admin.next_id();
|
|
52
|
-
|
|
53
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS entity_id text; -- object_id
|
|
54
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS entity_type text; -- table_name
|
|
55
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS sender text;
|
|
56
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS channel text;
|
|
57
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS participant text;
|
|
58
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS communication_date date;
|
|
59
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS expiration_date date;
|
|
60
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS announcement text;
|
|
61
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS subject text; -- title
|
|
62
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS body text;
|
|
63
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS mark numeric;
|
|
64
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS parent_id text;
|
|
65
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS target_id text[];
|
|
66
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS enabled boolean;
|
|
67
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS uid text;
|
|
68
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS files json;
|
|
69
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS cdate timestamp without time zone DEFAULT (now())::timestamp without time zone;
|
|
70
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS editor_id text;
|
|
71
|
-
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
|
|
72
|
-
ALTER TABLE crm.communications ADD CONSTRAINT crm_communications_pkey PRIMARY KEY (communication_id);
|
|
73
|
-
|
|
74
|
-
-- crm.checklists
|
|
75
|
-
-- DROP TABLE IF EXISTS crm.checklists;
|
|
76
|
-
CREATE TABLE IF NOT EXISTS crm.checklists();
|
|
77
|
-
ALTER TABLE crm.checklists DROP CONSTRAINT IF EXISTS checklists_pkey;
|
|
78
|
-
ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS checklist_id text NOT NULL DEFAULT admin.next_id();
|
|
79
|
-
|
|
80
|
-
ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS entity_id text; -- object_id
|
|
81
|
-
ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS entity_type text; -- table_name
|
|
82
|
-
ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS subject text; -- title
|
|
83
|
-
alter table crm.checklists add column IF NOT EXISTS is_done boolean default false;
|
|
84
|
-
alter table crm.checklists add column IF NOT EXISTS done_date date;
|
|
85
|
-
alter table crm.checklists add column IF NOT EXISTS category text;
|
|
86
|
-
alter table crm.checklists add column IF NOT EXISTS body text;
|
|
87
|
-
alter table crm.checklists add column IF NOT EXISTS parent_id text;
|
|
88
|
-
alter table crm.checklists add column IF NOT EXISTS flag boolean;
|
|
89
|
-
|
|
90
|
-
ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS uid text;
|
|
91
|
-
ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS files json;
|
|
92
|
-
ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS cdate timestamp without time zone DEFAULT (now())::timestamp without time zone;
|
|
93
|
-
ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS editor_id text;
|
|
94
|
-
ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
|
|
95
|
-
ALTER TABLE crm.checklists ADD CONSTRAINT crm_checklists_pkey PRIMARY KEY (checklist_id);
|
|
1
|
+
-- crm.notifications
|
|
2
|
+
-- DROP TABLE IF EXISTS crm.notifications;
|
|
3
|
+
CREATE TABLE IF NOT EXISTS crm.notifications();
|
|
4
|
+
ALTER TABLE crm.notifications DROP CONSTRAINT IF EXISTS crm_notifications_pkey;
|
|
5
|
+
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS notification_id text NOT NULL DEFAULT admin.next_id();
|
|
6
|
+
|
|
7
|
+
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS notification_user_id text;
|
|
8
|
+
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS notification_type text DEFAULT 'notify'::text;
|
|
9
|
+
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS notification_status text DEFAULT 'not sent'::text;
|
|
10
|
+
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS subject text;
|
|
11
|
+
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS body text;
|
|
12
|
+
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS link text;
|
|
13
|
+
|
|
14
|
+
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS uid text;
|
|
15
|
+
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS files json;
|
|
16
|
+
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS cdate timestamp without time zone DEFAULT (now())::timestamp without time zone;
|
|
17
|
+
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS editor_id text;
|
|
18
|
+
ALTER TABLE crm.notifications ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
|
|
19
|
+
ALTER TABLE crm.notifications ADD CONSTRAINT crm_notifications_pkey PRIMARY KEY (notification_id);
|
|
20
|
+
|
|
21
|
+
-- crm.files
|
|
22
|
+
-- DROP TABLE IF EXISTS crm.files;
|
|
23
|
+
CREATE TABLE IF NOT EXISTS crm.files();
|
|
24
|
+
ALTER TABLE crm.files DROP CONSTRAINT IF EXISTS crm_files_pkey;
|
|
25
|
+
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS file_id text NOT NULL DEFAULT admin.next_id();
|
|
26
|
+
|
|
27
|
+
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS uploaded_name text;
|
|
28
|
+
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS entity_id text; -- object_id
|
|
29
|
+
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS entity_type text; -- table_name
|
|
30
|
+
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS file_type text;
|
|
31
|
+
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS file_status numeric;
|
|
32
|
+
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS doc_type text;
|
|
33
|
+
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS subject text; -- title
|
|
34
|
+
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS size numeric;
|
|
35
|
+
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS ext text;
|
|
36
|
+
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS tags text[];
|
|
37
|
+
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS file_path text;
|
|
38
|
+
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS ismain boolean default false;
|
|
39
|
+
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS isverified boolean default false;
|
|
40
|
+
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS uid text;
|
|
41
|
+
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS files json;
|
|
42
|
+
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS cdate timestamp without time zone DEFAULT (now())::timestamp without time zone;
|
|
43
|
+
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS editor_id text;
|
|
44
|
+
ALTER TABLE crm.files ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
|
|
45
|
+
ALTER TABLE crm.files ADD CONSTRAINT crm_files_pkey PRIMARY KEY (file_id);
|
|
46
|
+
|
|
47
|
+
-- crm.communications
|
|
48
|
+
-- DROP TABLE IF EXISTS crm.communications;
|
|
49
|
+
CREATE TABLE IF NOT EXISTS crm.communications();
|
|
50
|
+
ALTER TABLE crm.communications DROP CONSTRAINT IF EXISTS crm_communications_pkey;
|
|
51
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS communication_id text NOT NULL DEFAULT admin.next_id();
|
|
52
|
+
|
|
53
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS entity_id text; -- object_id
|
|
54
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS entity_type text; -- table_name
|
|
55
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS sender text;
|
|
56
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS channel text;
|
|
57
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS participant text;
|
|
58
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS communication_date date;
|
|
59
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS expiration_date date;
|
|
60
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS announcement text;
|
|
61
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS subject text; -- title
|
|
62
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS body text;
|
|
63
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS mark numeric;
|
|
64
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS parent_id text;
|
|
65
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS target_id text[];
|
|
66
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS enabled boolean;
|
|
67
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS uid text;
|
|
68
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS files json;
|
|
69
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS cdate timestamp without time zone DEFAULT (now())::timestamp without time zone;
|
|
70
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS editor_id text;
|
|
71
|
+
ALTER TABLE crm.communications ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
|
|
72
|
+
ALTER TABLE crm.communications ADD CONSTRAINT crm_communications_pkey PRIMARY KEY (communication_id);
|
|
73
|
+
|
|
74
|
+
-- crm.checklists
|
|
75
|
+
-- DROP TABLE IF EXISTS crm.checklists;
|
|
76
|
+
CREATE TABLE IF NOT EXISTS crm.checklists();
|
|
77
|
+
ALTER TABLE crm.checklists DROP CONSTRAINT IF EXISTS checklists_pkey;
|
|
78
|
+
ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS checklist_id text NOT NULL DEFAULT admin.next_id();
|
|
79
|
+
|
|
80
|
+
ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS entity_id text; -- object_id
|
|
81
|
+
ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS entity_type text; -- table_name
|
|
82
|
+
ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS subject text; -- title
|
|
83
|
+
alter table crm.checklists add column IF NOT EXISTS is_done boolean default false;
|
|
84
|
+
alter table crm.checklists add column IF NOT EXISTS done_date date;
|
|
85
|
+
alter table crm.checklists add column IF NOT EXISTS category text;
|
|
86
|
+
alter table crm.checklists add column IF NOT EXISTS body text;
|
|
87
|
+
alter table crm.checklists add column IF NOT EXISTS parent_id text;
|
|
88
|
+
alter table crm.checklists add column IF NOT EXISTS flag boolean;
|
|
89
|
+
|
|
90
|
+
ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS uid text;
|
|
91
|
+
ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS files json;
|
|
92
|
+
ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS cdate timestamp without time zone DEFAULT (now())::timestamp without time zone;
|
|
93
|
+
ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS editor_id text;
|
|
94
|
+
ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
|
|
95
|
+
ALTER TABLE crm.checklists ADD CONSTRAINT crm_checklists_pkey PRIMARY KEY (checklist_id);
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
CREATE TABLE IF NOT EXISTS log.table_changes();
|
|
2
|
-
ALTER TABLE log.table_changes DROP CONSTRAINT IF EXISTS log_table_changes_pkey;
|
|
3
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS table_change_id text NOT NULL DEFAULT admin.next_id();
|
|
4
|
-
|
|
5
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS entity_type text;
|
|
6
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS entity_id text; -- object_id
|
|
7
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS change_type text;
|
|
8
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS change_key text;
|
|
9
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS change_date date;
|
|
10
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS json_old json;
|
|
11
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS json_new json;
|
|
12
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS date_old timestamp without time zone;
|
|
13
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS date_new timestamp without time zone;
|
|
14
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS number_old numeric;
|
|
15
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS number_new numeric;
|
|
16
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS bool_old boolean;
|
|
17
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS bool_new boolean;
|
|
18
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS text_old text;
|
|
19
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS text_new text;
|
|
20
|
-
|
|
21
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS uid text;
|
|
22
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS cdate timestamp without time zone DEFAULT (now())::timestamp without time zone;
|
|
23
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS editor_id text;
|
|
24
|
-
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
|
|
25
|
-
ALTER TABLE log.table_changes ADD CONSTRAINT log_table_changes_pkey PRIMARY KEY (table_change_id);
|
|
26
|
-
|
|
27
|
-
CREATE TABLE IF NOT EXISTS log.user_auth();
|
|
28
|
-
ALTER TABLE log.user_auth DROP CONSTRAINT IF EXISTS log_user_auth_pkey;
|
|
29
|
-
ALTER TABLE log.user_auth DROP CONSTRAINT IF EXISTS log_user_auth_user_id_fkey;
|
|
30
|
-
|
|
31
|
-
ALTER TABLE log.user_auth ADD COLUMN IF NOT EXISTS user_auth_id text NOT NULL DEFAULT admin.next_id();
|
|
32
|
-
|
|
33
|
-
ALTER TABLE log.user_auth ADD COLUMN IF NOT EXISTS user_id text;
|
|
34
|
-
ALTER TABLE log.user_auth ADD COLUMN IF NOT EXISTS user_auth_date timestamp without time zone;
|
|
35
|
-
ALTER TABLE log.user_auth ADD COLUMN IF NOT EXISTS user_auth_type text;
|
|
36
|
-
|
|
37
|
-
ALTER TABLE log.user_auth ADD COLUMN IF NOT EXISTS uid text;
|
|
38
|
-
ALTER TABLE log.user_auth ADD COLUMN IF NOT EXISTS cdate timestamp without time zone DEFAULT (now())::timestamp without time zone;
|
|
39
|
-
ALTER TABLE log.user_auth ADD COLUMN IF NOT EXISTS editor_id text;
|
|
40
|
-
ALTER TABLE log.user_auth ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
|
|
41
|
-
ALTER TABLE log.user_auth ADD CONSTRAINT log_user_auth_pkey PRIMARY KEY (user_auth_id);
|
|
1
|
+
CREATE TABLE IF NOT EXISTS log.table_changes();
|
|
2
|
+
ALTER TABLE log.table_changes DROP CONSTRAINT IF EXISTS log_table_changes_pkey;
|
|
3
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS table_change_id text NOT NULL DEFAULT admin.next_id();
|
|
4
|
+
|
|
5
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS entity_type text;
|
|
6
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS entity_id text; -- object_id
|
|
7
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS change_type text;
|
|
8
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS change_key text;
|
|
9
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS change_date date;
|
|
10
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS json_old json;
|
|
11
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS json_new json;
|
|
12
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS date_old timestamp without time zone;
|
|
13
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS date_new timestamp without time zone;
|
|
14
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS number_old numeric;
|
|
15
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS number_new numeric;
|
|
16
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS bool_old boolean;
|
|
17
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS bool_new boolean;
|
|
18
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS text_old text;
|
|
19
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS text_new text;
|
|
20
|
+
|
|
21
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS uid text;
|
|
22
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS cdate timestamp without time zone DEFAULT (now())::timestamp without time zone;
|
|
23
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS editor_id text;
|
|
24
|
+
ALTER TABLE log.table_changes ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
|
|
25
|
+
ALTER TABLE log.table_changes ADD CONSTRAINT log_table_changes_pkey PRIMARY KEY (table_change_id);
|
|
26
|
+
|
|
27
|
+
CREATE TABLE IF NOT EXISTS log.user_auth();
|
|
28
|
+
ALTER TABLE log.user_auth DROP CONSTRAINT IF EXISTS log_user_auth_pkey;
|
|
29
|
+
ALTER TABLE log.user_auth DROP CONSTRAINT IF EXISTS log_user_auth_user_id_fkey;
|
|
30
|
+
|
|
31
|
+
ALTER TABLE log.user_auth ADD COLUMN IF NOT EXISTS user_auth_id text NOT NULL DEFAULT admin.next_id();
|
|
32
|
+
|
|
33
|
+
ALTER TABLE log.user_auth ADD COLUMN IF NOT EXISTS user_id text;
|
|
34
|
+
ALTER TABLE log.user_auth ADD COLUMN IF NOT EXISTS user_auth_date timestamp without time zone;
|
|
35
|
+
ALTER TABLE log.user_auth ADD COLUMN IF NOT EXISTS user_auth_type text;
|
|
36
|
+
|
|
37
|
+
ALTER TABLE log.user_auth ADD COLUMN IF NOT EXISTS uid text;
|
|
38
|
+
ALTER TABLE log.user_auth ADD COLUMN IF NOT EXISTS cdate timestamp without time zone DEFAULT (now())::timestamp without time zone;
|
|
39
|
+
ALTER TABLE log.user_auth ADD COLUMN IF NOT EXISTS editor_id text;
|
|
40
|
+
ALTER TABLE log.user_auth ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
|
|
41
|
+
ALTER TABLE log.user_auth ADD CONSTRAINT log_user_auth_pkey PRIMARY KEY (user_auth_id);
|
|
42
42
|
ALTER TABLE log.user_auth ADD CONSTRAINT log_user_auth_user_id_fkey FOREIGN KEY (user_id) REFERENCES admin.users (uid) MATCH SIMPLE;
|
package/server.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
// This file contains code that we reuse
|
|
2
|
-
// between our tests.
|
|
3
|
-
import Fastify from 'fastify';
|
|
4
|
-
import config from './test/config.js';
|
|
5
|
-
import appService from './index.js';
|
|
6
|
-
|
|
7
|
-
const app = Fastify({ logger: false });
|
|
8
|
-
app.register(appService, config);
|
|
9
|
-
app.listen({ host: '0.0.0.0', port: process.env.PORT || 3000 }, (err) => {
|
|
10
|
-
if (err) {
|
|
11
|
-
app.log.error(err);
|
|
12
|
-
process.exit(1);
|
|
13
|
-
}
|
|
14
|
-
});
|
|
1
|
+
// This file contains code that we reuse
|
|
2
|
+
// between our tests.
|
|
3
|
+
import Fastify from 'fastify';
|
|
4
|
+
import config from './test/config.js';
|
|
5
|
+
import appService from './index.js';
|
|
6
|
+
|
|
7
|
+
const app = Fastify({ logger: false });
|
|
8
|
+
app.register(appService, config);
|
|
9
|
+
app.listen({ host: '0.0.0.0', port: process.env.PORT || 3000 }, (err) => {
|
|
10
|
+
if (err) {
|
|
11
|
+
app.log.error(err);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import getTemplate from './utils/getTemplate.js';
|
|
2
|
-
import getFilterSQL from '../funcs/getFilterSQL/index.js';
|
|
3
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
-
import metaFormat from '../funcs/metaFormat/index.js';
|
|
5
|
-
|
|
6
|
-
const maxLimit = 100;
|
|
7
|
-
export default async function data(req) {
|
|
8
|
-
const time = Date.now();
|
|
9
|
-
const {
|
|
10
|
-
pg, params, query = {},
|
|
11
|
-
} = req;
|
|
12
|
-
|
|
13
|
-
const loadTable = await getTemplate('table', params.table);
|
|
14
|
-
|
|
15
|
-
if (!loadTable) { return { status: 404, message: 'not found' }; }
|
|
16
|
-
|
|
17
|
-
const {
|
|
18
|
-
table, columns, sql, filters, form, meta,
|
|
19
|
-
} = loadTable;
|
|
20
|
-
const { pk } = await getMeta(table);
|
|
21
|
-
|
|
22
|
-
const cols = columns.map((el) => el.name || el).join(',');
|
|
23
|
-
const sqlTable = sql?.filter?.((el) => !el?.disabled && el?.sql?.replace).map((el, i) => ` left join lateral (${el.sql}) ${el.name || `t${i}`} on 1=1 `)?.join('') || '';
|
|
24
|
-
|
|
25
|
-
const fData = query.filter ? await getFilterSQL({
|
|
26
|
-
filter: query.filter,
|
|
27
|
-
table: params.table,
|
|
28
|
-
json: 1,
|
|
29
|
-
}) : {};
|
|
30
|
-
|
|
31
|
-
const keyQuery = query.key && loadTable.key && !params.id ? `${loadTable.key}=$1` : null;
|
|
32
|
-
|
|
33
|
-
const limit = Math.min(maxLimit, +(query.limit || 10));
|
|
34
|
-
|
|
35
|
-
const offset = query.page && query.page > 0 ? ` offset ${(query.page - 1) * limit}` : '';
|
|
36
|
-
// id, query, filter
|
|
37
|
-
const [orderColumn, orderDir] = (query.order || loadTable.order || '').split(/[- ]/);
|
|
38
|
-
|
|
39
|
-
const order = cols.includes(orderColumn) && orderColumn?.length ? `order by ${orderColumn} ${query.desc || orderDir === 'desc' ? 'desc' : ''}` : '';
|
|
40
|
-
const state = loadTable.filterState && query.state ? loadTable.filterState[query.state]?.sql : null;
|
|
41
|
-
const custom = loadTable.filterCustom && query.custom ? loadTable.filterCustom[query.custom]?.sql : null;
|
|
42
|
-
const search = loadTable.meta?.search && query.search ? `(${loadTable.meta?.search.split(',').map(el => `${el} ilike '%${query.search}%'`).join(' or ')})` : null;
|
|
43
|
-
|
|
44
|
-
const where = [(params.id ? ` "${pk}" = $1` : null), keyQuery, loadTable.query, fData.q, state, custom, search].filter((el) => el);
|
|
45
|
-
const q = `select ${pk ? `"${pk}" as id,` : ''} ${query.id || query.key ? '*' : cols || '*'} from ${table} t ${sqlTable} where ${where.join(' and ') || 'true'} ${order} ${offset} limit ${limit}`;
|
|
46
|
-
|
|
47
|
-
if (query.sql === '1') { return q; }
|
|
48
|
-
|
|
49
|
-
const { rows } = await pg.query(q, (params.id ? [params.id] : null) || (query.key && loadTable.key ? [query.key] : []));
|
|
50
|
-
|
|
51
|
-
const total = keyQuery || params.id ? rows.length : await pg.queryCache(`select count(*) from ${table} t where ${where.join(' and ') || 'true'}`).then((el) => el?.rows[0]?.count);
|
|
52
|
-
|
|
53
|
-
await metaFormat({ rows, table: params.table });
|
|
54
|
-
return {
|
|
55
|
-
time: Date.now() - time, total, count: rows.length, pk, form, rows, meta, columns, filters,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
1
|
+
import getTemplate from './utils/getTemplate.js';
|
|
2
|
+
import getFilterSQL from '../funcs/getFilterSQL/index.js';
|
|
3
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
+
import metaFormat from '../funcs/metaFormat/index.js';
|
|
5
|
+
|
|
6
|
+
const maxLimit = 100;
|
|
7
|
+
export default async function data(req) {
|
|
8
|
+
const time = Date.now();
|
|
9
|
+
const {
|
|
10
|
+
pg, params, query = {},
|
|
11
|
+
} = req;
|
|
12
|
+
|
|
13
|
+
const loadTable = await getTemplate('table', params.table);
|
|
14
|
+
|
|
15
|
+
if (!loadTable) { return { status: 404, message: 'not found' }; }
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
table, columns, sql, filters, form, meta,
|
|
19
|
+
} = loadTable;
|
|
20
|
+
const { pk } = await getMeta(table);
|
|
21
|
+
|
|
22
|
+
const cols = columns.map((el) => el.name || el).join(',');
|
|
23
|
+
const sqlTable = sql?.filter?.((el) => !el?.disabled && el?.sql?.replace).map((el, i) => ` left join lateral (${el.sql}) ${el.name || `t${i}`} on 1=1 `)?.join('') || '';
|
|
24
|
+
|
|
25
|
+
const fData = query.filter ? await getFilterSQL({
|
|
26
|
+
filter: query.filter,
|
|
27
|
+
table: params.table,
|
|
28
|
+
json: 1,
|
|
29
|
+
}) : {};
|
|
30
|
+
|
|
31
|
+
const keyQuery = query.key && loadTable.key && !params.id ? `${loadTable.key}=$1` : null;
|
|
32
|
+
|
|
33
|
+
const limit = Math.min(maxLimit, +(query.limit || 10));
|
|
34
|
+
|
|
35
|
+
const offset = query.page && query.page > 0 ? ` offset ${(query.page - 1) * limit}` : '';
|
|
36
|
+
// id, query, filter
|
|
37
|
+
const [orderColumn, orderDir] = (query.order || loadTable.order || '').split(/[- ]/);
|
|
38
|
+
|
|
39
|
+
const order = cols.includes(orderColumn) && orderColumn?.length ? `order by ${orderColumn} ${query.desc || orderDir === 'desc' ? 'desc' : ''}` : '';
|
|
40
|
+
const state = loadTable.filterState && query.state ? loadTable.filterState[query.state]?.sql : null;
|
|
41
|
+
const custom = loadTable.filterCustom && query.custom ? loadTable.filterCustom[query.custom]?.sql : null;
|
|
42
|
+
const search = loadTable.meta?.search && query.search ? `(${loadTable.meta?.search.split(',').map(el => `${el} ilike '%${query.search}%'`).join(' or ')})` : null;
|
|
43
|
+
|
|
44
|
+
const where = [(params.id ? ` "${pk}" = $1` : null), keyQuery, loadTable.query, fData.q, state, custom, search].filter((el) => el);
|
|
45
|
+
const q = `select ${pk ? `"${pk}" as id,` : ''} ${query.id || query.key ? '*' : cols || '*'} from ${table} t ${sqlTable} where ${where.join(' and ') || 'true'} ${order} ${offset} limit ${limit}`;
|
|
46
|
+
|
|
47
|
+
if (query.sql === '1') { return q; }
|
|
48
|
+
|
|
49
|
+
const { rows } = await pg.query(q, (params.id ? [params.id] : null) || (query.key && loadTable.key ? [query.key] : []));
|
|
50
|
+
|
|
51
|
+
const total = keyQuery || params.id ? rows.length : await pg.queryCache(`select count(*) from ${table} t where ${where.join(' and ') || 'true'}`).then((el) => el?.rows[0]?.count);
|
|
52
|
+
|
|
53
|
+
await metaFormat({ rows, table: params.table });
|
|
54
|
+
return {
|
|
55
|
+
time: Date.now() - time, total, count: rows.length, pk, form, rows, meta, columns, filters,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import getTemplate from './utils/getTemplate.js';
|
|
2
|
-
import getSelect from './utils/getSelect.js';
|
|
3
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
-
|
|
5
|
-
export default async function filter(req) {
|
|
6
|
-
const time = Date.now();
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
params,
|
|
10
|
-
} = req;
|
|
11
|
-
const loadTable = await getTemplate('table', params.table);
|
|
12
|
-
if (!loadTable) { return { status: 404, message: 'not found' }; }
|
|
13
|
-
const { columns } = await getMeta({ table: loadTable.table });
|
|
14
|
-
|
|
15
|
-
const filters = loadTable?.filters || loadTable?.filterList || [];
|
|
16
|
-
await Promise.all(filters.filter((el) => el.data).map(async (el) => {
|
|
17
|
-
const cls = await getSelect(el.data);
|
|
18
|
-
if (!cls?.arr || !loadTable.table) return;
|
|
19
|
-
const { dataTypeID } = columns.find((item) => item.name === el.id) || {};
|
|
20
|
-
const countArr = req.pg.pgType[dataTypeID]?.includes('[]')
|
|
21
|
-
? await req.pg.queryCache(`select unnest(${el.id})::text as id,count(*) from ${loadTable.table} group by unnest(${el.id})`)
|
|
22
|
-
: await req.pg.queryCache(`select ${el.id}::text as id,count(*) from ${loadTable.table} group by ${el.id}`);
|
|
23
|
-
|
|
24
|
-
const options = countArr.rows.map(cel => {
|
|
25
|
-
const data = cls?.arr.find(c => c.id === cel.id);
|
|
26
|
-
return { ...cel, ...data };
|
|
27
|
-
});
|
|
28
|
-
Object.assign(el, { options });
|
|
29
|
-
}));
|
|
30
|
-
return {
|
|
31
|
-
time: Date.now() - time,
|
|
32
|
-
list: filters,
|
|
33
|
-
custom: loadTable?.filterCustom?.map(el => ({ label: el.label })),
|
|
34
|
-
inline: loadTable?.filterInline,
|
|
35
|
-
state: loadTable?.filterState?.map(el => ({ label: el.label })),
|
|
36
|
-
};
|
|
37
|
-
}
|
|
1
|
+
import getTemplate from './utils/getTemplate.js';
|
|
2
|
+
import getSelect from './utils/getSelect.js';
|
|
3
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
+
|
|
5
|
+
export default async function filter(req) {
|
|
6
|
+
const time = Date.now();
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
params,
|
|
10
|
+
} = req;
|
|
11
|
+
const loadTable = await getTemplate('table', params.table);
|
|
12
|
+
if (!loadTable) { return { status: 404, message: 'not found' }; }
|
|
13
|
+
const { columns } = await getMeta({ table: loadTable.table });
|
|
14
|
+
|
|
15
|
+
const filters = loadTable?.filters || loadTable?.filterList || [];
|
|
16
|
+
await Promise.all(filters.filter((el) => el.data).map(async (el) => {
|
|
17
|
+
const cls = await getSelect(el.data);
|
|
18
|
+
if (!cls?.arr || !loadTable.table) return;
|
|
19
|
+
const { dataTypeID } = columns.find((item) => item.name === el.id) || {};
|
|
20
|
+
const countArr = req.pg.pgType[dataTypeID]?.includes('[]')
|
|
21
|
+
? await req.pg.queryCache(`select unnest(${el.id})::text as id,count(*) from ${loadTable.table} group by unnest(${el.id})`)
|
|
22
|
+
: await req.pg.queryCache(`select ${el.id}::text as id,count(*) from ${loadTable.table} group by ${el.id}`);
|
|
23
|
+
|
|
24
|
+
const options = countArr.rows.map(cel => {
|
|
25
|
+
const data = cls?.arr.find(c => c.id === cel.id);
|
|
26
|
+
return { ...cel, ...data };
|
|
27
|
+
});
|
|
28
|
+
Object.assign(el, { options });
|
|
29
|
+
}));
|
|
30
|
+
return {
|
|
31
|
+
time: Date.now() - time,
|
|
32
|
+
list: filters,
|
|
33
|
+
custom: loadTable?.filterCustom?.map(el => ({ label: el.label })),
|
|
34
|
+
inline: loadTable?.filterInline,
|
|
35
|
+
state: loadTable?.filterState?.map(el => ({ label: el.label })),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import getTemplate from './utils/getTemplate.js';
|
|
2
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
-
import metaFormat from '../funcs/metaFormat/index.js';
|
|
4
|
-
|
|
5
|
-
const maxLimit = 100;
|
|
6
|
-
|
|
7
|
-
export default async function data({
|
|
8
|
-
pg, query = {},
|
|
9
|
-
}) {
|
|
10
|
-
const time = Date.now();
|
|
11
|
-
|
|
12
|
-
const loadTable = await getTemplate('table', query.table);
|
|
13
|
-
|
|
14
|
-
if (!loadTable) { return { message: 'not found', status: 404 }; }
|
|
15
|
-
|
|
16
|
-
const { table, columns, meta } = loadTable;
|
|
17
|
-
const { pk } = await getMeta(table);
|
|
18
|
-
|
|
19
|
-
const cols = columns.map((el) => el.name || el).join(',');
|
|
20
|
-
const [orderColumn, orderDir] = (query.order || loadTable.order || '').split('-');
|
|
21
|
-
const order = cols.includes(orderColumn) && orderColumn?.length ? `order by ${orderColumn} ${query.desc || orderDir === 'desc' ? 'desc' : ''}` : '';
|
|
22
|
-
|
|
23
|
-
const limit = Math.min(maxLimit, +(query.limit || 10));
|
|
24
|
-
const offset = query.page && query.page > 0 ? ` offset ${(query.page - 1) * limit}` : '';
|
|
25
|
-
|
|
26
|
-
const search = meta?.search && query.key ? `(${meta?.search.concat(meta?.title ? `,${meta?.title}` : '').split(',').map(el => `${el} ilike '%${query.key}%'`).join(' or ')})` : null;
|
|
27
|
-
|
|
28
|
-
const where = [loadTable.query, search].filter((el) => el);
|
|
29
|
-
const q = `select ${pk ? `"${pk}" as id,` : ''} * from ${table} t where ${where.join(' and ') || 'true'} ${order} ${offset} limit ${limit}`;
|
|
30
|
-
|
|
31
|
-
if (query.sql === '1') return q;
|
|
32
|
-
|
|
33
|
-
const { rows } = await pg.query(q);
|
|
34
|
-
|
|
35
|
-
const total = await pg.queryCache(`select count(*) from ${table} t where ${where.join(' and ') || 'true'}`).then((el) => el?.rows[0]?.count);
|
|
36
|
-
|
|
37
|
-
await metaFormat({ rows, table: query.table });
|
|
38
|
-
return {
|
|
39
|
-
time: Date.now() - time, total, count: rows.length, rows,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
1
|
+
import getTemplate from './utils/getTemplate.js';
|
|
2
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
+
import metaFormat from '../funcs/metaFormat/index.js';
|
|
4
|
+
|
|
5
|
+
const maxLimit = 100;
|
|
6
|
+
|
|
7
|
+
export default async function data({
|
|
8
|
+
pg, query = {},
|
|
9
|
+
}) {
|
|
10
|
+
const time = Date.now();
|
|
11
|
+
|
|
12
|
+
const loadTable = await getTemplate('table', query.table);
|
|
13
|
+
|
|
14
|
+
if (!loadTable) { return { message: 'not found', status: 404 }; }
|
|
15
|
+
|
|
16
|
+
const { table, columns, meta } = loadTable;
|
|
17
|
+
const { pk } = await getMeta(table);
|
|
18
|
+
|
|
19
|
+
const cols = columns.map((el) => el.name || el).join(',');
|
|
20
|
+
const [orderColumn, orderDir] = (query.order || loadTable.order || '').split('-');
|
|
21
|
+
const order = cols.includes(orderColumn) && orderColumn?.length ? `order by ${orderColumn} ${query.desc || orderDir === 'desc' ? 'desc' : ''}` : '';
|
|
22
|
+
|
|
23
|
+
const limit = Math.min(maxLimit, +(query.limit || 10));
|
|
24
|
+
const offset = query.page && query.page > 0 ? ` offset ${(query.page - 1) * limit}` : '';
|
|
25
|
+
|
|
26
|
+
const search = meta?.search && query.key ? `(${meta?.search.concat(meta?.title ? `,${meta?.title}` : '').split(',').map(el => `${el} ilike '%${query.key}%'`).join(' or ')})` : null;
|
|
27
|
+
|
|
28
|
+
const where = [loadTable.query, search].filter((el) => el);
|
|
29
|
+
const q = `select ${pk ? `"${pk}" as id,` : ''} * from ${table} t where ${where.join(' and ') || 'true'} ${order} ${offset} limit ${limit}`;
|
|
30
|
+
|
|
31
|
+
if (query.sql === '1') return q;
|
|
32
|
+
|
|
33
|
+
const { rows } = await pg.query(q);
|
|
34
|
+
|
|
35
|
+
const total = await pg.queryCache(`select count(*) from ${table} t where ${where.join(' and ') || 'true'}`).then((el) => el?.rows[0]?.count);
|
|
36
|
+
|
|
37
|
+
await metaFormat({ rows, table: query.table });
|
|
38
|
+
return {
|
|
39
|
+
time: Date.now() - time, total, count: rows.length, rows,
|
|
40
|
+
};
|
|
41
|
+
}
|