@opengis/fastify-table 1.0.44 → 1.0.46

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # fastify-table
2
2
 
3
+ ## 1.0.46 - 24.06.2024
4
+
5
+ - fix data api edit geometry
6
+
7
+ ## 1.0.45 - 19.06.2024
8
+
9
+ - fix data api table template order
10
+
3
11
  ## 1.0.44 - 18.06.2024
4
12
 
5
13
  - add extra data support (form DataTable)
package/crud/index.js CHANGED
@@ -1,29 +1,29 @@
1
- import getOPt from './funcs/getOpt.js';
2
- import setOpt from './funcs/setOpt.js';
3
- import isFileExists from './funcs/isFileExists.js';
4
- import dataUpdate from './funcs/dataUpdate.js';
5
- import dataInsert from './funcs/dataInsert.js';
6
-
7
- import update from './controllers/update.js';
8
- import insert from './controllers/insert.js';
9
- import deleteCrud from './controllers/deleteCrud.js';
10
-
11
- // import config from '../config.js';
12
-
13
- async function plugin(fastify, config = {}) {
14
- const prefix = config.prefix || '/api';
15
- // funcs
16
- fastify.decorate('setOpt', setOpt);
17
- fastify.decorate('getOpt', getOPt);
18
- fastify.decorate('dataUpdate', dataUpdate);
19
- fastify.decorate('dataInsert', dataInsert);
20
-
21
- fastify.decorate('isFileExists', isFileExists);
22
-
23
- // api
24
- fastify.put(`${prefix}/table/:table/:id`, {}, update);
25
- fastify.delete(`${prefix}/table/:table/:id`, {}, deleteCrud);
26
- fastify.post(`${prefix}/table/:table`, {}, insert);
27
- }
28
-
29
- export default plugin;
1
+ import getOPt from './funcs/getOpt.js';
2
+ import setOpt from './funcs/setOpt.js';
3
+ import isFileExists from './funcs/isFileExists.js';
4
+ import dataUpdate from './funcs/dataUpdate.js';
5
+ import dataInsert from './funcs/dataInsert.js';
6
+
7
+ import update from './controllers/update.js';
8
+ import insert from './controllers/insert.js';
9
+ import deleteCrud from './controllers/deleteCrud.js';
10
+
11
+ // import config from '../config.js';
12
+
13
+ async function plugin(fastify, config = {}) {
14
+ const prefix = config.prefix || '/api';
15
+ // funcs
16
+ fastify.decorate('setOpt', setOpt);
17
+ fastify.decorate('getOpt', getOPt);
18
+ fastify.decorate('dataUpdate', dataUpdate);
19
+ fastify.decorate('dataInsert', dataInsert);
20
+
21
+ fastify.decorate('isFileExists', isFileExists);
22
+
23
+ // api
24
+ fastify.put(`${prefix}/table/:table/:id`, {}, update);
25
+ fastify.delete(`${prefix}/table/:table/:id`, {}, deleteCrud);
26
+ fastify.post(`${prefix}/table/:table`, {}, insert);
27
+ }
28
+
29
+ export default plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.0.44",
3
+ "version": "1.0.46",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",
@@ -0,0 +1,246 @@
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
+
8
+ ALTER TABLE admin.users add column if not exists login text;
9
+ ALTER TABLE admin.users add column if not exists password text NOT NULL DEFAULT ''::text;
10
+ ALTER TABLE admin.users add column if not exists user_name text;
11
+ ALTER TABLE admin.users add column if not exists sur_name text;
12
+ ALTER TABLE admin.users add column if not exists father_name text;
13
+ ALTER TABLE admin.users add column if not exists email text;
14
+ ALTER TABLE admin.users add column if not exists phone text;
15
+ ALTER TABLE admin.users add column if not exists avatar text;
16
+ ALTER TABLE admin.users add column if not exists enabled boolean;
17
+ ALTER TABLE admin.users add column if not exists user_personal_code text;
18
+ ALTER TABLE admin.users add column if not exists last_activity_date timestamp without time zone;
19
+ ALTER TABLE admin.users add column if not exists user_type text DEFAULT 'regular'::text;
20
+ ALTER TABLE admin.users add column if not exists salt text;
21
+ ALTER TABLE admin.users add column if not exists cdate timestamp without time zone DEFAULT date_trunc('seconds'::text, now());
22
+ ALTER TABLE admin.users add column if not exists editor_id text;
23
+ ALTER TABLE admin.users add column if not exists editor_date timestamp without time zone;
24
+
25
+ ALTER TABLE admin.users add CONSTRAINT admin_user_uid_pkey PRIMARY KEY (uid);
26
+
27
+ COMMENT ON COLUMN admin.users.uid IS 'ID користувача';
28
+ COMMENT ON COLUMN admin.users.login IS 'Логін користувача';
29
+ COMMENT ON COLUMN admin.users.password IS 'Пароль користувача';
30
+ COMMENT ON COLUMN admin.users.user_name IS 'Ім''я користувача';
31
+ COMMENT ON COLUMN admin.users.sur_name IS 'Прізвище користувача';
32
+ COMMENT ON COLUMN admin.users.father_name IS 'По-батькові користувача';
33
+ COMMENT ON COLUMN admin.users.email IS 'Ел. пошта користувача';
34
+ COMMENT ON COLUMN admin.users.phone IS 'Номер телефону користувача';
35
+ COMMENT ON COLUMN admin.users.avatar IS 'Аватар';
36
+ COMMENT ON COLUMN admin.users.enabled IS 'Вкл. / Відкл';
37
+ COMMENT ON COLUMN admin.users.last_activity_date IS 'Дата останньої активності';
38
+ COMMENT ON COLUMN admin.users.user_type IS 'Тип користувача';
39
+ COMMENT ON COLUMN admin.users.salt IS 'Сіль';
40
+
41
+ -- drop table if exists admin.user_group;
42
+ CREATE TABLE if not exists admin.user_group();
43
+ alter table admin.user_group DROP CONSTRAINT if exists admin_user_group_id_pkey cascade;
44
+
45
+ ALTER TABLE admin.user_group ADD COLUMN if not exists user_group_id text;
46
+ ALTER TABLE admin.user_group ALTER COLUMN user_group_id SET NOT NULL;
47
+ ALTER TABLE admin.user_group ALTER COLUMN user_group_id SET DEFAULT next_id();
48
+ ALTER TABLE admin.user_group ADD COLUMN if not exists group_name text;
49
+ ALTER TABLE admin.user_group ADD COLUMN if not exists enabled boolean;
50
+ ALTER TABLE admin.user_group ADD COLUMN if not exists cdate timestamp without time zone;
51
+ ALTER TABLE admin.user_group ALTER COLUMN cdate SET DEFAULT date_trunc('seconds'::text, now());
52
+ ALTER TABLE admin.user_group ADD COLUMN if not exists uid text;
53
+ ALTER TABLE admin.user_group ADD COLUMN if not exists editor_id text;
54
+ ALTER TABLE admin.user_group ADD COLUMN if not exists editor_date timestamp without time zone;
55
+
56
+ ALTER TABLE admin.user_group
57
+ ADD CONSTRAINT admin_user_group_id_pkey PRIMARY KEY(user_group_id);
58
+
59
+ COMMENT ON COLUMN admin.user_group.user_group_id IS 'Вкл./Выкл.';
60
+ COMMENT ON COLUMN admin.user_group.group_name IS 'Назва групи';
61
+ COMMENT ON COLUMN admin.user_group.enabled IS 'Вкл./Відкл.';
62
+ COMMENT ON COLUMN admin.user_group.cdate IS 'Дата створення';
63
+ COMMENT ON COLUMN admin.user_group.uid IS 'Хто створив';
64
+ COMMENT ON COLUMN admin.user_group.editor_id IS 'Останній редагувач';
65
+ COMMENT ON COLUMN admin.user_group.editor_date IS 'Дата останнього редагування';
66
+
67
+ -- drop table if exists admin.user_access;
68
+ CREATE TABLE if not exists admin.user_access();
69
+ alter table admin.user_access DROP CONSTRAINT if exists admin_user_access_id_pkey;
70
+ alter table admin.user_access DROP CONSTRAINT if exists admin_user_access_user_group_id_fkey;
71
+ alter table admin.user_access DROP CONSTRAINT if exists admin_user_access_interface_id_uid_unique;
72
+ alter table admin.user_access DROP CONSTRAINT if exists admin_user_access_interface_id_fkey;
73
+
74
+ alter table admin.user_access add column if not exists user_access_id text NOT NULL DEFAULT next_id();
75
+ alter table admin.user_access add column if not exists interface_id text NOT NULL;
76
+ alter table admin.user_access add column if not exists user_group_id text;
77
+ alter table admin.user_access add column if not exists user_uid text;
78
+ alter table admin.user_access add column if not exists scope text;
79
+ alter table admin.user_access add column if not exists actions text[];
80
+ ALTER TABLE admin.user_access ADD COLUMN IF NOT EXISTS access_granted text;
81
+ ALTER TABLE admin.user_access ADD COLUMN IF NOT EXISTS access_granted_time timestamp without time zone;
82
+ alter table admin.user_access add column if not exists cdate timestamp without time zone NOT NULL DEFAULT date_trunc('seconds'::text, now());
83
+ alter table admin.user_access add column if not exists uid text;
84
+ alter table admin.user_access add column if not exists editor_id text;
85
+ alter table admin.user_access add column if not exists editor_date timestamp without time zone;
86
+
87
+ alter table admin.user_access
88
+ add CONSTRAINT admin_user_access_id_pkey PRIMARY KEY (user_access_id);
89
+
90
+ alter table admin.user_access
91
+ add CONSTRAINT admin_user_access_user_group_id_fkey FOREIGN KEY (user_group_id) REFERENCES admin.user_group (user_group_id);
92
+
93
+ alter table admin.user_access
94
+ add CONSTRAINT admin_user_access_interface_id_uid_unique UNIQUE (interface_id, user_uid, user_group_id);
95
+ alter table admin.user_access
96
+ add constraint admin_user_access_interface_id_fkey FOREIGN KEY (interface_id) REFERENCES admin.interface_list(interface_id);
97
+
98
+ COMMENT ON TABLE admin.user_access IS 'Налаштування прав. Відношення груп / окремих користувачів до шаблонів';
99
+ COMMENT ON COLUMN admin.user_access.interface_id IS 'ID шаблона';
100
+ COMMENT ON COLUMN admin.user_access.user_group_id IS 'ID групи';
101
+ COMMENT ON COLUMN admin.user_access.user_uid IS 'ID користувача';
102
+ COMMENT ON COLUMN admin.user_access.scope IS 'Обмеження виведення (власні, відповідальний, всі)';
103
+ COMMENT ON COLUMN admin.user_access.actions IS 'Доступні дії';
104
+ COMMENT ON COLUMN admin.user_access.access_granted IS 'Ідентифікатор користувача який надав доступ';
105
+ COMMENT ON COLUMN admin.user_access.access_granted_time IS 'Час коли надали доступ';
106
+
107
+ CREATE INDEX if not exists admin_user_access_interface_id_idx
108
+ ON admin.user_access USING btree (interface_id COLLATE pg_catalog."default");
109
+
110
+ CREATE INDEX if not exists admin_user_access_user_group_id_idx
111
+ ON admin.user_access USING btree (user_group_id COLLATE pg_catalog."default");
112
+
113
+ -- DROP TABLE if exists admin.user_group_rel;
114
+ CREATE TABLE if not exists admin.user_group_rel();
115
+ ALTER TABLE admin.user_group_rel DROP CONSTRAINT IF EXISTS admin_user_group_rel_pkey;
116
+ ALTER TABLE admin.user_group_rel DROP CONSTRAINT IF EXISTS admin_user_group_rel_user_group_id_fkey;
117
+ ALTER TABLE admin.user_group_rel DROP CONSTRAINT IF EXISTS admin_user_group_rel_user_uid_fkey;
118
+ ALTER TABLE admin.user_group_rel DROP CONSTRAINT IF EXISTS admin_user_group_rel_user_uid_user_group_id_key;
119
+
120
+ ALTER TABLE admin.user_group_rel ADD COLUMN IF NOT EXISTS ugr_id text NOT NULL DEFAULT next_id();
121
+ ALTER TABLE admin.user_group_rel ADD COLUMN IF NOT EXISTS user_uid text NOT NULL;
122
+ ALTER TABLE admin.user_group_rel ADD COLUMN IF NOT EXISTS user_group_id text NOT NULL;
123
+ ALTER TABLE admin.user_group_rel ADD COLUMN IF NOT EXISTS cdate timestamp without time zone DEFAULT date_trunc('seconds'::text, now());
124
+ ALTER TABLE admin.user_group_rel ADD COLUMN IF NOT EXISTS uid text;
125
+ ALTER TABLE admin.user_group_rel ADD COLUMN IF NOT EXISTS editor_id text;
126
+ ALTER TABLE admin.user_group_rel ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
127
+ ALTER TABLE admin.user_group_rel ADD COLUMN IF NOT EXISTS expiration date;
128
+ ALTER TABLE admin.user_group_rel ADD COLUMN IF NOT EXISTS access_granted text;
129
+ ALTER TABLE admin.user_group_rel ADD COLUMN IF NOT EXISTS access_granted_time timestamp without time zone;
130
+
131
+ ALTER TABLE admin.user_group_rel ADD CONSTRAINT admin_user_group_rel_pkey PRIMARY KEY (ugr_id);
132
+ ALTER TABLE admin.user_group_rel ADD CONSTRAINT admin_user_group_rel_user_group_id_fkey FOREIGN KEY (user_group_id) REFERENCES admin.user_group (user_group_id);
133
+ ALTER TABLE admin.user_group_rel ADD CONSTRAINT admin_user_group_rel_user_uid_fkey FOREIGN KEY (user_uid) REFERENCES admin.users (uid);
134
+ ALTER TABLE admin.user_group_rel ADD CONSTRAINT admin_user_group_rel_user_uid_user_group_id_key UNIQUE (user_uid, user_group_id);
135
+
136
+ COMMENT ON TABLE admin.user_group_rel IS 'Відношення користувачів до груп';
137
+ COMMENT ON COLUMN admin.user_group_rel.user_uid IS 'ID користувача';
138
+ COMMENT ON COLUMN admin.user_group_rel.user_group_id IS 'ID групи';
139
+ COMMENT ON COLUMN admin.user_group_rel.uid IS 'Користувач, який створив запис в БД';
140
+ COMMENT ON COLUMN admin.user_group_rel.expiration IS 'закінчення терміну дії доступу до групи';
141
+ COMMENT ON COLUMN admin.user_group_rel.access_granted IS 'Ідентифікатор користувача який надав доступ';
142
+ COMMENT ON COLUMN admin.user_group_rel.access_granted_time IS 'Час коли надали доступ';
143
+
144
+ CREATE INDEX IF NOT EXISTS admin_user_group_access_user_uid_idx ON admin.user_group_rel USING btree (user_uid COLLATE pg_catalog."default");
145
+
146
+ CREATE INDEX IF NOT EXISTS admin_user_group_rel_cdate_btree_idx ON admin.user_group_rel USING btree (cdate);
147
+
148
+ CREATE INDEX IF NOT EXISTS admin_user_group_rel_editor_date_btree_idx ON admin.user_group_rel USING btree (editor_date);
149
+
150
+ CREATE INDEX IF NOT EXISTS admin_user_group_rel_user_uid_gin_idx ON admin.user_group_rel USING gin (user_uid COLLATE pg_catalog."default" gin_trgm_ops);
151
+
152
+ CREATE INDEX IF NOT EXISTS admin_user_group_user_group_id_idx ON admin.user_group_rel USING btree (user_group_id COLLATE pg_catalog."default");
153
+
154
+ -- DROP TABLE if exists admin.menu;
155
+ CREATE TABLE if not exists admin.menu();
156
+ alter table admin.menu DROP CONSTRAINT if exists admin_menu_id_pkey cascade;
157
+ alter table admin.menu DROP CONSTRAINT if exists admin_menu_name_unique;
158
+
159
+ alter table admin.menu add column if not exists menu_id text NOT NULL default next_id();
160
+ alter table admin.menu add column if not exists name text;
161
+ alter table admin.menu add column if not exists ord numeric;
162
+ alter table admin.menu add column if not exists enabled boolean NOT NULL DEFAULT true;
163
+ alter table admin.menu add column if not exists uid text;
164
+ alter table admin.menu add column if not exists editor_id text;
165
+ alter table admin.menu add column if not exists editor_date timestamp without time zone;
166
+ alter table admin.menu add column if not exists cdate timestamp without time zone DEFAULT now();
167
+ alter table admin.menu add CONSTRAINT admin_menu_id_pkey PRIMARY KEY (menu_id);
168
+ alter table admin.menu add CONSTRAINT admin_menu_name_unique UNIQUE (name);
169
+
170
+ COMMENT ON TABLE admin.menu IS 'Пункти меню';
171
+ COMMENT ON COLUMN admin.menu.menu_id IS 'Ідентифікатор пункту меню';
172
+ COMMENT ON COLUMN admin.menu.name IS 'Назва пункту меню';
173
+ COMMENT ON COLUMN admin.menu.ord IS 'Порядковий номер';
174
+ COMMENT ON COLUMN admin.menu.enabled IS 'On / Off';
175
+
176
+ -- DROP TABLE if exists admin.interface_list;
177
+ CREATE TABLE if not exists admin.interface_list();
178
+ alter table admin.interface_list DROP CONSTRAINT if exists admin_interface_id_pkey cascade;
179
+
180
+ alter table admin.interface_list add column if not exists interface_id text NOT NULL default next_id();
181
+ alter table admin.interface_list add column if not exists alias text NOT NULL;
182
+ alter table admin.interface_list add column if not exists title text;
183
+ alter table admin.interface_list add column if not exists public boolean;
184
+ alter table admin.interface_list add column if not exists menu_id text;
185
+ alter table admin.interface_list add column if not exists uid text;
186
+ alter table admin.interface_list add column if not exists editor_id text;
187
+ alter table admin.interface_list add column if not exists editor_date timestamp without time zone;
188
+ alter table admin.interface_list add column if not exists cdate timestamp without time zone DEFAULT now();
189
+ alter table admin.interface_list add column if not exists enabled boolean NOT NULL DEFAULT true;
190
+ alter table admin.interface_list add CONSTRAINT admin_interface_id_pkey PRIMARY KEY (interface_id);
191
+ alter table admin.interface_list add constraint admin_interface_menu_id_fkey FOREIGN KEY (menu_id) REFERENCES admin.menu(menu_id);
192
+
193
+ COMMENT ON TABLE admin.interface_list IS 'Список інтерфейсів';
194
+ COMMENT ON COLUMN admin.interface_list.interface_id IS 'Ідентифікатор інтерфейса';
195
+ COMMENT ON COLUMN admin.interface_list.alias IS 'Назва файлу інтерфейса';
196
+ COMMENT ON COLUMN admin.interface_list.title IS 'Назва інтерфейсу українською';
197
+ COMMENT ON COLUMN admin.interface_list.public IS 'Ознака чи для всіх показується';
198
+ COMMENT ON COLUMN admin.interface_list.enabled IS 'On / Off';
199
+ COMMENT ON COLUMN admin.interface_list.menu_id IS 'Пункт меню (для collapse)';
200
+
201
+ CREATE EXTENSION if not exists pgcrypto SCHEMA public VERSION "1.3";
202
+ CREATE OR REPLACE FUNCTION admin.crypt(text, text) RETURNS text AS '$libdir/pgcrypto', 'pg_crypt' LANGUAGE c IMMUTABLE STRICT COST 1;
203
+
204
+ -- DROP FUNCTION admin.insert_update_user_before();
205
+ CREATE OR REPLACE FUNCTION admin.insert_update_user_before()
206
+ RETURNS trigger AS
207
+
208
+ $BODY$
209
+ DECLARE
210
+
211
+ iterations int;
212
+ hash character varying;
213
+
214
+ BEGIN
215
+
216
+ if(TG_OP='INSERT' or (TG_OP='UPDATE' and new.password<>old.password)) then
217
+ if(char_length(new.password) <> 0 and char_length(new.password) < 8) then
218
+ --raise exception 'password must be longer than 8 characters';
219
+ end if;
220
+ new.salt=md5(now()::text);
221
+ --raise exception '%','change pass';
222
+ if(new.salt ='') then
223
+ new.salt=gen_salt('md5');
224
+ end if;
225
+ iterations = 10;
226
+ hash='';
227
+
228
+ loop
229
+ if iterations=0 then
230
+ exit;
231
+ end if;
232
+ hash = md5(new.password||hash||new.salt);
233
+ iterations=iterations-1;
234
+ end loop;
235
+ new.password=admin.crypt(hash,new.salt);
236
+
237
+ end if;
238
+ RETURN new;
239
+ END
240
+ $BODY$
241
+
242
+ LANGUAGE plpgsql VOLATILE COST 100;
243
+
244
+ DROP TRIGGER if exists insert_update_user_before on admin.users;
245
+ CREATE TRIGGER insert_update_user_before BEFORE INSERT OR UPDATE ON admin.users FOR EACH ROW
246
+ EXECUTE PROCEDURE admin.insert_update_user_before();
@@ -17,9 +17,12 @@ export default async function data(req) {
17
17
  const {
18
18
  table, columns, sql, cardSql, filters, form, meta,
19
19
  } = loadTable;
20
- const { pk } = await getMeta(table);
20
+ const { pk, columns: dbColumns = [] } = await getMeta(table);
21
+
22
+ if (!pk) return { message: `table not found: ${table}`, status: 404 };
21
23
 
22
24
  const cols = columns.map((el) => el.name || el).join(',');
25
+ const columnList = dbColumns.map((el) => el.name || el).join(',');
23
26
  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
27
  const cardSqlFiltered = params.id ? cardSql?.filter?.((el) => !el?.disabled && el?.name && el?.sql?.replace) : [];
25
28
  const cardSqlTable = cardSqlFiltered.length ? cardSqlFiltered.map((el, i) => ` left join lateral (select json_agg(row_to_json(q)) as ${el.name} from (${el.sql})q) ct${i} on 1=1 `).join('') || '' : '';
@@ -38,14 +41,14 @@ export default async function data(req) {
38
41
  // id, query, filter
39
42
  const [orderColumn, orderDir] = (query.order || loadTable.order || '').split(/[- ]/);
40
43
 
41
- const order = cols.includes(orderColumn) && orderColumn?.length ? `order by ${orderColumn} ${query.desc || orderDir === 'desc' ? 'desc' : ''}` : '';
44
+ const order = columnList.includes(orderColumn) && orderColumn?.length ? `order by ${orderColumn} ${query.desc || orderDir === 'desc' ? 'desc' : ''}` : '';
42
45
  const state = loadTable.filterState && query.state ? loadTable.filterState[query.state]?.sql : null;
43
46
  const custom = loadTable.filterCustom && query.custom ? loadTable.filterCustom[query.custom]?.sql : null;
44
47
  const search = loadTable.meta?.search && query.search ? `(${loadTable.meta?.search.split(',').map(el => `${el} ilike '%${query.search}%'`).join(' or ')})` : null;
45
48
 
46
49
  const where = [(params.id ? ` "${pk}" = $1` : null), keyQuery, loadTable.query, fData.q, state, custom, search].filter((el) => el);
47
50
  const cardColumns = cardSqlFiltered.length ? `,${cardSqlFiltered.map((el) => el.name)}` : '';
48
- const q = `select ${pk ? `"${pk}" as id,` : ''} ${query.id || query.key ? '*' : cols || '*'} ${cardColumns} from ${table} t ${sqlTable} ${cardSqlTable} where ${where.join(' and ') || 'true'} ${order} ${offset} limit ${limit}`;
51
+ const q = `select ${pk ? `"${pk}" as id,` : ''} ${columnList.includes('geom') ? `st_asgeojson(geom)::json as geom,` : ''} ${query.id || query.key ? '*' : cols || '*'} ${cardColumns} from ${table} t ${sqlTable} ${cardSqlTable} where ${where.join(' and ') || 'true'} ${order} ${offset} limit ${limit}`;
49
52
 
50
53
  if (query.sql === '1') { return q; }
51
54
 
@@ -1,28 +1,28 @@
1
- import { readFile } from 'fs/promises';
2
- import fs from 'fs';
3
- import path from 'path';
4
- import config from '../../../config.js';
5
-
6
- const loadTemplate = {};
7
-
8
- export default async function getTemplateDir(type, name) {
9
- if (!type) return null;
10
- if (!name) return null;
11
-
12
- const cwd = process.cwd();
13
- const typeDir = path.join(cwd, (config.templateDir || 'server/templates'), type);
14
-
15
- if (!loadTemplate[type]) {
16
- const typeList = fs.existsSync(typeDir) ? fs.readdirSync(typeDir) : [];
17
- loadTemplate[type] = typeList;
18
- }
19
-
20
- const fullname = loadTemplate[type].find((el) => path.parse(el).name === name);
21
- const ext = fullname ? path.extname(fullname)?.slice(1) : null;
22
- if (!ext) return null;
23
-
24
- const sql = loadTemplate[type].includes(`${name}.sql`) ? await readFile(path.join(typeDir, `${name}.sql`), 'utf-8') : null;
25
- const data = loadTemplate[type].includes(`${name}.json`) ? JSON.parse(await readFile(path.join(typeDir, `${name}.json`), 'utf-8')) : await readFile(path.join(typeDir, `${name}.${ext}`), 'utf-8');
26
- if (sql) return { ...data || {}, sql };
27
- return data;
28
- }
1
+ import { readFile } from 'fs/promises';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import config from '../../../config.js';
5
+
6
+ const loadTemplate = {};
7
+
8
+ export default async function getTemplateDir(type, name) {
9
+ if (!type) return null;
10
+ if (!name) return null;
11
+
12
+ const cwd = process.cwd();
13
+ const typeDir = path.join(cwd, (config.templateDir || 'server/templates'), type);
14
+
15
+ if (!loadTemplate[type]) {
16
+ const typeList = fs.existsSync(typeDir) ? fs.readdirSync(typeDir) : [];
17
+ loadTemplate[type] = typeList;
18
+ }
19
+
20
+ const fullname = loadTemplate[type].find((el) => path.parse(el).name === name);
21
+ const ext = fullname ? path.extname(fullname)?.slice(1) : null;
22
+ if (!ext) return null;
23
+
24
+ const sql = loadTemplate[type].includes(`${name}.sql`) ? await readFile(path.join(typeDir, `${name}.sql`), 'utf-8') : null;
25
+ const data = loadTemplate[type].includes(`${name}.json`) ? JSON.parse(await readFile(path.join(typeDir, `${name}.json`), 'utf-8')) : await readFile(path.join(typeDir, `${name}.${ext}`), 'utf-8');
26
+ if (sql) return { ...data || {}, sql };
27
+ return data;
28
+ }