@opengis/fastify-table 1.0.96 → 1.1.0
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 +4 -0
- package/README.md +26 -26
- package/config.js +10 -10
- package/cron/controllers/cronApi.js +22 -22
- package/cron/controllers/utils/cronList.js +1 -1
- package/cron/funcs/addCron.js +131 -131
- package/cron/index.js +10 -10
- package/crud/controllers/utils/checkXSS.js +45 -45
- package/crud/controllers/utils/xssInjection.js +72 -72
- package/crud/funcs/dataUpdate.js +30 -30
- package/crud/funcs/getToken.js +27 -27
- package/crud/funcs/isFileExists.js +13 -13
- package/crud/funcs/setToken.js +53 -53
- package/crud/funcs/utils/logChanges.js +7 -4
- package/migration/exec.migrations.js +79 -76
- package/notification/controllers/testEmail.js +49 -49
- package/notification/funcs/utils/sendEmail.js +39 -39
- package/notification/index.js +38 -38
- package/package.json +1 -1
- package/pg/funcs/getPG.js +30 -30
- package/redis/funcs/getRedis.js +23 -23
- package/server/migrations/crm.sql +150 -150
- package/server/migrations/log.sql +80 -80
- package/server/migrations/properties.sql +31 -0
- package/server/migrations/roles.sql +164 -0
- package/server/migrations/users.sql +89 -0
- package/server/templates/select/test.storage.data.json +3 -3
- package/server/templates/select/test.suggest.ato_new.json +2 -2
- package/server/templates/select/test.suggest.ato_new.sql +25 -25
- package/server/templates/select/test.suggest.data.json +4 -4
- package/server/templates/select/test.suggest.parent.sql +2 -2
- package/server.js +14 -14
- package/table/controllers/card.js +44 -44
- package/table/controllers/filter.js +37 -37
- package/table/controllers/form.js +28 -28
- package/table/controllers/search.js +80 -72
- package/table/controllers/utils/getSelect.js +20 -20
- package/table/controllers/utils/getTemplate.js +69 -28
- package/table/controllers/utils/getTemplatePath.js +40 -0
- package/table/controllers/utils/getTemplate_old.js +28 -0
- package/table/controllers/utils/getTemplates.js +18 -18
- package/table/controllers/utils/loadTemplate.js +1 -0
- package/table/controllers/utils/loadTemplatePath.js +1 -0
- package/table/funcs/getFilterSQL/util/getCustomQuery.js +1 -1
- package/table/index.js +84 -80
- package/test/api/crud.xss.test.js +72 -72
- package/test/api/notification.test.js +37 -37
- package/test/api/suggest.test.js +65 -65
- package/test/config.example +18 -18
- 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
- package/util/controllers/logger.file.js +90 -90
- package/util/controllers/next.id.js +4 -4
- package/util/controllers/properties.get.js +19 -19
- package/util/controllers/utils/checkUserAccess.js +19 -19
- package/util/controllers/utils/getRootDir.js +20 -20
- package/util/index.js +23 -23
- package/utils.js +8 -0
|
@@ -1,72 +1,80 @@
|
|
|
1
|
-
import getTemplate from './utils/getTemplate.js';
|
|
2
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
-
import metaFormat from '../funcs/metaFormat/index.js';
|
|
4
|
-
import getTemplates from './utils/getTemplates.js';
|
|
5
|
-
|
|
6
|
-
function sequence(tables, data, fn) {
|
|
7
|
-
return tables.reduce((promise, table) => promise.then(() => fn({
|
|
8
|
-
...data, tableName: table.replace('.json', ''),
|
|
9
|
-
})), Promise.resolve());
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async function getData({
|
|
13
|
-
pg, funcs, tableName, query = {}, maxLimit, res,
|
|
14
|
-
}) {
|
|
15
|
-
const loadTable = await getTemplate('table', tableName);
|
|
16
|
-
|
|
17
|
-
if (!loadTable) { return { message: 'not found', status: 404 }; }
|
|
18
|
-
|
|
19
|
-
const {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
await
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
1
|
+
import getTemplate from './utils/getTemplate.js';
|
|
2
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
+
import metaFormat from '../funcs/metaFormat/index.js';
|
|
4
|
+
import getTemplates from './utils/getTemplates.js';
|
|
5
|
+
|
|
6
|
+
function sequence(tables, data, fn) {
|
|
7
|
+
return tables.reduce((promise, table) => promise.then(() => fn({
|
|
8
|
+
...data, tableName: table.replace('.json', ''),
|
|
9
|
+
})), Promise.resolve());
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async function getData({
|
|
13
|
+
pg, funcs, tableName, query = {}, maxLimit, res,
|
|
14
|
+
}) {
|
|
15
|
+
const loadTable = await getTemplate('table', tableName);
|
|
16
|
+
|
|
17
|
+
if (!loadTable) { return { message: 'not found', status: 404 }; }
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
table, columns, meta,
|
|
21
|
+
} = loadTable;
|
|
22
|
+
|
|
23
|
+
const { pk } = await getMeta(table);
|
|
24
|
+
|
|
25
|
+
const cols = columns.map((el) => el.name || el).join(',');
|
|
26
|
+
const [orderColumn, orderDir] = (query.order || loadTable.order || '').split('-');
|
|
27
|
+
const order = cols.includes(orderColumn) && orderColumn?.length ? `order by ${orderColumn} ${query.desc || orderDir === 'desc' ? 'desc' : ''}` : '';
|
|
28
|
+
|
|
29
|
+
const limit = Math.max(maxLimit - res.rows.length, 0);
|
|
30
|
+
// Math.max(query.offset - res.rows.length,0)
|
|
31
|
+
const offset = query.page && query.page > 0 ? ` offset ${(query.page - 1) * limit}` : '';
|
|
32
|
+
|
|
33
|
+
const search1 = meta?.search && query.key ? `(${meta?.search.concat(meta?.title ? `,${meta?.title}` : '').split(',').map(el => `${el} ilike '%${query.key}%'`).join(' or ')})` : 'false';
|
|
34
|
+
|
|
35
|
+
const where = [!pk ? 'false' : 'true', loadTable.query, search1].filter((el) => el);
|
|
36
|
+
const q = `select ${[`"${pk}" as id`, meta?.title ? `${meta.title} as title` : ''].filter((el) => el).join(',')} from ${table} t where ${where.join(' and ') || 'true'} ${order} ${offset} limit ${limit}`;
|
|
37
|
+
if (query.sql) {
|
|
38
|
+
res.sql.push(q);
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const { rows } = await pg.query(q);
|
|
43
|
+
|
|
44
|
+
const total = await pg.queryCache(`select count(*) from ${table} t where ${where.join(' and ') || 'true'}`).then((el) => el?.rows[0]?.count) || 0;
|
|
45
|
+
|
|
46
|
+
await metaFormat({ rows, table: tableName });
|
|
47
|
+
res.total += +total;
|
|
48
|
+
rows.forEach((row) => {
|
|
49
|
+
const href = meta?.href ? funcs.handlebars.compile(meta.href)({ ...row, [pk]: row.id }) : undefined;
|
|
50
|
+
res.rows.push({
|
|
51
|
+
...row, register: tableName, register_title: loadTable.ua, href,
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default async function search({
|
|
58
|
+
pg, funcs, query = {},
|
|
59
|
+
}) {
|
|
60
|
+
const time = Date.now();
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const tables = query.table ? [query.table] : await getTemplates('table');
|
|
64
|
+
const res = { rows: [], sql: [], total: 0 };
|
|
65
|
+
|
|
66
|
+
const maxLimit = Math.min(100, query.limit || '16');
|
|
67
|
+
await sequence(tables, {
|
|
68
|
+
pg, funcs, query, maxLimit, res,
|
|
69
|
+
}, getData);
|
|
70
|
+
|
|
71
|
+
if (query.sql) return res.sql.join(';\n');
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
time: Date.now() - time, total: res.total, count: res.rows.length, rows: res.rows,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
return { error: err.toString(), status: 500 };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import getTemplate from './getTemplate.js';
|
|
2
|
-
|
|
3
|
-
const loadCls = {};
|
|
4
|
-
|
|
5
|
-
export default async function getSelect(name) {
|
|
6
|
-
if (loadCls[name]) return loadCls[name];
|
|
7
|
-
|
|
8
|
-
const clsData = await getTemplate('cls', name);
|
|
9
|
-
|
|
10
|
-
if (clsData) {
|
|
11
|
-
loadCls[name] = { arr: clsData };
|
|
12
|
-
return loadCls[name];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const selectData = await getTemplate('select', name);
|
|
16
|
-
if (!selectData) { return null; }
|
|
17
|
-
|
|
18
|
-
loadCls[name] = selectData;
|
|
19
|
-
return loadCls[name];
|
|
20
|
-
}
|
|
1
|
+
import getTemplate from './getTemplate.js';
|
|
2
|
+
|
|
3
|
+
const loadCls = {};
|
|
4
|
+
|
|
5
|
+
export default async function getSelect(name) {
|
|
6
|
+
if (loadCls[name]) return loadCls[name];
|
|
7
|
+
|
|
8
|
+
const clsData = await getTemplate('cls', name);
|
|
9
|
+
console.log(clsData);
|
|
10
|
+
if (clsData) {
|
|
11
|
+
loadCls[name] = { arr: clsData };
|
|
12
|
+
return loadCls[name];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const selectData = await getTemplate('select', name);
|
|
16
|
+
if (!selectData) { return null; }
|
|
17
|
+
|
|
18
|
+
loadCls[name] = selectData;
|
|
19
|
+
return loadCls[name];
|
|
20
|
+
}
|
|
@@ -1,28 +1,69 @@
|
|
|
1
|
-
import { readFile } from 'fs/promises';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
import { readdir, readFile } from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import yaml from 'js-yaml';
|
|
4
|
+
|
|
5
|
+
import getTemplatePath from './getTemplatePath.js';
|
|
6
|
+
import loadTemplate from './loadTemplate.js';
|
|
7
|
+
|
|
8
|
+
async function readFileData(file) {
|
|
9
|
+
const data = await readFile(file, 'utf-8');
|
|
10
|
+
const ext = file.substring(file.lastIndexOf('.') + 1);
|
|
11
|
+
|
|
12
|
+
if (ext === 'yml') {
|
|
13
|
+
return yaml.load(data);
|
|
14
|
+
}
|
|
15
|
+
if (ext === 'json') {
|
|
16
|
+
return JSON.parse(data);
|
|
17
|
+
}
|
|
18
|
+
return data;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
|
22
|
+
|
|
23
|
+
async function getTemplateData(template) {
|
|
24
|
+
// dir template: dashboard, card
|
|
25
|
+
if (template[0][3]) {
|
|
26
|
+
const files = await readdir(template[0][1]);
|
|
27
|
+
const data = await Promise.all(files.map(async el => readFileData(path.join(template[0][1], el))));
|
|
28
|
+
return files.map((el, i) => [el, data[i]]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// one file template: table, form
|
|
32
|
+
if (template.length === 1) {
|
|
33
|
+
const data = await readFileData(template[0][1]);
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// multi file template: select, etc
|
|
38
|
+
if (template.length > 1) {
|
|
39
|
+
const data = await Promise.all(template.map(async el => readFileData(el[1])));
|
|
40
|
+
const result = {};
|
|
41
|
+
template.forEach((el, i) => {
|
|
42
|
+
Object.assign(result, typeof data[i] === 'object' ? data[i] : { [el[2]]: data[i] });
|
|
43
|
+
});
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
export default async function getTemplate(type, name) {
|
|
49
|
+
if (!type) return null;
|
|
50
|
+
if (!name) return null;
|
|
51
|
+
|
|
52
|
+
const key = `${type}:${name}`;
|
|
53
|
+
if (name === 'cache' && !isProduction) return loadTemplate; // all cache debug
|
|
54
|
+
if (loadTemplate[key] && isProduction) return loadTemplate[key]; // from cache
|
|
55
|
+
|
|
56
|
+
// type one or multi
|
|
57
|
+
const templateList = Array.isArray(type)
|
|
58
|
+
? type.map(el => getTemplatePath(el)).filter(list => list?.filter(el => el[0] === name).length)[0] || []
|
|
59
|
+
: getTemplatePath(type);
|
|
60
|
+
|
|
61
|
+
// find template
|
|
62
|
+
const template = templateList?.filter(el => el[0] === name);
|
|
63
|
+
if (name === 'list' && !isProduction) return templateList; // all template debug
|
|
64
|
+
|
|
65
|
+
if (!template.length) return null; // not found
|
|
66
|
+
|
|
67
|
+
loadTemplate[key] = await getTemplateData(template);
|
|
68
|
+
return loadTemplate[key];
|
|
69
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// import { readFile } from 'fs/promises';
|
|
2
|
+
import fs, { existsSync, readdirSync } from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import config from '../../../config.js';
|
|
5
|
+
|
|
6
|
+
import loadTemplatePath from './loadTemplatePath.js';
|
|
7
|
+
|
|
8
|
+
const cwd = process.cwd();
|
|
9
|
+
|
|
10
|
+
export default function getTemplatePath(type) {
|
|
11
|
+
if (!type) return null;
|
|
12
|
+
|
|
13
|
+
// form cache
|
|
14
|
+
|
|
15
|
+
if (loadTemplatePath[type]) return loadTemplatePath[type];
|
|
16
|
+
loadTemplatePath[type] = [];
|
|
17
|
+
|
|
18
|
+
const moduleList = [];
|
|
19
|
+
const moduleDir = path.join(cwd, 'module');
|
|
20
|
+
if (fs.existsSync(moduleDir) && !moduleList.length) {
|
|
21
|
+
readdirSync(moduleDir).forEach(el => moduleList.push(path.join(moduleDir, el, type)));
|
|
22
|
+
}
|
|
23
|
+
moduleList.push(path.join(cwd, config.templateDir || 'server/templates', type));
|
|
24
|
+
|
|
25
|
+
moduleList.forEach(el => {
|
|
26
|
+
const templateDir = el;
|
|
27
|
+
if (!existsSync(templateDir)) return;
|
|
28
|
+
|
|
29
|
+
const list = readdirSync(templateDir, { withFileTypes: true });
|
|
30
|
+
|
|
31
|
+
list.forEach(file => {
|
|
32
|
+
const isDir = file.isDirectory();
|
|
33
|
+
const name = isDir ? file.name : file.name.substring(0, file.name.lastIndexOf('.'));
|
|
34
|
+
const ext = isDir ? null : file.name.substring(file.name.lastIndexOf('.') + 1);
|
|
35
|
+
loadTemplatePath[type].push([name, path.join(templateDir, file.name), ext, isDir]);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return loadTemplatePath[type];
|
|
40
|
+
}
|
|
@@ -0,0 +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 { sql };
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import config from '../../../config.js';
|
|
4
|
-
|
|
5
|
-
const loadTemplate = {};
|
|
6
|
-
|
|
7
|
-
export default async function getTemplateDir(type) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import config from '../../../config.js';
|
|
4
|
+
|
|
5
|
+
const loadTemplate = {};
|
|
6
|
+
|
|
7
|
+
export default async function getTemplateDir(type) {
|
|
8
|
+
if (!type) return null;
|
|
9
|
+
|
|
10
|
+
const cwd = process.cwd();
|
|
11
|
+
const typeDir = path.join(cwd, (config.templateDir || 'server/templates'), type);
|
|
12
|
+
|
|
13
|
+
if (!loadTemplate[type]) {
|
|
14
|
+
const typeList = fs.existsSync(typeDir) ? fs.readdirSync(typeDir) : [];
|
|
15
|
+
loadTemplate[type] = typeList;
|
|
16
|
+
}
|
|
17
|
+
return loadTemplate[type];
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {};
|
|
@@ -4,7 +4,7 @@ async function getCustomQuery({
|
|
|
4
4
|
if (!customFilter) return null;
|
|
5
5
|
const customFilterList = customFilter?.split(',')?.map((el) => el?.split('_').pop());
|
|
6
6
|
const { property_json: customFilterSQL } = await pg.one(`select json_agg(json_build_object('id',property_id,'name',property_key,'query',property_text)
|
|
7
|
-
) as property_json from
|
|
7
|
+
) as property_json from admin.properties where property_key is not null and property_entity='customQuery' and object_id=$1`, [table]);
|
|
8
8
|
const data = customFilterSQL?.length ? customFilterSQL.filter((el) => customFilterList.includes(el.id)) || [] : [];
|
|
9
9
|
const customQuery = data?.map((el) => el.query).join(' and ');
|
|
10
10
|
return `${customQuery}`;
|
package/table/index.js
CHANGED
|
@@ -1,80 +1,84 @@
|
|
|
1
|
-
import suggest from './controllers/suggest.js';
|
|
2
|
-
import data from './controllers/data.js';
|
|
3
|
-
import table from './controllers/table.js';
|
|
4
|
-
import card from './controllers/card.js';
|
|
5
|
-
import search from './controllers/search.js';
|
|
6
|
-
import filter from './controllers/filter.js';
|
|
7
|
-
import form from './controllers/form.js';
|
|
8
|
-
import metaFormat from './funcs/metaFormat/index.js';
|
|
9
|
-
import getFilterSQL from './funcs/getFilterSQL/index.js';
|
|
10
|
-
import getTemplate from './controllers/utils/getTemplate.js';
|
|
11
|
-
import getSelect from './controllers/utils/getSelect.js';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
fastify.decorate('
|
|
69
|
-
fastify.decorate('
|
|
70
|
-
|
|
71
|
-
fastify.
|
|
72
|
-
|
|
73
|
-
fastify.get(`${prefix}/
|
|
74
|
-
fastify.get(`${prefix}/
|
|
75
|
-
fastify.get(`${prefix}/
|
|
76
|
-
fastify.get(`${prefix}/
|
|
77
|
-
fastify.get(`${prefix}/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
1
|
+
import suggest from './controllers/suggest.js';
|
|
2
|
+
import data from './controllers/data.js';
|
|
3
|
+
import table from './controllers/table.js';
|
|
4
|
+
import card from './controllers/card.js';
|
|
5
|
+
import search from './controllers/search.js';
|
|
6
|
+
import filter from './controllers/filter.js';
|
|
7
|
+
import form from './controllers/form.js';
|
|
8
|
+
import metaFormat from './funcs/metaFormat/index.js';
|
|
9
|
+
import getFilterSQL from './funcs/getFilterSQL/index.js';
|
|
10
|
+
import getTemplate from './controllers/utils/getTemplate.js';
|
|
11
|
+
import getSelect from './controllers/utils/getSelect.js';
|
|
12
|
+
|
|
13
|
+
import loadTemplatePath from './controllers/utils/loadTemplatePath.js';
|
|
14
|
+
|
|
15
|
+
const tableSchema = {
|
|
16
|
+
querystring1: {
|
|
17
|
+
page: { type: 'string', pattern: '^(\\d+)$' },
|
|
18
|
+
order: { type: 'string', pattern: '^(\\d+)$' },
|
|
19
|
+
filter: { type: 'string', pattern: '^([\\w\\d_-]+)=([\\w\\d_-]+)$' },
|
|
20
|
+
},
|
|
21
|
+
params: {
|
|
22
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
23
|
+
table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const searchSchema = {
|
|
28
|
+
querystring: {
|
|
29
|
+
page: { type: 'string', pattern: '^(\\d+)$' },
|
|
30
|
+
limit: { type: 'string', pattern: '^(\\d+)$' },
|
|
31
|
+
order: { type: 'string', pattern: '^([\\w_.]+)$' },
|
|
32
|
+
desc: { type: 'string', pattern: '^(desc)|(asc)$' },
|
|
33
|
+
key: { type: 'string', pattern: '^([\\w\\d_]+)$' },
|
|
34
|
+
table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
35
|
+
sql: { type: 'string', pattern: '^(\\d)$' },
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const suggestSchema = {
|
|
40
|
+
querystring: {
|
|
41
|
+
lang: { type: 'string', pattern: '^([\\w.]+)$' },
|
|
42
|
+
// parent: { type: 'string', pattern: '^([\\w,./]+)$' },
|
|
43
|
+
sel: { type: 'string', pattern: '^([\\w,./]+)$' },
|
|
44
|
+
name: { type: 'string', pattern: '^([\\w,./]+)$' },
|
|
45
|
+
// key: { type: 'string', pattern: '^([\\w\\d_]+)$' },
|
|
46
|
+
// val: { type: 'string', pattern: '^([\\w.,]+)$' },
|
|
47
|
+
sql: { type: 'string', pattern: '^(\\d)$' },
|
|
48
|
+
},
|
|
49
|
+
params: {
|
|
50
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const formSchema = {
|
|
55
|
+
params: {
|
|
56
|
+
form: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const filterSchema = {
|
|
61
|
+
params: {
|
|
62
|
+
table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
async function plugin(fastify, config = {}) {
|
|
67
|
+
const prefix = config.prefix || '/api';
|
|
68
|
+
fastify.decorate('metaFormat', metaFormat);
|
|
69
|
+
fastify.decorate('getFilterSQL', getFilterSQL);
|
|
70
|
+
fastify.decorate('getTemplate', getTemplate);
|
|
71
|
+
fastify.decorate('getSelect', getSelect);
|
|
72
|
+
|
|
73
|
+
fastify.get(`${prefix}/suggest/:data`, { schema: suggestSchema }, suggest);
|
|
74
|
+
fastify.get(`${prefix}/data/:table/:id?`, { schema: tableSchema }, data); // vs.crm.data.api с node
|
|
75
|
+
fastify.get(`${prefix}/table/:table/:id`, { schema: tableSchema }, table);
|
|
76
|
+
fastify.get(`${prefix}/card/:table/:id`, { schema: tableSchema }, card);
|
|
77
|
+
fastify.get(`${prefix}/search`, { schema: searchSchema }, search);
|
|
78
|
+
|
|
79
|
+
fastify.get(`${prefix}/templates`, () => loadTemplatePath);
|
|
80
|
+
fastify.get(`${prefix}/filter/:table`, { schema: filterSchema }, filter);
|
|
81
|
+
fastify.get(`${prefix}/form/:form`, { schema: formSchema }, form);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export default plugin;
|