@opengis/fastify-table 1.1.56 → 1.1.58
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 +27 -14
- package/package.json +9 -4
- package/{cron → server/plugins/cron}/funcs/addCron.js +12 -12
- package/server/plugins/cron/index.js +6 -0
- package/{crud → server/plugins/crud}/funcs/dataDelete.js +3 -1
- package/{crud → server/plugins/crud}/funcs/dataInsert.js +3 -0
- package/{crud → server/plugins/crud}/funcs/dataUpdate.js +3 -1
- package/{crud → server/plugins/crud}/funcs/getAccess.js +5 -3
- package/{crud → server/plugins/crud}/funcs/getOpt.js +2 -0
- package/{crud → server/plugins/crud}/funcs/getToken.js +4 -1
- package/{crud → server/plugins/crud}/funcs/setOpt.js +3 -0
- package/{crud → server/plugins/crud}/funcs/setToken.js +4 -1
- package/{crud → server/plugins/crud}/funcs/utils/getFolder.js +2 -1
- package/{crud → server/plugins/crud}/funcs/utils/logChanges.js +2 -2
- package/server/plugins/crud/index.js +23 -0
- package/{hook → server/plugins/hook}/funcs/addHook.js +1 -1
- package/{hook → server/plugins/hook}/funcs/applyHook.js +2 -2
- package/server/plugins/hook/index.js +8 -0
- package/{logger → server/plugins/logger}/createFileStream.js +1 -1
- package/{logger → server/plugins/logger}/getLogger.js +1 -1
- package/{migration → server/plugins/migration/funcs}/exec.migrations.js +1 -1
- package/server/plugins/migration/index.js +7 -0
- package/{pg → server/plugins/pg}/funcs/getPG.js +3 -3
- package/{pg → server/plugins/pg}/funcs/getPGAsync.js +3 -3
- package/{pg → server/plugins/pg}/funcs/init.js +2 -4
- package/{pg → server/plugins/pg}/index.js +5 -14
- package/{pg → server/plugins/pg}/pgClients.js +2 -1
- package/{policy → server/plugins/policy}/funcs/checkPolicy.js +1 -1
- package/{crud/controllers/utils → server/plugins/policy/funcs}/checkXSS.js +1 -4
- package/{policy → server/plugins/policy}/index.js +0 -2
- package/{policy/funcs → server/plugins/policy}/sqlInjection.js +1 -1
- package/{redis → server/plugins/redis}/funcs/getRedis.js +2 -1
- package/{redis → server/plugins/redis}/funcs/redisClients.js +1 -0
- package/{redis → server/plugins/redis}/index.js +2 -6
- package/{table → server/plugins/table}/funcs/getFilterSQL/index.js +3 -1
- package/{table/controllers/utils → server/plugins/table/funcs}/getSelectMeta.js +1 -10
- package/{table/controllers/utils → server/plugins/table/funcs}/getTemplate.js +2 -1
- package/{table/controllers/utils → server/plugins/table/funcs}/getTemplatePath.js +3 -3
- package/{table/controllers/utils → server/plugins/table/funcs}/getTemplates.js +2 -1
- package/{table/controllers/utils → server/plugins/table/funcs}/gisIRColumn.js +4 -7
- package/{table → server/plugins/table}/funcs/metaFormat/getSelectVal.js +4 -2
- package/{table → server/plugins/table}/funcs/metaFormat/index.js +3 -1
- package/server/plugins/table/index.js +13 -0
- package/{util → server/plugins/util/funcs}/eventStream.js +1 -0
- package/server/plugins/util/index.js +7 -0
- package/{cron → server/routes/cron}/controllers/cronApi.js +1 -1
- package/{cron → server/routes/cron}/index.js +5 -3
- package/{crud → server/routes/crud}/controllers/deleteCrud.js +2 -2
- package/{crud → server/routes/crud}/controllers/insert.js +5 -3
- package/{crud → server/routes/crud}/controllers/update.js +3 -3
- package/server/routes/crud/index.js +19 -0
- package/{util → server/routes/logger}/controllers/logger.file.js +5 -5
- package/{util → server/routes/logger}/controllers/utils/checkUserAccess.js +1 -1
- package/{util → server/routes/logger}/controllers/utils/getRootDir.js +4 -3
- package/server/routes/logger/index.js +15 -0
- package/{util → server/routes/properties}/controllers/properties.add.js +19 -20
- package/server/routes/properties/controllers/properties.get.js +17 -0
- package/{util → server/routes/properties}/index.js +5 -8
- package/{table → server/routes/table}/controllers/card.js +3 -5
- package/{table → server/routes/table}/controllers/data.js +4 -10
- package/{table → server/routes/table}/controllers/filter.js +3 -4
- package/{table → server/routes/table}/controllers/form.js +1 -1
- package/{table → server/routes/table}/controllers/search.js +15 -17
- package/{table → server/routes/table}/controllers/suggest.js +8 -7
- package/{table → server/routes/table}/controllers/table.js +5 -7
- package/{table → server/routes/table}/index.js +1 -10
- package/{table → server/routes/table}/schema.js +1 -1
- package/{util → server/routes/util}/controllers/next.id.js +1 -1
- package/server/routes/util/index.js +11 -0
- package/utils.js +58 -50
- package/.eslintrc.cjs +0 -44
- package/.gitlab-ci.yml +0 -18
- package/Changelog.md +0 -352
- package/cron/schema.js +0 -8
- package/crud/index.js +0 -31
- package/crud/schema.js +0 -11
- package/docs/.vitepress/abbr.mjs +0 -26
- package/docs/.vitepress/config.mjs +0 -127
- package/docs/.vitepress/navigation.mjs +0 -82
- package/docs/.vitepress/theme/Layout.vue +0 -17
- package/docs/.vitepress/theme/components/NavigationLinks.vue +0 -102
- package/docs/.vitepress/theme/components/Panzoom.vue +0 -169
- package/docs/.vitepress/theme/index.mjs +0 -15
- package/docs/.vitepress/theme/style.scss +0 -163
- package/docs/abbr.json +0 -4
- package/docs/api/cron/cronApi.md +0 -56
- package/docs/api/crud/deleteCrud.md +0 -58
- package/docs/api/crud/insert.md +0 -82
- package/docs/api/crud/update.md +0 -85
- package/docs/api/index.md +0 -47
- package/docs/api/notification/testEmail.md +0 -91
- package/docs/api/table/card.md +0 -73
- package/docs/api/table/data.md +0 -134
- package/docs/api/table/export.md +0 -60
- package/docs/api/table/filter.md +0 -104
- package/docs/api/table/form.md +0 -126
- package/docs/api/table/search.md +0 -123
- package/docs/api/table/suggest.md +0 -156
- package/docs/api/table/table.md +0 -107
- package/docs/api/user/user.cls.id.md +0 -77
- package/docs/api/user/user.cls.md +0 -49
- package/docs/api/user/user.cls.post.md +0 -62
- package/docs/api/user/user.info.md +0 -37
- package/docs/api/utils/logger.file.md +0 -61
- package/docs/api/utils/next.id.md +0 -34
- package/docs/api/utils/properties.add.md +0 -127
- package/docs/api/utils/properties.get.md +0 -73
- package/docs/api/utils/status.monitor.md +0 -36
- package/docs/api/widget/widget.del.md +0 -76
- package/docs/api/widget/widget.get.md +0 -233
- package/docs/api/widget/widget.set.md +0 -88
- package/docs/db/admin.md +0 -947
- package/docs/db/crm.md +0 -564
- package/docs/db/index.md +0 -9
- package/docs/db/log.md +0 -204
- package/docs/hook/card/afterCard.md +0 -20
- package/docs/hook/card/preCard.md +0 -25
- package/docs/hook/data/afterData.md +0 -26
- package/docs/hook/data/preData.md +0 -26
- package/docs/hook/deleteCrud/afterDelete.md +0 -21
- package/docs/hook/deleteCrud/preDelete.md +0 -26
- package/docs/hook/form/afterForm.md +0 -19
- package/docs/hook/form/preForm.md +0 -26
- package/docs/hook/getTemplate/afterTemplate.md +0 -24
- package/docs/hook/getTemplate/preTemplate.md +0 -29
- package/docs/hook/index.md +0 -45
- package/docs/hook/insert/afterInsert.md +0 -41
- package/docs/hook/insert/preInsert.md +0 -25
- package/docs/hook/table/afterTable.md +0 -20
- package/docs/hook/table/preTable.md +0 -25
- package/docs/hook/update/afterUpdate.md +0 -41
- package/docs/hook/update/preUpdate.md +0 -25
- package/docs/index.md +0 -42
- package/docs/public/fastify-dark.svg +0 -4
- package/docs/public/fastify.svg +0 -1
- package/docs/public/logo-short-dark.svg +0 -12
- package/docs/public/logo-short.svg +0 -11
- package/docs/public/logo.svg +0 -19
- package/docs/readme/index.md +0 -121
- package/docs/templates/card.md +0 -83
- package/docs/templates/cls.md +0 -29
- package/docs/templates/filters.md +0 -91
- package/docs/templates/forms.md +0 -139
- package/docs/templates/image.png +0 -0
- package/docs/templates/index.md +0 -28
- package/docs/templates/select.md +0 -90
- package/docs/templates/table.md +0 -162
- package/docs/utils/cron/addCron.md +0 -29
- package/docs/utils/crud/dataInsert.md +0 -52
- package/docs/utils/crud/dataUpdate.md +0 -53
- package/docs/utils/crud/getOpt.md +0 -34
- package/docs/utils/crud/isFileExists.md +0 -38
- package/docs/utils/crud/setOpt.md +0 -38
- package/docs/utils/hook/addHook.md +0 -74
- package/docs/utils/hook/applyHook.md +0 -64
- package/docs/utils/index.md +0 -48
- package/docs/utils/notification/addNotification.md +0 -28
- package/docs/utils/notification/notification.md +0 -41
- package/docs/utils/pg/autoIndex.md +0 -22
- package/docs/utils/pg/getMeta.md +0 -59
- package/docs/utils/pg/getPG.md +0 -34
- package/docs/utils/pg/init.md +0 -30
- package/docs/utils/pg/pg.md +0 -70
- package/docs/utils/redis/getRedis.md +0 -36
- package/docs/utils/redis/rclient.md +0 -74
- package/docs/utils/table/getForm.md +0 -69
- package/docs/utils/table/getMeta.md +0 -56
- package/docs/utils/table/getSelect.md +0 -39
- package/docs/utils/table/getSelectMeta.md +0 -47
- package/docs/utils/table/getTable.md +0 -78
- package/helper.js +0 -30
- package/module/core/select/core.user_mentioned.sql +0 -2
- package/module/test/cls/itree.composition.json +0 -26
- package/module/test/table/test.rest_zone.table.json +0 -266
- package/notification/controllers/readNotifications.js +0 -27
- package/notification/controllers/testEmail.js +0 -46
- package/notification/controllers/userNotifications.js +0 -61
- package/notification/controllers/utils/pin-m-ty-media-record-outline+303070.png +0 -0
- package/notification/funcs/addNotification.js +0 -21
- package/notification/funcs/sendNotification.js +0 -111
- package/notification/funcs/utils/sendEmail.js +0 -39
- package/notification/index.js +0 -18
- package/notification/schema.js +0 -10
- package/server.js +0 -26
- package/table/controllers/utils/getTemplate_old.js +0 -28
- package/test/api/applyHook.test.js +0 -95
- package/test/api/crud.test.js +0 -89
- package/test/api/crud.xss.test.js +0 -80
- package/test/api/notification.test.js +0 -48
- package/test/api/suggest.test.js +0 -66
- package/test/api/table.test.js +0 -134
- package/test/api/user.test.js +0 -85
- package/test/api/widget.test.js +0 -117
- package/test/config.example +0 -18
- package/test/funcs/pg.test.js +0 -34
- package/test/funcs/redis.test.js +0 -19
- package/test/helper/formatDate.test.js +0 -62
- package/test/templates/cls/itree.quality_condition.json +0 -20
- package/test/templates/cls/itree.recommend copy.json +0 -26
- package/test/templates/cls/itree.recommend.json +0 -26
- package/test/templates/cls/itree.type_plant.json +0 -65
- package/test/templates/cls/test.json +0 -10
- package/test/templates/form/cp_building.form.json +0 -33
- package/test/templates/select/account_id.json +0 -4
- package/test/templates/select/account_id.sql +0 -1
- package/test/templates/select/atu.nsdi.ato_level.json +0 -4
- package/test/templates/select/atu.nsdi.ato_level.sql +0 -11
- package/test/templates/select/contact_id.sql +0 -1
- package/test/templates/select/storage.data.json +0 -3
- package/test/templates/select/storage.data.sql +0 -1
- package/test/templates/select/test.storage.data.json +0 -4
- package/test/templates/select/test.storage.data.sql +0 -1
- package/test/templates/select/test.suggest.ato_new.json +0 -4
- package/test/templates/select/test.suggest.ato_new.sql +0 -26
- package/test/templates/select/test.suggest.data.json +0 -5
- package/test/templates/select/test.suggest.data.sql +0 -1
- package/test/templates/select/test.suggest.parent.sql +0 -2
- package/test/templates/table/gis.dataset.table.json +0 -21
- package/test/templates/table/green_space.table.json +0 -383
- package/test/templates/table/service.json +0 -18
- package/user/controllers/user.cls.id.js +0 -14
- package/user/controllers/user.cls.js +0 -71
- package/user/controllers/user.cls.post.js +0 -52
- package/user/controllers/user.info.js +0 -17
- package/user/index.js +0 -17
- package/user/schema.js +0 -17
- package/util/controllers/properties.get.js +0 -17
- package/util/schema.js +0 -19
- package/widget/controllers/utils/historyFormat.js +0 -76
- package/widget/controllers/utils/obj2db.js +0 -13
- package/widget/controllers/widget.del.js +0 -41
- package/widget/controllers/widget.get.js +0 -96
- package/widget/controllers/widget.set.js +0 -74
- package/widget/index.js +0 -40
- /package/{cron/controllers/utils → server/plugins/cron}/cronList.js +0 -0
- /package/{crud → server/plugins/crud}/funcs/isFileExists.js +0 -0
- /package/{hook/funcs → server/plugins/hook}/hookList.js +0 -0
- /package/{logger → server/plugins/logger}/getHooks.js +0 -0
- /package/{logger → server/plugins/logger}/labels.js +0 -0
- /package/{logger → server/plugins/logger}/logger.test.api.js +0 -0
- /package/{logger → server/plugins/logger}/serializers.js +0 -0
- /package/{pg → server/plugins/pg}/funcs/autoIndex.js +0 -0
- /package/{pg → server/plugins/pg}/funcs/getMeta.js +0 -0
- /package/{pg → server/plugins/pg}/funcs/pgClients.js +0 -0
- /package/{crud/controllers/utils → server/plugins/policy}/xssInjection.js +0 -0
- /package/{redis → server/plugins/redis}/client.js +0 -0
- /package/{table/controllers/utils → server/plugins/table/funcs}/addTemplateDir.js +0 -0
- /package/{table → server/plugins/table}/funcs/getFilterSQL/util/formatValue.js +0 -0
- /package/{table → server/plugins/table}/funcs/getFilterSQL/util/getCustomQuery.js +0 -0
- /package/{table → server/plugins/table}/funcs/getFilterSQL/util/getFilterQuery.js +0 -0
- /package/{table → server/plugins/table}/funcs/getFilterSQL/util/getOptimizedQuery.js +0 -0
- /package/{table → server/plugins/table}/funcs/getFilterSQL/util/getTableSql.js +0 -0
- /package/{table/controllers/utils → server/plugins/table/funcs}/getSelect.js +0 -0
- /package/{table/controllers/utils → server/plugins/table/funcs}/loadTemplate.js +0 -0
- /package/{table/controllers/utils → server/plugins/table/funcs}/loadTemplatePath.js +0 -0
- /package/{table/controllers/utils → server/plugins/table/funcs}/userTemplateDir.js +0 -0
- /package/{util → server/routes/util}/controllers/status.monitor.js +0 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import getSelect from '
|
|
2
|
-
import pgClients from '../../../pg/pgClients.js';
|
|
1
|
+
import getSelect from '../getSelect.js';
|
|
2
|
+
import pgClients from '../../../pg/funcs/pgClients.js';
|
|
3
3
|
import redis from '../../../redis/client.js';
|
|
4
4
|
|
|
5
|
+
// import { pgClients, getSelect } from '../../../../../utils.js';
|
|
6
|
+
|
|
5
7
|
export default async function getSelectVal({ pg: pg1, name, values }) {
|
|
6
8
|
const pg = pg1 || pgClients.client;
|
|
7
9
|
const cls = await getSelect(name);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import getTemplate from '
|
|
1
|
+
import getTemplate from '../getTemplate.js';
|
|
2
2
|
import getSelectVal from './getSelectVal.js';
|
|
3
3
|
|
|
4
|
+
// import { getTemplate, getSelectVal } from '../../../../../utils.js';
|
|
5
|
+
|
|
4
6
|
export default async function metaFormat({ rows, table }) {
|
|
5
7
|
const loadTable = await getTemplate('table', table);
|
|
6
8
|
const selectCols = loadTable?.columns?.filter((e) => e.data);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import metaFormat from './funcs/metaFormat/index.js';
|
|
2
|
+
import getFilterSQL from './funcs/getFilterSQL/index.js';
|
|
3
|
+
import getTemplate from './funcs/getTemplate.js';
|
|
4
|
+
import getSelect from './funcs/getSelect.js';
|
|
5
|
+
|
|
6
|
+
async function plugin(fastify) {
|
|
7
|
+
// fastify.decorate('metaFormat', metaFormat);
|
|
8
|
+
// fastify.decorate('getFilterSQL', getFilterSQL);
|
|
9
|
+
// fastify.decorate('getTemplate', getTemplate);
|
|
10
|
+
// fastify.decorate('getSelect', getSelect);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default plugin;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import cronApi from './controllers/cronApi.js';
|
|
2
|
-
import addCron from './funcs/addCron.js';
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
const cronSchema = {
|
|
4
|
+
params: {
|
|
5
|
+
name: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
|
|
6
|
+
},
|
|
7
|
+
};
|
|
5
8
|
|
|
6
9
|
async function plugin(fastify, config = {}) {
|
|
7
10
|
const prefix = config.prefix || '/api';
|
|
8
|
-
fastify.decorate('addCron', addCron);
|
|
9
11
|
fastify.get(`${prefix}/cron/:name`, { schema: cronSchema }, cronApi);
|
|
10
12
|
}
|
|
11
13
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
dataDelete, getTemplate, getAccess, applyHook, getToken, config,
|
|
3
|
-
} from '
|
|
3
|
+
} from '../../../../utils.js';
|
|
4
4
|
|
|
5
5
|
export default async function deleteCrud(req) {
|
|
6
6
|
const { user, params = {} } = req || {};
|
|
@@ -18,7 +18,7 @@ export default async function deleteCrud(req) {
|
|
|
18
18
|
const { table: del, id } = hookData || tokenData || (config.auth?.disable ? req.params : {});
|
|
19
19
|
const { actions = [] } = await getAccess({ table: del, id, user }) || {};
|
|
20
20
|
|
|
21
|
-
if (!actions.includes('del')) {
|
|
21
|
+
if (!actions.includes('del') && !config?.local) {
|
|
22
22
|
return { message: 'access restricted', status: 403 };
|
|
23
23
|
}
|
|
24
24
|
const loadTemplate = await getTemplate('table', del);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
applyHook, getAccess, getTemplate, checkXSS, dataInsert, getToken, config,
|
|
3
|
-
} from '
|
|
3
|
+
} from '../../../../utils.js';
|
|
4
4
|
|
|
5
5
|
export default async function insert(req) {
|
|
6
6
|
const {
|
|
@@ -18,7 +18,9 @@ export default async function insert(req) {
|
|
|
18
18
|
|
|
19
19
|
const { actions = [] } = await getAccess({ table: add, user }) || {};
|
|
20
20
|
|
|
21
|
-
if (!actions.includes('add'))
|
|
21
|
+
if (!actions.includes('add') && !config?.local) {
|
|
22
|
+
return { message: 'access restricted', status: 403 };
|
|
23
|
+
}
|
|
22
24
|
|
|
23
25
|
if (!add) {
|
|
24
26
|
return { message: 'table is required', status: 400 };
|
|
@@ -40,7 +42,7 @@ export default async function insert(req) {
|
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
const uid = user?.uid;
|
|
43
|
-
if (
|
|
45
|
+
if (![add, table].filter((el) => el !== 'admin.users')?.length) {
|
|
44
46
|
Object.assign(body, { uid, editor_id: uid });
|
|
45
47
|
}
|
|
46
48
|
const res = await dataInsert({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
pgClients, applyHook, getAccess, getTemplate, checkXSS, dataInsert, dataUpdate, logger, getToken,
|
|
3
|
-
} from '
|
|
4
|
-
import config from '
|
|
3
|
+
} from '../../../../utils.js';
|
|
4
|
+
import config from '../../../../config.js';
|
|
5
5
|
|
|
6
6
|
export default async function update(req) {
|
|
7
7
|
const { user, params = {}, body = {} } = req;
|
|
@@ -20,7 +20,7 @@ export default async function update(req) {
|
|
|
20
20
|
|
|
21
21
|
const { actions = [] } = await getAccess({ table: edit, id, user }) || {};
|
|
22
22
|
|
|
23
|
-
if (!actions.includes('edit')) {
|
|
23
|
+
if (!actions.includes('edit') && !config?.local) {
|
|
24
24
|
return { message: 'access restricted', status: 403 };
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import update from './controllers/update.js';
|
|
2
|
+
import insert from './controllers/insert.js';
|
|
3
|
+
import deleteCrud from './controllers/deleteCrud.js';
|
|
4
|
+
|
|
5
|
+
const tableSchema = {
|
|
6
|
+
params: {
|
|
7
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
8
|
+
table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
async function plugin(fastify, config = {}) {
|
|
13
|
+
const prefix = config.prefix || '/api';
|
|
14
|
+
fastify.put(`${prefix}/table/:table/:id?`, { schema: tableSchema }, update);
|
|
15
|
+
fastify.delete(`${prefix}/table/:table/:id?`, { schema: tableSchema }, deleteCrud);
|
|
16
|
+
fastify.post(`${prefix}/table/:table?`, { schema: tableSchema }, insert);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default plugin;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { lstat, readdir, readFile } from 'fs/promises';
|
|
3
|
-
import { createReadStream, existsSync } from 'fs';
|
|
4
|
-
import readline from 'readline';
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { lstat, readdir, readFile } from 'node:fs/promises';
|
|
3
|
+
import { createReadStream, existsSync } from 'node:fs';
|
|
4
|
+
import readline from 'node:readline';
|
|
5
5
|
|
|
6
6
|
import checkUserAccess from './utils/checkUserAccess.js';
|
|
7
7
|
import getRootDir from './utils/getRootDir.js';
|
|
@@ -14,7 +14,7 @@ import getRootDir from './utils/getRootDir.js';
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
export default async function loggerFile({
|
|
17
|
-
params, user, query, originalUrl,
|
|
17
|
+
params = {}, user = {}, query = {}, originalUrl,
|
|
18
18
|
}, reply) {
|
|
19
19
|
const limit = 200000;
|
|
20
20
|
// console.log(user);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import config from '../../../../../config.js';
|
|
4
5
|
|
|
5
6
|
// import { existsSync } from 'fs';
|
|
6
7
|
let logDir = null;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import loggerFile from './controllers/logger.file.js';
|
|
2
|
+
|
|
3
|
+
const loggerSchema = {
|
|
4
|
+
querystring: {
|
|
5
|
+
download: { type: 'string', pattern: '^(\\d+)$' },
|
|
6
|
+
full: { type: 'string', pattern: '^(\\d+)$' },
|
|
7
|
+
dir: { type: 'string', pattern: '^(\\d+)$' },
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
async function plugin(fastify) {
|
|
12
|
+
fastify.get('/logger-file/*', { schema: loggerSchema }, loggerFile);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default plugin;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { dataInsert
|
|
1
|
+
import { dataInsert } from '../../../../utils.js';
|
|
2
2
|
|
|
3
3
|
const table = 'crm.properties';
|
|
4
4
|
|
|
@@ -34,23 +34,22 @@ export default async function addExtraProperties({
|
|
|
34
34
|
return { message: 'table not found: crm.properties', status: 400 };
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return { message: { rows: res }, status: 200 };
|
|
37
|
+
await pg.query('delete from crm.properties where object_id=$1', [id]); // rewrite?
|
|
38
|
+
const keyTypeMatch = extraProperties.filter((key) => body[key]).reduce((acc, curr) => Object.assign(acc, checkKeyType({ body, key: curr })), {});
|
|
39
|
+
const res = await Promise.all(Object.keys(keyTypeMatch).map(async (key) => {
|
|
40
|
+
const propertyType = keyTypeMatch[key];
|
|
41
|
+
const { rows = [] } = await dataInsert({
|
|
42
|
+
pg,
|
|
43
|
+
table,
|
|
44
|
+
data: {
|
|
45
|
+
property_type: propertyType,
|
|
46
|
+
property_key: key,
|
|
47
|
+
object_id: id,
|
|
48
|
+
[`property_${propertyType}`]: body[key],
|
|
49
|
+
},
|
|
50
|
+
uid,
|
|
51
|
+
});
|
|
52
|
+
return { id: rows[0]?.property_id, type: propertyType, value: body[key] };
|
|
53
|
+
}));
|
|
54
|
+
return { message: { rows: res }, status: 200 };
|
|
56
55
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default async function getExtraProperties({
|
|
2
|
+
pg, params = {},
|
|
3
|
+
}) {
|
|
4
|
+
const { id } = params;
|
|
5
|
+
if (!id) {
|
|
6
|
+
return { message: 'not enougn params', status: 400 };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const { rows = [] } = pg.pk?.['crm.properties']
|
|
10
|
+
? await pg.query(`select property_key, property_type, property_text, property_int,
|
|
11
|
+
property_json, property_date from crm.properties where property_key is not null and object_id=$1`, [id])
|
|
12
|
+
: {};
|
|
13
|
+
if (!rows.length) return {};
|
|
14
|
+
|
|
15
|
+
const data = rows.reduce((acc, curr) => Object.assign(acc, { [curr.property_key]: curr[`property_${curr.property_type}`] }), {});
|
|
16
|
+
return { message: data, status: 200 };
|
|
17
|
+
}
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import getExtraProperties from './controllers/properties.get.js';
|
|
2
2
|
import addExtraProperties from './controllers/properties.add.js';
|
|
3
|
-
import nextId from './controllers/next.id.js';
|
|
4
|
-
import statusMonitor from './controllers/status.monitor.js';
|
|
5
|
-
import loggerFile from './controllers/logger.file.js';
|
|
6
3
|
|
|
7
|
-
|
|
4
|
+
const propertiesSchema = {
|
|
5
|
+
params: {
|
|
6
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
7
|
+
},
|
|
8
|
+
};
|
|
8
9
|
|
|
9
10
|
async function plugin(fastify, config = {}) {
|
|
10
11
|
const prefix = config.prefix || '/api';
|
|
11
|
-
|
|
12
|
-
fastify.get(`${prefix}/next-id`, {}, nextId);
|
|
13
|
-
fastify.get(`${prefix}/status-monitor`, {}, statusMonitor);
|
|
14
12
|
fastify.get(`${prefix}/properties/:id`, { schema: propertiesSchema }, getExtraProperties);
|
|
15
13
|
fastify.post(`${prefix}/properties/:id`, { schema: propertiesSchema }, addExtraProperties);
|
|
16
|
-
fastify.get('/logger-file/*', { schema: loggerSchema }, loggerFile);
|
|
17
14
|
}
|
|
18
15
|
|
|
19
16
|
export default plugin;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import applyHook from '../../hook/funcs/applyHook.js';
|
|
5
|
-
import getAccess from '../../crud/funcs/getAccess.js';
|
|
1
|
+
import {
|
|
2
|
+
getTemplate, getMeta, metaFormat, getAccess, applyHook,
|
|
3
|
+
} from '../../../../utils.js';
|
|
6
4
|
|
|
7
5
|
export default async function card(req) {
|
|
8
6
|
const time = Date.now();
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import metaFormat from '../funcs/metaFormat/index.js';
|
|
5
|
-
import getAccess from '../../crud/funcs/getAccess.js';
|
|
6
|
-
import setToken from '../../crud/funcs/setToken.js';
|
|
7
|
-
import gisIRColumn from './utils/gisIRColumn.js';
|
|
8
|
-
import applyHook from '../../hook/funcs/applyHook.js';
|
|
9
|
-
// import config from '../../config.js';
|
|
1
|
+
import {
|
|
2
|
+
config, getTemplate, getFilterSQL, getMeta, metaFormat, getAccess, setToken, gisIRColumn, applyHook,
|
|
3
|
+
} from '../../../../utils.js';
|
|
10
4
|
|
|
11
5
|
const maxLimit = 100;
|
|
12
6
|
export default async function dataAPI(req) {
|
|
@@ -31,7 +25,7 @@ export default async function dataAPI(req) {
|
|
|
31
25
|
const id = hookData?.id || params?.id;
|
|
32
26
|
const { actions = [], query: accessQuery } = await getAccess({ table: hookData?.table || params.table, id, user }) || {};
|
|
33
27
|
|
|
34
|
-
if (!actions.includes('get')) {
|
|
28
|
+
if (!actions.includes('get') && !config?.local) {
|
|
35
29
|
return { message: 'access restricted', status: 403 };
|
|
36
30
|
}
|
|
37
31
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import getFilterSQL from '../funcs/getFilterSQL/index.js';
|
|
1
|
+
import {
|
|
2
|
+
getSelect, getMeta, getFilterSQL, getTemplate,
|
|
3
|
+
} from '../../../../utils.js';
|
|
5
4
|
|
|
6
5
|
export default async function filterAPI(req) {
|
|
7
6
|
const time = Date.now();
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import getTemplates from './utils/getTemplates.js';
|
|
1
|
+
import {
|
|
2
|
+
getMeta, metaFormat, getTemplates, getTemplate, handlebars,
|
|
3
|
+
} from '../../../../utils.js';
|
|
5
4
|
|
|
6
5
|
function sequence(tables, data, fn) {
|
|
7
6
|
return tables.reduce((promise, table) => promise.then(() => fn({
|
|
@@ -10,7 +9,7 @@ function sequence(tables, data, fn) {
|
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
async function getData({
|
|
13
|
-
pg,
|
|
12
|
+
pg, tableName, query = {}, maxLimit, res,
|
|
14
13
|
}) {
|
|
15
14
|
const loadTable = await getTemplate('table', tableName);
|
|
16
15
|
|
|
@@ -46,7 +45,7 @@ async function getData({
|
|
|
46
45
|
await metaFormat({ rows, table: tableName });
|
|
47
46
|
res.total += +total;
|
|
48
47
|
rows.forEach((row) => {
|
|
49
|
-
const href = meta?.href ?
|
|
48
|
+
const href = meta?.href ? handlebars.compile(meta.href)({ ...row, [pk]: row.id }) : undefined;
|
|
50
49
|
res.rows.push({
|
|
51
50
|
...row, register: tableName, register_title: loadTable.ua, href,
|
|
52
51
|
});
|
|
@@ -59,18 +58,17 @@ export default async function search({
|
|
|
59
58
|
}) {
|
|
60
59
|
const time = Date.now();
|
|
61
60
|
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
const tables = query.table ? [query.table] : await getTemplates('table');
|
|
62
|
+
const res = { rows: [], sql: [], total: 0 };
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
const maxLimit = Math.min(100, query.limit || '16');
|
|
65
|
+
await sequence(tables, {
|
|
66
|
+
pg, funcs, query, maxLimit, res,
|
|
67
|
+
}, getData);
|
|
69
68
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
time: Date.now() - time, total: res.total, count: res.rows.length, rows: res.rows,
|
|
74
|
-
};
|
|
69
|
+
if (query.sql) return res.sql.join(';\n');
|
|
75
70
|
|
|
71
|
+
return {
|
|
72
|
+
time: Date.now() - time, total: res.total, count: res.rows.length, rows: res.rows,
|
|
73
|
+
};
|
|
76
74
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import getTemplate from './utils/getTemplate.js';
|
|
5
|
-
|
|
6
|
-
// import getTableSql from '../funcs/getFilterSQL/util/getTableSql.js';
|
|
1
|
+
import {
|
|
2
|
+
config, getPG, getTemplate, getSelectMeta,
|
|
3
|
+
} from '../../../../utils.js';
|
|
7
4
|
|
|
8
5
|
const limit = 50;
|
|
9
|
-
const headers = {
|
|
6
|
+
const headers = {
|
|
7
|
+
'Access-Control-Allow-Origin': '*',
|
|
8
|
+
'Access-Control-Allow-Methods': 'GET',
|
|
9
|
+
'Cache-Control': 'no-cache',
|
|
10
|
+
};
|
|
10
11
|
|
|
11
12
|
export default async function suggest(req) {
|
|
12
13
|
const {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import applyHook from '../../hook/funcs/applyHook.js';
|
|
5
|
-
import getAccess from '../../crud/funcs/getAccess.js';
|
|
1
|
+
import {
|
|
2
|
+
config, getAccess, getTemplate, getMeta, setToken, applyHook,
|
|
3
|
+
} from '../../../../utils.js';
|
|
6
4
|
|
|
7
5
|
export default async function tableAPI(req) {
|
|
8
6
|
const {
|
|
@@ -31,7 +29,7 @@ export default async function tableAPI(req) {
|
|
|
31
29
|
user,
|
|
32
30
|
}) || {};
|
|
33
31
|
|
|
34
|
-
if (!actions.includes('edit')) {
|
|
32
|
+
if (!actions.includes('edit') && !config?.local) {
|
|
35
33
|
return { message: 'access restricted', status: 403 };
|
|
36
34
|
}
|
|
37
35
|
|
|
@@ -63,7 +61,7 @@ export default async function tableAPI(req) {
|
|
|
63
61
|
if (extraKeys?.length) {
|
|
64
62
|
await Promise.all(extraKeys?.map(async (key) => {
|
|
65
63
|
const { colModel, table: extraTable, parent_id: parentId } = schema[key];
|
|
66
|
-
const { rows: extraRows } = await pg.query(`select ${parentId} as parent, ${colModel.map((col) => col.name).join(',')} from ${extraTable} a where ${parentId}=$1`, [
|
|
64
|
+
const { rows: extraRows } = await pg.query(`select ${parentId} as parent, ${colModel.map((col) => col.name).join(',')} from ${extraTable} a where ${parentId}=$1`, [hookData?.id || params?.id]);
|
|
67
65
|
Object.assign(data, { [key]: extraRows });
|
|
68
66
|
}));
|
|
69
67
|
}
|
|
@@ -5,12 +5,8 @@ import card from './controllers/card.js';
|
|
|
5
5
|
import search from './controllers/search.js';
|
|
6
6
|
import filter from './controllers/filter.js';
|
|
7
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
8
|
|
|
13
|
-
import loadTemplatePath from '
|
|
9
|
+
import loadTemplatePath from '../../plugins/table/funcs/loadTemplatePath.js';
|
|
14
10
|
|
|
15
11
|
import {
|
|
16
12
|
tableSchema, searchSchema, suggestSchema, formSchema, filterSchema,
|
|
@@ -18,11 +14,6 @@ import {
|
|
|
18
14
|
|
|
19
15
|
async function plugin(fastify, config = {}) {
|
|
20
16
|
const prefix = config.prefix || '/api';
|
|
21
|
-
fastify.decorate('metaFormat', metaFormat);
|
|
22
|
-
fastify.decorate('getFilterSQL', getFilterSQL);
|
|
23
|
-
fastify.decorate('getTemplate', getTemplate);
|
|
24
|
-
fastify.decorate('getSelect', getSelect);
|
|
25
|
-
|
|
26
17
|
fastify.get(`${prefix}/suggest/:data`, { schema: suggestSchema }, suggest);
|
|
27
18
|
fastify.get(`${prefix}/data/:table/:id?`, { schema: tableSchema }, data); // vs.crm.data.api с node
|
|
28
19
|
fastify.get(`${prefix}/table/:table/:id?`, { schema: tableSchema }, table);
|
|
@@ -9,7 +9,7 @@ const tableSchema = {
|
|
|
9
9
|
// state: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
|
|
10
10
|
// custom: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
|
|
11
11
|
bbox: { type: 'string', pattern: '^([\\d\\s,.-]+)$' },
|
|
12
|
-
polyline: { type: 'string', pattern: '^([\\d\\w\\|@\\/\\{\\}~_`]+)$' },
|
|
12
|
+
// polyline: { type: 'string', pattern: '^([\\d\\w\\|@\\/\\{\\}~_`]+)$' },
|
|
13
13
|
key: { type: 'string', pattern: '^([А-Яа-яҐґЄєІіЇї\\d\\w\\s_.-]+)$' },
|
|
14
14
|
uid: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
|
|
15
15
|
sql: { type: 'string', pattern: '^(\\d)$' },
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import nextId from './controllers/next.id.js';
|
|
2
|
+
import statusMonitor from './controllers/status.monitor.js';
|
|
3
|
+
|
|
4
|
+
async function plugin(fastify, config = {}) {
|
|
5
|
+
const prefix = config.prefix || '/api';
|
|
6
|
+
|
|
7
|
+
fastify.get(`${prefix}/next-id`, {}, nextId);
|
|
8
|
+
fastify.get(`${prefix}/status-monitor`, {}, statusMonitor);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default plugin;
|