@opengis/fastify-table 1.2.19 → 1.2.21
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/index.js +82 -79
- package/package.json +1 -1
- package/server/migrations/0.sql +84 -84
- package/server/migrations/properties.sql +184 -184
- package/server/migrations/template.sql +34 -34
- package/server/migrations/users.sql +175 -175
- package/server/plugins/crud/funcs/dataDelete.js +24 -24
- package/server/plugins/crud/funcs/dataInsert.js +53 -53
- package/server/plugins/crud/funcs/dataUpdate.js +65 -65
- package/server/plugins/crud/funcs/utils/logChanges.js +118 -118
- package/server/plugins/logger/getLogger.js +13 -3
- package/server/plugins/metric/index.js +8 -0
- package/server/plugins/metric/loggerSystem.js +129 -0
- package/server/plugins/metric/systemMetricsFifthly.js +23 -0
- package/server/plugins/migration/exec.migrations.js +37 -37
- package/server/plugins/policy/index.js +12 -12
- package/server/plugins/table/funcs/getFilterSQL/util/formatValue.js +179 -179
- package/server/plugins/table/funcs/getFilterSQL/util/getFilterQuery.js +66 -66
- package/server/plugins/table/funcs/metaFormat/getSelectVal.js +50 -50
- package/server/plugins/table/funcs/metaFormat/index.js +45 -45
- package/server/routes/crud/controllers/deleteCrud.js +39 -39
- package/server/routes/table/controllers/filter.js +67 -67
- package/server/routes/table/controllers/suggest.js +166 -166
- package/utils.js +129 -129
|
@@ -1,176 +1,176 @@
|
|
|
1
|
-
create schema if not exists admin;
|
|
2
|
-
|
|
3
|
-
-- DROP TABLE is exists admin.users;
|
|
4
|
-
CREATE TABLE if not exists admin.users();
|
|
5
|
-
ALTER TABLE admin.users add column if not exists uid text NOT NULL DEFAULT next_id();
|
|
6
|
-
ALTER TABLE admin.users DROP CONSTRAINT if exists admin_user_uid_pkey cascade;
|
|
7
|
-
ALTER TABLE admin.users DROP CONSTRAINT if exists user_pk cascade;
|
|
8
|
-
ALTER TABLE admin.users DROP CONSTRAINT if exists admin_user_user_rnokpp;
|
|
9
|
-
|
|
10
|
-
ALTER TABLE admin.users add column if not exists login text;
|
|
11
|
-
ALTER TABLE admin.users add column if not exists password text NOT NULL DEFAULT ''::text;
|
|
12
|
-
ALTER TABLE admin.users add column if not exists user_name text;
|
|
13
|
-
ALTER TABLE admin.users add column if not exists sur_name text;
|
|
14
|
-
ALTER TABLE admin.users add column if not exists father_name text;
|
|
15
|
-
ALTER TABLE admin.users add column if not exists email text;
|
|
16
|
-
ALTER TABLE admin.users add column if not exists phone text;
|
|
17
|
-
ALTER TABLE admin.users add column if not exists avatar text;
|
|
18
|
-
ALTER TABLE admin.users add column if not exists enabled boolean;
|
|
19
|
-
ALTER TABLE admin.users add column if not exists user_personal_code text;
|
|
20
|
-
ALTER TABLE admin.users add column if not exists last_activity_date timestamp without time zone;
|
|
21
|
-
ALTER TABLE admin.users add column if not exists user_type text DEFAULT 'regular'::text;
|
|
22
|
-
ALTER TABLE admin.users add column if not exists user_rnokpp text;
|
|
23
|
-
ALTER TABLE admin.users alter column user_rnokpp drop not null;
|
|
24
|
-
ALTER TABLE admin.users add column if not exists social_auth_id text;
|
|
25
|
-
ALTER TABLE admin.users add column if not exists social_auth_type text;
|
|
26
|
-
ALTER TABLE admin.users add column if not exists salt text;
|
|
27
|
-
ALTER TABLE admin.users add column if not exists cdate timestamp without time zone DEFAULT date_trunc('seconds'::text, now());
|
|
28
|
-
ALTER TABLE admin.users add column if not exists editor_id text;
|
|
29
|
-
ALTER TABLE admin.users add column if not exists editor_date timestamp without time zone;
|
|
30
|
-
|
|
31
|
-
ALTER TABLE admin.users add CONSTRAINT admin_user_uid_pkey PRIMARY KEY (uid);
|
|
32
|
-
ALTER TABLE admin.users add CONSTRAINT admin_user_user_rnokpp UNIQUE (user_rnokpp);
|
|
33
|
-
|
|
34
|
-
COMMENT ON TABLE admin.users IS 'Користувачі';
|
|
35
|
-
|
|
36
|
-
COMMENT ON COLUMN admin.users.uid IS 'ID користувача';
|
|
37
|
-
COMMENT ON COLUMN admin.users.login IS 'Логін користувача';
|
|
38
|
-
COMMENT ON COLUMN admin.users.password IS 'Пароль користувача';
|
|
39
|
-
COMMENT ON COLUMN admin.users.user_name IS 'Ім''я користувача';
|
|
40
|
-
COMMENT ON COLUMN admin.users.sur_name IS 'Прізвище користувача';
|
|
41
|
-
COMMENT ON COLUMN admin.users.father_name IS 'По-батькові користувача';
|
|
42
|
-
COMMENT ON COLUMN admin.users.email IS 'Ел. пошта користувача';
|
|
43
|
-
COMMENT ON COLUMN admin.users.phone IS 'Номер телефону користувача';
|
|
44
|
-
COMMENT ON COLUMN admin.users.avatar IS 'Аватар';
|
|
45
|
-
COMMENT ON COLUMN admin.users.enabled IS 'On / Off';
|
|
46
|
-
COMMENT ON COLUMN admin.users.last_activity_date IS 'Дата останньої активності';
|
|
47
|
-
COMMENT ON COLUMN admin.users.user_type IS 'Тип користувача';
|
|
48
|
-
COMMENT ON COLUMN admin.users.salt IS 'Сіль';
|
|
49
|
-
|
|
50
|
-
CREATE EXTENSION if not exists pgcrypto SCHEMA public VERSION "1.3";
|
|
51
|
-
CREATE OR REPLACE FUNCTION admin.crypt(text, text) RETURNS text AS '$libdir/pgcrypto', 'pg_crypt' LANGUAGE c IMMUTABLE STRICT COST 1;
|
|
52
|
-
|
|
53
|
-
-- DROP FUNCTION admin.insert_update_user_before();
|
|
54
|
-
CREATE OR REPLACE FUNCTION admin.insert_update_user_before()
|
|
55
|
-
RETURNS trigger AS
|
|
56
|
-
|
|
57
|
-
$BODY$
|
|
58
|
-
DECLARE
|
|
59
|
-
|
|
60
|
-
iterations int;
|
|
61
|
-
hash character varying;
|
|
62
|
-
|
|
63
|
-
BEGIN
|
|
64
|
-
|
|
65
|
-
if(TG_OP='INSERT' or (TG_OP='UPDATE' and new.password<>old.password)) then
|
|
66
|
-
if(char_length(new.password) <> 0 and char_length(new.password) < 8) then
|
|
67
|
-
--raise exception 'password must be longer than 8 characters';
|
|
68
|
-
end if;
|
|
69
|
-
new.salt=md5(now()::text);
|
|
70
|
-
--raise exception '%','change pass';
|
|
71
|
-
if(new.salt ='') then
|
|
72
|
-
new.salt=gen_salt('md5');
|
|
73
|
-
end if;
|
|
74
|
-
iterations = 10;
|
|
75
|
-
hash='';
|
|
76
|
-
|
|
77
|
-
loop
|
|
78
|
-
if iterations=0 then
|
|
79
|
-
exit;
|
|
80
|
-
end if;
|
|
81
|
-
hash = md5(new.password||hash||new.salt);
|
|
82
|
-
iterations=iterations-1;
|
|
83
|
-
end loop;
|
|
84
|
-
new.password=admin.crypt(hash,new.salt);
|
|
85
|
-
|
|
86
|
-
end if;
|
|
87
|
-
RETURN new;
|
|
88
|
-
END
|
|
89
|
-
$BODY$
|
|
90
|
-
|
|
91
|
-
LANGUAGE plpgsql VOLATILE COST 100;
|
|
92
|
-
|
|
93
|
-
DROP TRIGGER if exists insert_update_user_before on admin.users;
|
|
94
|
-
CREATE TRIGGER insert_update_user_before BEFORE INSERT OR UPDATE ON admin.users FOR EACH ROW
|
|
95
|
-
EXECUTE PROCEDURE admin.insert_update_user_before();
|
|
96
|
-
|
|
97
|
-
-- DROP TABLE is exists admin.users_social_auth;
|
|
98
|
-
CREATE TABLE if not exists admin.users_social_auth();
|
|
99
|
-
ALTER TABLE admin.users_social_auth add column if not exists users_social_auth_id text NOT NULL DEFAULT next_id();
|
|
100
|
-
ALTER TABLE admin.users_social_auth alter column users_social_auth_id set DEFAULT next_id();
|
|
101
|
-
ALTER TABLE admin.users_social_auth DROP CONSTRAINT if exists users_social_auth_pk cascade;
|
|
102
|
-
ALTER TABLE admin.users_social_auth DROP CONSTRAINT if exists users_social_auth_users_fk cascade;
|
|
103
|
-
ALTER TABLE admin.users_social_auth DROP CONSTRAINT if exists users_social_auth_social_id_email_unique;
|
|
104
|
-
|
|
105
|
-
ALTER TABLE admin.users_social_auth add column if not exists uid text not null;
|
|
106
|
-
ALTER TABLE admin.users_social_auth add column if not exists user_name text;
|
|
107
|
-
ALTER TABLE admin.users_social_auth add column if not exists sur_name text;
|
|
108
|
-
ALTER TABLE admin.users_social_auth add column if not exists email text;
|
|
109
|
-
ALTER TABLE admin.users_social_auth add column if not exists city text;
|
|
110
|
-
ALTER TABLE admin.users_social_auth add column if not exists phone text;
|
|
111
|
-
ALTER TABLE admin.users_social_auth add column if not exists social_auth_id text;
|
|
112
|
-
ALTER TABLE admin.users_social_auth add column if not exists social_auth_type text;
|
|
113
|
-
ALTER TABLE admin.users_social_auth add column if not exists social_auth_code text;
|
|
114
|
-
ALTER TABLE admin.users_social_auth add column if not exists social_auth_obj json;
|
|
115
|
-
ALTER TABLE admin.users_social_auth add column if not exists social_auth_date timestamp without time zone;
|
|
116
|
-
ALTER TABLE admin.users_social_auth add column if not exists social_auth_softpro_code text;
|
|
117
|
-
ALTER TABLE admin.users_social_auth add column if not exists enabled boolean;
|
|
118
|
-
ALTER TABLE admin.users_social_auth add column if not exists cdate timestamp without time zone;
|
|
119
|
-
ALTER TABLE admin.users_social_auth alter column cdate SET DEFAULT date_trunc('seconds'::text, now());
|
|
120
|
-
|
|
121
|
-
ALTER TABLE admin.users_social_auth add column if not exists editor_id text;
|
|
122
|
-
ALTER TABLE admin.users_social_auth add column if not exists lang text;
|
|
123
|
-
ALTER TABLE admin.users_social_auth add column if not exists editor_date timestamp without time zone;
|
|
124
|
-
ALTER TABLE admin.users_social_auth add column if not exists social_auth_url text;
|
|
125
|
-
ALTER TABLE admin.users_social_auth add CONSTRAINT users_social_auth_pk PRIMARY KEY (users_social_auth_id);
|
|
126
|
-
ALTER TABLE admin.users_social_auth add CONSTRAINT users_social_auth_users_fk FOREIGN KEY (uid) REFERENCES admin.users (uid) MATCH SIMPLE on delete cascade;
|
|
127
|
-
ALTER TABLE admin.users_social_auth add CONSTRAINT users_social_auth_social_id_email_unique UNIQUE (social_auth_id,email);
|
|
128
|
-
|
|
129
|
-
COMMENT ON COLUMN admin.users_social_auth.uid IS 'id пользователя';
|
|
130
|
-
COMMENT ON COLUMN admin.users_social_auth.user_name IS 'Имя пользователя';
|
|
131
|
-
COMMENT ON COLUMN admin.users_social_auth.sur_name IS 'Фамилия';
|
|
132
|
-
COMMENT ON COLUMN admin.users_social_auth.email IS 'email пользователя';
|
|
133
|
-
COMMENT ON COLUMN admin.users_social_auth.city IS 'Місто';
|
|
134
|
-
COMMENT ON COLUMN admin.users_social_auth.phone IS 'Телефон';
|
|
135
|
-
COMMENT ON COLUMN admin.users_social_auth.social_auth_id IS 'ID в соцсети';
|
|
136
|
-
COMMENT ON COLUMN admin.users_social_auth.social_auth_type IS 'тип соцсети';
|
|
137
|
-
COMMENT ON COLUMN admin.users_social_auth.social_auth_code IS 'код обьекта соцсети, используеться соцсетью';
|
|
138
|
-
COMMENT ON COLUMN admin.users_social_auth.social_auth_obj IS 'обьект соцсети';
|
|
139
|
-
COMMENT ON COLUMN admin.users_social_auth.social_auth_date IS 'время получение последнего обьекта соцсети';
|
|
140
|
-
COMMENT ON COLUMN admin.users_social_auth.social_auth_softpro_code IS 'код обьекта соцсети, создаваемый и используемый сервером авторизации';
|
|
141
|
-
COMMENT ON COLUMN admin.users_social_auth.enabled IS 'Выключатель';
|
|
142
|
-
COMMENT ON COLUMN admin.users_social_auth.social_auth_url IS 'URL для QR code';
|
|
143
|
-
|
|
144
|
-
CREATE TABLE IF NOT EXISTS admin.user_cls();
|
|
145
|
-
ALTER TABLE admin.user_cls DROP CONSTRAINT IF EXISTS admin_user_cls_pkey;
|
|
146
|
-
ALTER TABLE admin.user_cls DROP CONSTRAINT IF EXISTS admin_user_unique;
|
|
147
|
-
|
|
148
|
-
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS user_clsid text;
|
|
149
|
-
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS code text;
|
|
150
|
-
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS parent text;
|
|
151
|
-
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS name text;
|
|
152
|
-
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS icon text;
|
|
153
|
-
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS data text;
|
|
154
|
-
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS type text;
|
|
155
|
-
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS files json;
|
|
156
|
-
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS cdate timestamp without time zone;
|
|
157
|
-
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS editor_id text;
|
|
158
|
-
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
|
|
159
|
-
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS uid text;
|
|
160
|
-
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS color text;
|
|
161
|
-
|
|
162
|
-
ALTER TABLE admin.user_cls ALTER COLUMN user_clsid SET NOT NULL;
|
|
163
|
-
ALTER TABLE admin.user_cls ALTER COLUMN user_clsid SET DEFAULT next_id();
|
|
164
|
-
ALTER TABLE admin.user_cls ALTER COLUMN cdate SET DEFAULT (now())::timestamp without time zone;
|
|
165
|
-
ALTER TABLE admin.user_cls ALTER COLUMN uid SET NOT NULL;
|
|
166
|
-
ALTER TABLE admin.user_cls ALTER COLUMN uid SET DEFAULT '1'::text;
|
|
167
|
-
|
|
168
|
-
ALTER TABLE admin.user_cls ADD CONSTRAINT admin_user_cls_pkey PRIMARY KEY(user_clsid);
|
|
169
|
-
ALTER TABLE admin.user_cls ADD CONSTRAINT admin_user_unique UNIQUE(code, parent);
|
|
170
|
-
|
|
171
|
-
COMMENT ON TABLE admin.user_cls IS 'Користувацькі класифікатори';
|
|
172
|
-
COMMENT ON COLUMN admin.user_cls.user_clsid IS 'ID';
|
|
173
|
-
COMMENT ON COLUMN admin.user_cls.code IS 'Код';
|
|
174
|
-
COMMENT ON COLUMN admin.user_cls.name IS 'Назва';
|
|
175
|
-
COMMENT ON COLUMN admin.user_cls.icon IS 'Іконка';
|
|
1
|
+
create schema if not exists admin;
|
|
2
|
+
|
|
3
|
+
-- DROP TABLE is exists admin.users;
|
|
4
|
+
CREATE TABLE if not exists admin.users();
|
|
5
|
+
ALTER TABLE admin.users add column if not exists uid text NOT NULL DEFAULT next_id();
|
|
6
|
+
ALTER TABLE admin.users DROP CONSTRAINT if exists admin_user_uid_pkey cascade;
|
|
7
|
+
ALTER TABLE admin.users DROP CONSTRAINT if exists user_pk cascade;
|
|
8
|
+
ALTER TABLE admin.users DROP CONSTRAINT if exists admin_user_user_rnokpp;
|
|
9
|
+
|
|
10
|
+
ALTER TABLE admin.users add column if not exists login text;
|
|
11
|
+
ALTER TABLE admin.users add column if not exists password text NOT NULL DEFAULT ''::text;
|
|
12
|
+
ALTER TABLE admin.users add column if not exists user_name text;
|
|
13
|
+
ALTER TABLE admin.users add column if not exists sur_name text;
|
|
14
|
+
ALTER TABLE admin.users add column if not exists father_name text;
|
|
15
|
+
ALTER TABLE admin.users add column if not exists email text;
|
|
16
|
+
ALTER TABLE admin.users add column if not exists phone text;
|
|
17
|
+
ALTER TABLE admin.users add column if not exists avatar text;
|
|
18
|
+
ALTER TABLE admin.users add column if not exists enabled boolean;
|
|
19
|
+
ALTER TABLE admin.users add column if not exists user_personal_code text;
|
|
20
|
+
ALTER TABLE admin.users add column if not exists last_activity_date timestamp without time zone;
|
|
21
|
+
ALTER TABLE admin.users add column if not exists user_type text DEFAULT 'regular'::text;
|
|
22
|
+
ALTER TABLE admin.users add column if not exists user_rnokpp text;
|
|
23
|
+
ALTER TABLE admin.users alter column user_rnokpp drop not null;
|
|
24
|
+
ALTER TABLE admin.users add column if not exists social_auth_id text;
|
|
25
|
+
ALTER TABLE admin.users add column if not exists social_auth_type text;
|
|
26
|
+
ALTER TABLE admin.users add column if not exists salt text;
|
|
27
|
+
ALTER TABLE admin.users add column if not exists cdate timestamp without time zone DEFAULT date_trunc('seconds'::text, now());
|
|
28
|
+
ALTER TABLE admin.users add column if not exists editor_id text;
|
|
29
|
+
ALTER TABLE admin.users add column if not exists editor_date timestamp without time zone;
|
|
30
|
+
|
|
31
|
+
ALTER TABLE admin.users add CONSTRAINT admin_user_uid_pkey PRIMARY KEY (uid);
|
|
32
|
+
ALTER TABLE admin.users add CONSTRAINT admin_user_user_rnokpp UNIQUE (user_rnokpp);
|
|
33
|
+
|
|
34
|
+
COMMENT ON TABLE admin.users IS 'Користувачі';
|
|
35
|
+
|
|
36
|
+
COMMENT ON COLUMN admin.users.uid IS 'ID користувача';
|
|
37
|
+
COMMENT ON COLUMN admin.users.login IS 'Логін користувача';
|
|
38
|
+
COMMENT ON COLUMN admin.users.password IS 'Пароль користувача';
|
|
39
|
+
COMMENT ON COLUMN admin.users.user_name IS 'Ім''я користувача';
|
|
40
|
+
COMMENT ON COLUMN admin.users.sur_name IS 'Прізвище користувача';
|
|
41
|
+
COMMENT ON COLUMN admin.users.father_name IS 'По-батькові користувача';
|
|
42
|
+
COMMENT ON COLUMN admin.users.email IS 'Ел. пошта користувача';
|
|
43
|
+
COMMENT ON COLUMN admin.users.phone IS 'Номер телефону користувача';
|
|
44
|
+
COMMENT ON COLUMN admin.users.avatar IS 'Аватар';
|
|
45
|
+
COMMENT ON COLUMN admin.users.enabled IS 'On / Off';
|
|
46
|
+
COMMENT ON COLUMN admin.users.last_activity_date IS 'Дата останньої активності';
|
|
47
|
+
COMMENT ON COLUMN admin.users.user_type IS 'Тип користувача';
|
|
48
|
+
COMMENT ON COLUMN admin.users.salt IS 'Сіль';
|
|
49
|
+
|
|
50
|
+
CREATE EXTENSION if not exists pgcrypto SCHEMA public VERSION "1.3";
|
|
51
|
+
CREATE OR REPLACE FUNCTION admin.crypt(text, text) RETURNS text AS '$libdir/pgcrypto', 'pg_crypt' LANGUAGE c IMMUTABLE STRICT COST 1;
|
|
52
|
+
|
|
53
|
+
-- DROP FUNCTION admin.insert_update_user_before();
|
|
54
|
+
CREATE OR REPLACE FUNCTION admin.insert_update_user_before()
|
|
55
|
+
RETURNS trigger AS
|
|
56
|
+
|
|
57
|
+
$BODY$
|
|
58
|
+
DECLARE
|
|
59
|
+
|
|
60
|
+
iterations int;
|
|
61
|
+
hash character varying;
|
|
62
|
+
|
|
63
|
+
BEGIN
|
|
64
|
+
|
|
65
|
+
if(TG_OP='INSERT' or (TG_OP='UPDATE' and new.password<>old.password)) then
|
|
66
|
+
if(char_length(new.password) <> 0 and char_length(new.password) < 8) then
|
|
67
|
+
--raise exception 'password must be longer than 8 characters';
|
|
68
|
+
end if;
|
|
69
|
+
new.salt=md5(now()::text);
|
|
70
|
+
--raise exception '%','change pass';
|
|
71
|
+
if(new.salt ='') then
|
|
72
|
+
new.salt=gen_salt('md5');
|
|
73
|
+
end if;
|
|
74
|
+
iterations = 10;
|
|
75
|
+
hash='';
|
|
76
|
+
|
|
77
|
+
loop
|
|
78
|
+
if iterations=0 then
|
|
79
|
+
exit;
|
|
80
|
+
end if;
|
|
81
|
+
hash = md5(new.password||hash||new.salt);
|
|
82
|
+
iterations=iterations-1;
|
|
83
|
+
end loop;
|
|
84
|
+
new.password=admin.crypt(hash,new.salt);
|
|
85
|
+
|
|
86
|
+
end if;
|
|
87
|
+
RETURN new;
|
|
88
|
+
END
|
|
89
|
+
$BODY$
|
|
90
|
+
|
|
91
|
+
LANGUAGE plpgsql VOLATILE COST 100;
|
|
92
|
+
|
|
93
|
+
DROP TRIGGER if exists insert_update_user_before on admin.users;
|
|
94
|
+
CREATE TRIGGER insert_update_user_before BEFORE INSERT OR UPDATE ON admin.users FOR EACH ROW
|
|
95
|
+
EXECUTE PROCEDURE admin.insert_update_user_before();
|
|
96
|
+
|
|
97
|
+
-- DROP TABLE is exists admin.users_social_auth;
|
|
98
|
+
CREATE TABLE if not exists admin.users_social_auth();
|
|
99
|
+
ALTER TABLE admin.users_social_auth add column if not exists users_social_auth_id text NOT NULL DEFAULT next_id();
|
|
100
|
+
ALTER TABLE admin.users_social_auth alter column users_social_auth_id set DEFAULT next_id();
|
|
101
|
+
ALTER TABLE admin.users_social_auth DROP CONSTRAINT if exists users_social_auth_pk cascade;
|
|
102
|
+
ALTER TABLE admin.users_social_auth DROP CONSTRAINT if exists users_social_auth_users_fk cascade;
|
|
103
|
+
ALTER TABLE admin.users_social_auth DROP CONSTRAINT if exists users_social_auth_social_id_email_unique;
|
|
104
|
+
|
|
105
|
+
ALTER TABLE admin.users_social_auth add column if not exists uid text not null;
|
|
106
|
+
ALTER TABLE admin.users_social_auth add column if not exists user_name text;
|
|
107
|
+
ALTER TABLE admin.users_social_auth add column if not exists sur_name text;
|
|
108
|
+
ALTER TABLE admin.users_social_auth add column if not exists email text;
|
|
109
|
+
ALTER TABLE admin.users_social_auth add column if not exists city text;
|
|
110
|
+
ALTER TABLE admin.users_social_auth add column if not exists phone text;
|
|
111
|
+
ALTER TABLE admin.users_social_auth add column if not exists social_auth_id text;
|
|
112
|
+
ALTER TABLE admin.users_social_auth add column if not exists social_auth_type text;
|
|
113
|
+
ALTER TABLE admin.users_social_auth add column if not exists social_auth_code text;
|
|
114
|
+
ALTER TABLE admin.users_social_auth add column if not exists social_auth_obj json;
|
|
115
|
+
ALTER TABLE admin.users_social_auth add column if not exists social_auth_date timestamp without time zone;
|
|
116
|
+
ALTER TABLE admin.users_social_auth add column if not exists social_auth_softpro_code text;
|
|
117
|
+
ALTER TABLE admin.users_social_auth add column if not exists enabled boolean;
|
|
118
|
+
ALTER TABLE admin.users_social_auth add column if not exists cdate timestamp without time zone;
|
|
119
|
+
ALTER TABLE admin.users_social_auth alter column cdate SET DEFAULT date_trunc('seconds'::text, now());
|
|
120
|
+
|
|
121
|
+
ALTER TABLE admin.users_social_auth add column if not exists editor_id text;
|
|
122
|
+
ALTER TABLE admin.users_social_auth add column if not exists lang text;
|
|
123
|
+
ALTER TABLE admin.users_social_auth add column if not exists editor_date timestamp without time zone;
|
|
124
|
+
ALTER TABLE admin.users_social_auth add column if not exists social_auth_url text;
|
|
125
|
+
ALTER TABLE admin.users_social_auth add CONSTRAINT users_social_auth_pk PRIMARY KEY (users_social_auth_id);
|
|
126
|
+
ALTER TABLE admin.users_social_auth add CONSTRAINT users_social_auth_users_fk FOREIGN KEY (uid) REFERENCES admin.users (uid) MATCH SIMPLE on delete cascade;
|
|
127
|
+
ALTER TABLE admin.users_social_auth add CONSTRAINT users_social_auth_social_id_email_unique UNIQUE (social_auth_id,email);
|
|
128
|
+
|
|
129
|
+
COMMENT ON COLUMN admin.users_social_auth.uid IS 'id пользователя';
|
|
130
|
+
COMMENT ON COLUMN admin.users_social_auth.user_name IS 'Имя пользователя';
|
|
131
|
+
COMMENT ON COLUMN admin.users_social_auth.sur_name IS 'Фамилия';
|
|
132
|
+
COMMENT ON COLUMN admin.users_social_auth.email IS 'email пользователя';
|
|
133
|
+
COMMENT ON COLUMN admin.users_social_auth.city IS 'Місто';
|
|
134
|
+
COMMENT ON COLUMN admin.users_social_auth.phone IS 'Телефон';
|
|
135
|
+
COMMENT ON COLUMN admin.users_social_auth.social_auth_id IS 'ID в соцсети';
|
|
136
|
+
COMMENT ON COLUMN admin.users_social_auth.social_auth_type IS 'тип соцсети';
|
|
137
|
+
COMMENT ON COLUMN admin.users_social_auth.social_auth_code IS 'код обьекта соцсети, используеться соцсетью';
|
|
138
|
+
COMMENT ON COLUMN admin.users_social_auth.social_auth_obj IS 'обьект соцсети';
|
|
139
|
+
COMMENT ON COLUMN admin.users_social_auth.social_auth_date IS 'время получение последнего обьекта соцсети';
|
|
140
|
+
COMMENT ON COLUMN admin.users_social_auth.social_auth_softpro_code IS 'код обьекта соцсети, создаваемый и используемый сервером авторизации';
|
|
141
|
+
COMMENT ON COLUMN admin.users_social_auth.enabled IS 'Выключатель';
|
|
142
|
+
COMMENT ON COLUMN admin.users_social_auth.social_auth_url IS 'URL для QR code';
|
|
143
|
+
|
|
144
|
+
CREATE TABLE IF NOT EXISTS admin.user_cls();
|
|
145
|
+
ALTER TABLE admin.user_cls DROP CONSTRAINT IF EXISTS admin_user_cls_pkey;
|
|
146
|
+
ALTER TABLE admin.user_cls DROP CONSTRAINT IF EXISTS admin_user_unique;
|
|
147
|
+
|
|
148
|
+
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS user_clsid text;
|
|
149
|
+
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS code text;
|
|
150
|
+
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS parent text;
|
|
151
|
+
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS name text;
|
|
152
|
+
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS icon text;
|
|
153
|
+
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS data text;
|
|
154
|
+
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS type text;
|
|
155
|
+
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS files json;
|
|
156
|
+
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS cdate timestamp without time zone;
|
|
157
|
+
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS editor_id text;
|
|
158
|
+
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
|
|
159
|
+
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS uid text;
|
|
160
|
+
ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS color text;
|
|
161
|
+
|
|
162
|
+
ALTER TABLE admin.user_cls ALTER COLUMN user_clsid SET NOT NULL;
|
|
163
|
+
ALTER TABLE admin.user_cls ALTER COLUMN user_clsid SET DEFAULT next_id();
|
|
164
|
+
ALTER TABLE admin.user_cls ALTER COLUMN cdate SET DEFAULT (now())::timestamp without time zone;
|
|
165
|
+
ALTER TABLE admin.user_cls ALTER COLUMN uid SET NOT NULL;
|
|
166
|
+
ALTER TABLE admin.user_cls ALTER COLUMN uid SET DEFAULT '1'::text;
|
|
167
|
+
|
|
168
|
+
ALTER TABLE admin.user_cls ADD CONSTRAINT admin_user_cls_pkey PRIMARY KEY(user_clsid);
|
|
169
|
+
ALTER TABLE admin.user_cls ADD CONSTRAINT admin_user_unique UNIQUE(code, parent);
|
|
170
|
+
|
|
171
|
+
COMMENT ON TABLE admin.user_cls IS 'Користувацькі класифікатори';
|
|
172
|
+
COMMENT ON COLUMN admin.user_cls.user_clsid IS 'ID';
|
|
173
|
+
COMMENT ON COLUMN admin.user_cls.code IS 'Код';
|
|
174
|
+
COMMENT ON COLUMN admin.user_cls.name IS 'Назва';
|
|
175
|
+
COMMENT ON COLUMN admin.user_cls.icon IS 'Іконка';
|
|
176
176
|
COMMENT ON COLUMN admin.user_cls.color IS 'Колір';
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
-
import getRedis from '../../redis/funcs/getRedis.js';
|
|
4
|
-
|
|
5
|
-
import logChanges from './utils/logChanges.js';
|
|
6
|
-
|
|
7
|
-
const rclient = getRedis();
|
|
8
|
-
|
|
9
|
-
export default async function dataDelete({
|
|
10
|
-
table, tokenData, referer, id, pg: pg1, uid,
|
|
11
|
-
}) {
|
|
12
|
-
const pg = pg1 || getPG({ name: 'client' });
|
|
13
|
-
const { pk } = await getMeta({ pg, table });
|
|
14
|
-
const table1 = table.replace(/"/g, '');
|
|
15
|
-
if (!pg.tlist?.includes(table1)) return 'table not exist';
|
|
16
|
-
const delQuery = `delete from ${table} WHERE ${pk} = $1 returning *`;
|
|
17
|
-
|
|
18
|
-
const res = await pg.query(delQuery, [id]).then(el => el.rows?.[0] || {});
|
|
19
|
-
await logChanges({
|
|
20
|
-
pg, table, tokenData, referer, id, uid, type: 'DELETE',
|
|
21
|
-
});
|
|
22
|
-
rclient.incr(`pg:${table}:crud`);
|
|
23
|
-
return res;
|
|
24
|
-
}
|
|
1
|
+
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
+
import getRedis from '../../redis/funcs/getRedis.js';
|
|
4
|
+
|
|
5
|
+
import logChanges from './utils/logChanges.js';
|
|
6
|
+
|
|
7
|
+
const rclient = getRedis();
|
|
8
|
+
|
|
9
|
+
export default async function dataDelete({
|
|
10
|
+
table, tokenData, referer, id, pg: pg1, uid,
|
|
11
|
+
}) {
|
|
12
|
+
const pg = pg1 || getPG({ name: 'client' });
|
|
13
|
+
const { pk } = await getMeta({ pg, table });
|
|
14
|
+
const table1 = table.replace(/"/g, '');
|
|
15
|
+
if (!pg.tlist?.includes(table1)) return 'table not exist';
|
|
16
|
+
const delQuery = `delete from ${table} WHERE ${pk} = $1 returning *`;
|
|
17
|
+
|
|
18
|
+
const res = await pg.query(delQuery, [id]).then(el => el.rows?.[0] || {});
|
|
19
|
+
await logChanges({
|
|
20
|
+
pg, table, tokenData, referer, id, uid, type: 'DELETE',
|
|
21
|
+
});
|
|
22
|
+
rclient.incr(`pg:${table}:crud`);
|
|
23
|
+
return res;
|
|
24
|
+
}
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
-
import getRedis from '../../redis/funcs/getRedis.js';
|
|
4
|
-
|
|
5
|
-
import logChanges from './utils/logChanges.js';
|
|
6
|
-
|
|
7
|
-
const rclient = getRedis();
|
|
8
|
-
|
|
9
|
-
export default async function dataInsert({
|
|
10
|
-
id, table, tokenData, referer, data, pg: pg1, uid,
|
|
11
|
-
}) {
|
|
12
|
-
const pg = pg1 || getPG({ name: 'client' });
|
|
13
|
-
if (!data) return null;
|
|
14
|
-
const { columns } = await getMeta({ pg, table });
|
|
15
|
-
if (!columns) return null;
|
|
16
|
-
|
|
17
|
-
const names = columns.map((el) => el.name);
|
|
18
|
-
|
|
19
|
-
Object.assign(data, {
|
|
20
|
-
...(id && pg.pk?.[table] ? { [pg.pk?.[table]]: id } : {}),
|
|
21
|
-
...(table !== 'admin.users' ? { uid } : {}),
|
|
22
|
-
// editor_id: uid,
|
|
23
|
-
});
|
|
24
|
-
const systemColumns = ['cdate', 'editor_date'].filter((el) => names.includes(el)).map((el) => [el, 'now()']);
|
|
25
|
-
|
|
26
|
-
const filterData = Object.keys(data)
|
|
27
|
-
.filter((el) => !['cdate', 'editor_date'].includes(el) && (typeof data[el] === 'boolean' ? true : data[el]) && names.includes(el)).map((el) => [el, data[el]]);
|
|
28
|
-
|
|
29
|
-
const insertQuery = `insert into ${table}
|
|
30
|
-
|
|
31
|
-
( ${filterData?.map((key) => `"${key[0]}"`).concat(systemColumns.map((el) => el[0])).join(',')})
|
|
32
|
-
|
|
33
|
-
values (${filterData?.map((key, i) => (key[0] === 'geom' ? `st_setsrid(st_geomfromgeojson($${i + 1}::json),4326)` : `$${i + 1}`)).concat(systemColumns.map((el) => el[1])).join(',')})
|
|
34
|
-
|
|
35
|
-
returning *`;
|
|
36
|
-
|
|
37
|
-
const res = await pg.query(insertQuery, [...filterData.map((el) => (typeof el[1] === 'object' && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]))]) || {};
|
|
38
|
-
|
|
39
|
-
const table1 = pg.pk[table] ? table : table.replace(/"/g, '');
|
|
40
|
-
await logChanges({
|
|
41
|
-
pg,
|
|
42
|
-
table,
|
|
43
|
-
tokenData,
|
|
44
|
-
referer,
|
|
45
|
-
data,
|
|
46
|
-
id: res.rows?.[0]?.[pg.pk[table1]],
|
|
47
|
-
uid,
|
|
48
|
-
type: 'INSERT',
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
rclient.incr(`pg:${table}:crud`);
|
|
52
|
-
return res;
|
|
53
|
-
}
|
|
1
|
+
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
+
import getRedis from '../../redis/funcs/getRedis.js';
|
|
4
|
+
|
|
5
|
+
import logChanges from './utils/logChanges.js';
|
|
6
|
+
|
|
7
|
+
const rclient = getRedis();
|
|
8
|
+
|
|
9
|
+
export default async function dataInsert({
|
|
10
|
+
id, table, tokenData, referer, data, pg: pg1, uid,
|
|
11
|
+
}) {
|
|
12
|
+
const pg = pg1 || getPG({ name: 'client' });
|
|
13
|
+
if (!data) return null;
|
|
14
|
+
const { columns } = await getMeta({ pg, table });
|
|
15
|
+
if (!columns) return null;
|
|
16
|
+
|
|
17
|
+
const names = columns.map((el) => el.name);
|
|
18
|
+
|
|
19
|
+
Object.assign(data, {
|
|
20
|
+
...(id && pg.pk?.[table] ? { [pg.pk?.[table]]: id } : {}),
|
|
21
|
+
...(table !== 'admin.users' ? { uid } : {}),
|
|
22
|
+
// editor_id: uid,
|
|
23
|
+
});
|
|
24
|
+
const systemColumns = ['cdate', 'editor_date'].filter((el) => names.includes(el)).map((el) => [el, 'now()']);
|
|
25
|
+
|
|
26
|
+
const filterData = Object.keys(data)
|
|
27
|
+
.filter((el) => !['cdate', 'editor_date'].includes(el) && (typeof data[el] === 'boolean' ? true : data[el]) && names.includes(el)).map((el) => [el, data[el]]);
|
|
28
|
+
|
|
29
|
+
const insertQuery = `insert into ${table}
|
|
30
|
+
|
|
31
|
+
( ${filterData?.map((key) => `"${key[0]}"`).concat(systemColumns.map((el) => el[0])).join(',')})
|
|
32
|
+
|
|
33
|
+
values (${filterData?.map((key, i) => (key[0] === 'geom' ? `st_setsrid(st_geomfromgeojson($${i + 1}::json),4326)` : `$${i + 1}`)).concat(systemColumns.map((el) => el[1])).join(',')})
|
|
34
|
+
|
|
35
|
+
returning *`;
|
|
36
|
+
|
|
37
|
+
const res = await pg.query(insertQuery, [...filterData.map((el) => (typeof el[1] === 'object' && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]))]) || {};
|
|
38
|
+
|
|
39
|
+
const table1 = pg.pk[table] ? table : table.replace(/"/g, '');
|
|
40
|
+
await logChanges({
|
|
41
|
+
pg,
|
|
42
|
+
table,
|
|
43
|
+
tokenData,
|
|
44
|
+
referer,
|
|
45
|
+
data,
|
|
46
|
+
id: res.rows?.[0]?.[pg.pk[table1]],
|
|
47
|
+
uid,
|
|
48
|
+
type: 'INSERT',
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
rclient.incr(`pg:${table}:crud`);
|
|
52
|
+
return res;
|
|
53
|
+
}
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
-
import getRedis from '../../redis/funcs/getRedis.js';
|
|
4
|
-
|
|
5
|
-
import logChanges from './utils/logChanges.js';
|
|
6
|
-
|
|
7
|
-
const rclient = getRedis();
|
|
8
|
-
const srids = {};
|
|
9
|
-
|
|
10
|
-
function assignValue(key, i, srid = 4326, columnType = 'text') {
|
|
11
|
-
if (key === 'geom' && columnType === 'geometry') {
|
|
12
|
-
return `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),4326)`;
|
|
13
|
-
}
|
|
14
|
-
if (key?.includes('geom') && columnType === 'geometry') {
|
|
15
|
-
return `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),${srid})`;
|
|
16
|
-
}
|
|
17
|
-
return `"${key}"=$${i + 2}`;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default async function dataUpdate({
|
|
21
|
-
table, tokenData, referer, id, data, pg: pg1, uid,
|
|
22
|
-
}) {
|
|
23
|
-
if (!data || !table || !id) return null;
|
|
24
|
-
|
|
25
|
-
const pg = pg1 || getPG({ name: 'client' });
|
|
26
|
-
const { columns, pk } = await getMeta({ pg, table });
|
|
27
|
-
|
|
28
|
-
const names = columns?.map((el) => el.name);
|
|
29
|
-
|
|
30
|
-
const filterData = Object.keys(data)
|
|
31
|
-
.filter((el) => (/* typeof data[el] === 'boolean' ? true : data[el] && */ names?.includes(el) && !['editor_date', 'editor_id'].includes(el)));
|
|
32
|
-
|
|
33
|
-
const systemColumns = [['editor_date', 'now()'], uid ? ['editor_id', `'${uid.replace(/'/g, "''")}'`] : []].filter((el) => names.includes(el[0])).map((el) => `${el[0]} = ${el[1]}`).join(',');
|
|
34
|
-
|
|
35
|
-
const filterValue = filterData.map((el) => {
|
|
36
|
-
const { dataTypeID = 25 } = columns?.find?.((col) => col?.name === el) || {};
|
|
37
|
-
if (pg.pgType[dataTypeID]?.endsWith('[]') && ['string', 'number'].includes(typeof data[el])) {
|
|
38
|
-
Object.assign(data, { [el]: data[el].split(',') });
|
|
39
|
-
}
|
|
40
|
-
return [el, data[el]];
|
|
41
|
-
}).map((el) => (typeof el[1] === 'object' && el[1] && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]));
|
|
42
|
-
|
|
43
|
-
// update geometry with srid
|
|
44
|
-
if (!srids[table]) {
|
|
45
|
-
const { srids1 } = await pg.query(`select json_object_agg(_table,rel) as srids1 from (
|
|
46
|
-
select f_table_schema||'.'||f_table_name as _table,
|
|
47
|
-
json_object_agg(f_geometry_column, case when srid = 0 then 4326 else srid end) as rel
|
|
48
|
-
from public.geometry_columns group by f_table_schema||'.'||f_table_name
|
|
49
|
-
)q`).then((res1) => res1.rows?.[0] || {});
|
|
50
|
-
Object.assign(srids, srids1);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const updateQuery = `UPDATE ${table} SET ${systemColumns ? `${systemColumns}${filterData?.length ? ',' : ''}` : ''}
|
|
54
|
-
${filterData?.map((key, i) => assignValue(key, i, srids[table]?.[key] || 4326, pg.pgType?.[columns.find(col => col.name === key)?.dataTypeID || '']))?.join(',')}
|
|
55
|
-
WHERE ${pk} = $1 returning *`;
|
|
56
|
-
// console.log(updateQuery, filterValue);
|
|
57
|
-
const res = await pg.query(updateQuery, [id, ...filterValue]).then(el => el?.rows?.[0]) || {};
|
|
58
|
-
|
|
59
|
-
await logChanges({
|
|
60
|
-
pg, table, tokenData, referer, data, id, uid, type: 'UPDATE',
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
rclient.incr(`pg:${table}:crud`);
|
|
64
|
-
return res;
|
|
65
|
-
}
|
|
1
|
+
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
+
import getRedis from '../../redis/funcs/getRedis.js';
|
|
4
|
+
|
|
5
|
+
import logChanges from './utils/logChanges.js';
|
|
6
|
+
|
|
7
|
+
const rclient = getRedis();
|
|
8
|
+
const srids = {};
|
|
9
|
+
|
|
10
|
+
function assignValue(key, i, srid = 4326, columnType = 'text') {
|
|
11
|
+
if (key === 'geom' && columnType === 'geometry') {
|
|
12
|
+
return `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),4326)`;
|
|
13
|
+
}
|
|
14
|
+
if (key?.includes('geom') && columnType === 'geometry') {
|
|
15
|
+
return `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),${srid})`;
|
|
16
|
+
}
|
|
17
|
+
return `"${key}"=$${i + 2}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default async function dataUpdate({
|
|
21
|
+
table, tokenData, referer, id, data, pg: pg1, uid,
|
|
22
|
+
}) {
|
|
23
|
+
if (!data || !table || !id) return null;
|
|
24
|
+
|
|
25
|
+
const pg = pg1 || getPG({ name: 'client' });
|
|
26
|
+
const { columns, pk } = await getMeta({ pg, table });
|
|
27
|
+
|
|
28
|
+
const names = columns?.map((el) => el.name);
|
|
29
|
+
|
|
30
|
+
const filterData = Object.keys(data)
|
|
31
|
+
.filter((el) => (/* typeof data[el] === 'boolean' ? true : data[el] && */ names?.includes(el) && !['editor_date', 'editor_id'].includes(el)));
|
|
32
|
+
|
|
33
|
+
const systemColumns = [['editor_date', 'now()'], uid ? ['editor_id', `'${uid.replace(/'/g, "''")}'`] : []].filter((el) => names.includes(el[0])).map((el) => `${el[0]} = ${el[1]}`).join(',');
|
|
34
|
+
|
|
35
|
+
const filterValue = filterData.map((el) => {
|
|
36
|
+
const { dataTypeID = 25 } = columns?.find?.((col) => col?.name === el) || {};
|
|
37
|
+
if (pg.pgType[dataTypeID]?.endsWith('[]') && ['string', 'number'].includes(typeof data[el])) {
|
|
38
|
+
Object.assign(data, { [el]: data[el].split(',') });
|
|
39
|
+
}
|
|
40
|
+
return [el, data[el]];
|
|
41
|
+
}).map((el) => (typeof el[1] === 'object' && el[1] && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]));
|
|
42
|
+
|
|
43
|
+
// update geometry with srid
|
|
44
|
+
if (!srids[table]) {
|
|
45
|
+
const { srids1 } = await pg.query(`select json_object_agg(_table,rel) as srids1 from (
|
|
46
|
+
select f_table_schema||'.'||f_table_name as _table,
|
|
47
|
+
json_object_agg(f_geometry_column, case when srid = 0 then 4326 else srid end) as rel
|
|
48
|
+
from public.geometry_columns group by f_table_schema||'.'||f_table_name
|
|
49
|
+
)q`).then((res1) => res1.rows?.[0] || {});
|
|
50
|
+
Object.assign(srids, srids1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const updateQuery = `UPDATE ${table} SET ${systemColumns ? `${systemColumns}${filterData?.length ? ',' : ''}` : ''}
|
|
54
|
+
${filterData?.map((key, i) => assignValue(key, i, srids[table]?.[key] || 4326, pg.pgType?.[columns.find(col => col.name === key)?.dataTypeID || '']))?.join(',')}
|
|
55
|
+
WHERE ${pk} = $1 returning *`;
|
|
56
|
+
// console.log(updateQuery, filterValue);
|
|
57
|
+
const res = await pg.query(updateQuery, [id, ...filterValue]).then(el => el?.rows?.[0]) || {};
|
|
58
|
+
|
|
59
|
+
await logChanges({
|
|
60
|
+
pg, table, tokenData, referer, data, id, uid, type: 'UPDATE',
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
rclient.incr(`pg:${table}:crud`);
|
|
64
|
+
return res;
|
|
65
|
+
}
|