@opengis/cms 0.0.26 → 0.0.28

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.
Files changed (90) hide show
  1. package/README.md +98 -98
  2. package/dist/index-W-qQIppj-DunG40EG.js +2452 -0
  3. package/dist/index.html +28 -28
  4. package/dist/index.js +12683 -6702
  5. package/dist/index.umd.cjs +87 -41
  6. package/dist/style.css +1 -0
  7. package/package.json +68 -68
  8. package/plugin.js +76 -76
  9. package/server/app.js +35 -35
  10. package/server/config.js +4 -4
  11. package/server/functions/getDraftKey.js +22 -22
  12. package/server/index.js +22 -22
  13. package/server/migrations/fixes.sql +123 -123
  14. package/server/migrations/site.sql +545 -545
  15. package/server/plugins/adminHook.js +78 -78
  16. package/server/plugins/hook.js +59 -59
  17. package/server/plugins/vite.js +84 -84
  18. package/server/routes/category/controllers/cms.category.delete.js +21 -21
  19. package/server/routes/category/controllers/cms.category.get.js +17 -17
  20. package/server/routes/category/controllers/cms.category.list.js +16 -16
  21. package/server/routes/category/controllers/cms.category.post.js +21 -21
  22. package/server/routes/category/controllers/cms.category.put.js +23 -23
  23. package/server/routes/category/index.mjs +22 -22
  24. package/server/routes/cms/controllers/cmsStat.js +55 -55
  25. package/server/routes/cms/controllers/cmsSuggest.js +57 -57
  26. package/server/routes/cms/controllers/deleteContent.js +114 -114
  27. package/server/routes/cms/controllers/deleteMedia.js +75 -75
  28. package/server/routes/cms/controllers/downloadMedia.js +48 -48
  29. package/server/routes/cms/controllers/getContent.js +110 -110
  30. package/server/routes/cms/controllers/getContentBySlug.js +95 -95
  31. package/server/routes/cms/controllers/getPermissions.js +15 -15
  32. package/server/routes/cms/controllers/insertContent.js +218 -218
  33. package/server/routes/cms/controllers/listMedia.js +93 -93
  34. package/server/routes/cms/controllers/metadataMedia.js +38 -38
  35. package/server/routes/cms/controllers/properties.get.js +53 -53
  36. package/server/routes/cms/controllers/properties.post.js +99 -99
  37. package/server/routes/cms/controllers/searchContent.js +205 -205
  38. package/server/routes/cms/controllers/setPermissions.js +49 -49
  39. package/server/routes/cms/controllers/translate.js +89 -89
  40. package/server/routes/cms/controllers/updateContent.js +238 -238
  41. package/server/routes/cms/controllers/uploadMedia.js +78 -78
  42. package/server/routes/cms/index.mjs +114 -114
  43. package/server/routes/cms/utils/additionalData.js +35 -35
  44. package/server/routes/cms/utils/getCollection.js +81 -81
  45. package/server/routes/cms/utils/getSingle.js +187 -187
  46. package/server/routes/cms/utils/insertContentLocalization.js +86 -86
  47. package/server/routes/cms/utils/requestTranslation.js +85 -85
  48. package/server/routes/cms/utils/updateLocalization.js +47 -47
  49. package/server/routes/cmsSpace/controllers/deleteSpace.js +25 -25
  50. package/server/routes/cmsSpace/controllers/getSpaces.js +27 -27
  51. package/server/routes/cmsSpace/controllers/insertSpace.js +21 -21
  52. package/server/routes/cmsSpace/controllers/updateSpace.js +23 -23
  53. package/server/routes/cmsSpace/index.mjs +20 -20
  54. package/server/routes/contentType/controllers/addContentType.js +162 -162
  55. package/server/routes/contentType/controllers/contentTypeList.js +54 -54
  56. package/server/routes/contentType/controllers/delContentType.js +75 -75
  57. package/server/routes/contentType/controllers/editContentType.js +61 -61
  58. package/server/routes/contentType/controllers/getContentType.js +37 -37
  59. package/server/routes/contentType/index.mjs +35 -35
  60. package/server/routes/contentType/utils/updateContents.js +28 -28
  61. package/server/routes/contentType/utils/updateCustomContentTable.js +55 -55
  62. package/server/routes/feedback/controllers/email.list.js +24 -24
  63. package/server/routes/feedback/controllers/feedback.js +48 -48
  64. package/server/routes/feedback/controllers/feedback.list.js +37 -37
  65. package/server/routes/feedback/controllers/news.subscriptions.js +44 -44
  66. package/server/routes/feedback/index.mjs +71 -71
  67. package/server/routes/logs/controllers/export.user.logs.js +77 -77
  68. package/server/routes/logs/controllers/user.logs.js +44 -44
  69. package/server/routes/logs/index.mjs +9 -9
  70. package/server/routes/menu/controllers/addMenu.js +37 -37
  71. package/server/routes/menu/controllers/delMenu.js +31 -31
  72. package/server/routes/menu/controllers/editMenu.js +41 -41
  73. package/server/routes/menu/controllers/getMenu.js +42 -42
  74. package/server/routes/menu/index.mjs +13 -13
  75. package/server/routes/migration/controllers/collectionToCustom.js +137 -137
  76. package/server/routes/migration/index.mjs +8 -8
  77. package/server/routes/root.mjs +8 -8
  78. package/server/routes/tags/controllers/add.tags.js +24 -24
  79. package/server/routes/tags/controllers/del.tags.js +19 -19
  80. package/server/routes/tags/controllers/edit.tags.js +25 -25
  81. package/server/routes/tags/controllers/get.tags.js +15 -15
  82. package/server/routes/tags/index.mjs +14 -14
  83. package/server/templates/cls/cms.category_type.json +9 -9
  84. package/server/templates/cls/cms.content_review_status.json +9 -9
  85. package/server/templates/cls/cms.content_status.json +9 -9
  86. package/server/templates/cls/cms.content_type.json +9 -9
  87. package/server/templates/cls/cms.lang.json +9 -9
  88. package/server/templates/page/login.html +126 -126
  89. package/server/templates/select/core.user_mentioned.sql +1 -1
  90. package/dist/index-W-qQIppj-DRzFSjU1.js +0 -2452
@@ -1,32 +1,32 @@
1
- import { dataDelete } from "@opengis/fastify-table/utils.js";
2
-
3
- export default async function delMenu(req, reply) {
4
- const { pg = pgClients.client, params = {}, user = {}, headers = {}, body = {} } = req;
5
-
6
- if (!pg?.pk) {
7
- return reply.status(400).send('empty pg');
8
- }
9
-
10
- if (!pg?.pk?.['site.menus']) {
11
- return reply.status(404).send('table not found');
12
- }
13
-
14
- if (!params.id) {
15
- return reply.status(400).send('not enough params: id');
16
- }
17
-
18
- const res = await dataDelete({
19
- pg,
20
- table: 'site.menus',
21
- id: params.id,
22
- data: body,
23
- referer: headers.referer,
24
- uid: user.uid,
25
- });
26
-
27
- if (!res) {
28
- return reply.status(500).send('delete menu error');
29
- }
30
-
31
- return reply.status(200).send(res);
1
+ import { dataDelete } from "@opengis/fastify-table/utils.js";
2
+
3
+ export default async function delMenu(req, reply) {
4
+ const { pg = pgClients.client, params = {}, user = {}, headers = {}, body = {} } = req;
5
+
6
+ if (!pg?.pk) {
7
+ return reply.status(400).send('empty pg');
8
+ }
9
+
10
+ if (!pg?.pk?.['site.menus']) {
11
+ return reply.status(404).send('table not found');
12
+ }
13
+
14
+ if (!params.id) {
15
+ return reply.status(400).send('not enough params: id');
16
+ }
17
+
18
+ const res = await dataDelete({
19
+ pg,
20
+ table: 'site.menus',
21
+ id: params.id,
22
+ data: body,
23
+ referer: headers.referer,
24
+ uid: user.uid,
25
+ });
26
+
27
+ if (!res) {
28
+ return reply.status(500).send('delete menu error');
29
+ }
30
+
31
+ return reply.status(200).send(res);
32
32
  }
@@ -1,42 +1,42 @@
1
- import { dataUpdate, yml2json, json2yml } from "@opengis/fastify-table/utils.js";
2
-
3
- export default async function editMenu(req, reply) {
4
- const { pg = pgClients.client, params = {}, user = {}, headers = {}, body = {} } = req;
5
-
6
- if (!pg?.pk) {
7
- return reply.status(400).send('empty pg');
8
- }
9
-
10
- if (!pg?.pk?.['site.menus']) {
11
- return reply.status(404).send('table not found');
12
- }
13
-
14
- if (!params.id) {
15
- return reply.status(400).send('not enough params: id');
16
- }
17
-
18
- if (typeof body.content === 'string') {
19
- body.items = yml2json(body.content || '');
20
- } else if (body.items && typeof body.items === 'object') {
21
- body.content = json2yml(body.items || {});
22
- }
23
-
24
- if (!Object.keys(body.items || {}).length) {
25
- return reply.status(400).send('access restricted: empty json items / invalid yml content');
26
- }
27
-
28
- const res = await dataUpdate({
29
- pg,
30
- table: 'site.menus',
31
- id: params.id,
32
- data: body,
33
- referer: headers.referer,
34
- uid: user.uid,
35
- });
36
-
37
- if (!res) {
38
- return reply.status(500).send('update menu error');
39
- }
40
-
41
- return reply.status(200).send(res);
1
+ import { dataUpdate, yml2json, json2yml } from "@opengis/fastify-table/utils.js";
2
+
3
+ export default async function editMenu(req, reply) {
4
+ const { pg = pgClients.client, params = {}, user = {}, headers = {}, body = {} } = req;
5
+
6
+ if (!pg?.pk) {
7
+ return reply.status(400).send('empty pg');
8
+ }
9
+
10
+ if (!pg?.pk?.['site.menus']) {
11
+ return reply.status(404).send('table not found');
12
+ }
13
+
14
+ if (!params.id) {
15
+ return reply.status(400).send('not enough params: id');
16
+ }
17
+
18
+ if (typeof body.content === 'string') {
19
+ body.items = yml2json(body.content || '');
20
+ } else if (body.items && typeof body.items === 'object') {
21
+ body.content = json2yml(body.items || {});
22
+ }
23
+
24
+ if (!Object.keys(body.items || {}).length) {
25
+ return reply.status(400).send('access restricted: empty json items / invalid yml content');
26
+ }
27
+
28
+ const res = await dataUpdate({
29
+ pg,
30
+ table: 'site.menus',
31
+ id: params.id,
32
+ data: body,
33
+ referer: headers.referer,
34
+ uid: user.uid,
35
+ });
36
+
37
+ if (!res) {
38
+ return reply.status(500).send('update menu error');
39
+ }
40
+
41
+ return reply.status(200).send(res);
42
42
  }
@@ -1,43 +1,43 @@
1
- import { pgClients } from "@opengis/fastify-table/utils.js";
2
-
3
- const limit = 16;
4
-
5
- const err = { error: 'menu not found', code: 404 };
6
-
7
- export default async function getMenu(req, reply) {
8
- const { pg = pgClients.client, query = {}, params = {} } = req;
9
-
10
- if (!pg?.pk) {
11
- return reply.status(400).send('empty pg');
12
- }
13
-
14
- if (!pg?.pk?.['site.menus']) {
15
- return reply.status(404).send('table not found');
16
- }
17
-
18
- const offset = query.page && query.page > 0 ? (query.page - 1) * limit : 0;
19
-
20
- const q = `select menu_id, name, locale, description ${params.id ? ',items::json, content' : ''} from site.menus
21
- where ${params.id ? '$1 in (menu_id, name)' : '1=1'}
22
- and ${query.locale ? `locale='${query.locale.replace(/'/g, "''")}'` : 'true'}
23
- order by (case when locale='uk' then false else true end)
24
- limit ${limit} offset ${offset}`;
25
-
26
- if (query.sql) return q;
27
-
28
- const rows = await pg.query(q, [params.id].filter(Boolean))
29
- .then(el => el.rows || []);
30
-
31
- if (params.id) {
32
- if (!rows.length && params.id) {
33
- return reply.status(404).send(err);
34
- }
35
- return reply.status(200).send(rows[0]);
36
- }
37
-
38
- if (!rows.length && params.id) {
39
- return reply.status(404).send(err);
40
- }
41
-
42
- return reply.status(200).send({ rows });
1
+ import { pgClients } from "@opengis/fastify-table/utils.js";
2
+
3
+ const limit = 16;
4
+
5
+ const err = { error: 'menu not found', code: 404 };
6
+
7
+ export default async function getMenu(req, reply) {
8
+ const { pg = pgClients.client, query = {}, params = {} } = req;
9
+
10
+ if (!pg?.pk) {
11
+ return reply.status(400).send('empty pg');
12
+ }
13
+
14
+ if (!pg?.pk?.['site.menus']) {
15
+ return reply.status(404).send('table not found');
16
+ }
17
+
18
+ const offset = query.page && query.page > 0 ? (query.page - 1) * limit : 0;
19
+
20
+ const q = `select menu_id, name, locale, description ${params.id ? ',items::json, content' : ''} from site.menus
21
+ where ${params.id ? '$1 in (menu_id, name)' : '1=1'}
22
+ and ${query.locale ? `locale='${query.locale.replace(/'/g, "''")}'` : 'true'}
23
+ order by (case when locale='uk' then false else true end)
24
+ limit ${limit} offset ${offset}`;
25
+
26
+ if (query.sql) return q;
27
+
28
+ const rows = await pg.query(q, [params.id].filter(Boolean))
29
+ .then(el => el.rows || []);
30
+
31
+ if (params.id) {
32
+ if (!rows.length && params.id) {
33
+ return reply.status(404).send(err);
34
+ }
35
+ return reply.status(200).send(rows[0]);
36
+ }
37
+
38
+ if (!rows.length && params.id) {
39
+ return reply.status(404).send(err);
40
+ }
41
+
42
+ return reply.status(200).send({ rows });
43
43
  }
@@ -1,13 +1,13 @@
1
- import getMenu from './controllers/getMenu.js';
2
- import addMenu from './controllers/addMenu.js';
3
- import editMenu from './controllers/editMenu.js';
4
- import delMenu from './controllers/delMenu.js';
5
-
6
- const params = { config: { policy: ['public'] } };
7
-
8
- export default async function route(app) {
9
- app.post('/cms-menu/:id?', params, addMenu);
10
- app.put('/cms-menu/:id', params, editMenu);
11
- app.delete('/cms-menu/:id', params, delMenu);
12
- app.get('/cms-menu/:id?', params, getMenu);
13
- }
1
+ import getMenu from './controllers/getMenu.js';
2
+ import addMenu from './controllers/addMenu.js';
3
+ import editMenu from './controllers/editMenu.js';
4
+ import delMenu from './controllers/delMenu.js';
5
+
6
+ const params = { config: { policy: ['public'] } };
7
+
8
+ export default async function route(app) {
9
+ app.post('/cms-menu/:id?', params, addMenu);
10
+ app.put('/cms-menu/:id', params, editMenu);
11
+ app.delete('/cms-menu/:id', params, delMenu);
12
+ app.get('/cms-menu/:id?', params, getMenu);
13
+ }
@@ -1,137 +1,137 @@
1
- export default async function collectionToCustom(req, reply) {
2
- const { params, pg, query } = req;
3
- const { id } = params;
4
-
5
- if (!id) return reply.code(400).send({ status: 400, message: 'Невказаний id або slug колекції!' });
6
-
7
- const selectTableStructure = `
8
- select
9
- name,
10
- title,
11
- columns,
12
- type
13
- from site.content_types
14
- where '${id}' in (content_type_id,name)
15
- limit 1
16
- `;
17
-
18
- const { name, title, columns, type } = await pg.one(selectTableStructure);
19
-
20
- if (!name || !title) return reply.code(404).send({ status: 404, message: 'За вказаним параметром колекції не існує!' });
21
- if (!columns || columns?.length === 0) return reply.code(400).send({ status: 400, message: 'У вказаної колекції відсутня структура колонок!' });
22
- if (type !== 'collection') return reply.code(400).send({ status: 400, message: 'У вказаного об\'єкта тип не відповідає колекції' });
23
-
24
- let createTableSql = `
25
- CREATE TABLE IF NOT EXISTS data."${name}"(
26
- id text not null DEFAULT next_id(),
27
- slug text NOT NULL,
28
- title text NOT NULL,
29
- status text NOT NULL DEFAULT 'draft'::text,
30
- published_at timestamp without time zone NOT NULL,
31
- created_at timestamp without time zone NOT NULL DEFAULT now(),
32
- updated_at timestamp without time zone NOT NULL DEFAULT now(),
33
- CONSTRAINT "${name}_pkey" PRIMARY KEY (id)
34
- );
35
- COMMENT ON TABLE data."${name}" IS '${title}';
36
- `;
37
-
38
- let recordColumns = [];
39
- let columnsArrFormat = [];
40
- let columnsArr = [];
41
-
42
- columns?.forEach(column => {
43
- if (column?.name && column?.type) {
44
- const columnType = (() => {
45
- switch (column?.type) {
46
- case 'text': return 'text';
47
- case 'number': return 'numeric';
48
- case 'integer': return 'integer';
49
- case 'date': return 'date';
50
- case 'datetime': return 'timestamp without time zone';
51
- case 'select': return 'text';
52
- case 'multiselect': return 'text[]';
53
- case 'radio': return 'text[]';
54
- case 'boolean': return 'boolean';
55
- case 'array':
56
- switch (column?.subtype) {
57
- case 'text': return 'text[]';
58
- case 'number': return 'numeric[]';
59
- case 'integer': return 'integer[]';
60
- case 'date': return 'date[]';
61
- case 'datetime': return 'timestamp without time zone[]';
62
- case 'boolean': return 'boolean[]';
63
- default: return 'text[]';
64
- }
65
- case 'datalist': return 'json';
66
- case 'image': return 'text';
67
- case 'slug': return 'text';
68
- case 'richtext': return 'text';
69
- case 'FileList': return 'text[]';
70
- default: return 'text';
71
- }
72
- })();
73
-
74
- const columnSql = `\nALTER TABLE data."${name}" ADD COLUMN IF NOT EXISTS "${column.name}" ${columnType};\nCOMMENT ON COLUMN data."${name}"."${column.name}" IS '${column?.label}';
75
- `;
76
- createTableSql += columnSql;
77
-
78
- const recordColumn = `"${column.name}" ${columnType}`;
79
- recordColumns.push(recordColumn);
80
- columnsArr.push(`"${column.name}"`);
81
- if (columnType === 'json') {
82
- columnsArrFormat.push(`replace(replace(replace("${column.name}"::text,'\"','"'),'"[','['), ']"',']')::json as "${column.name}"`);
83
- } else {
84
- columnsArrFormat.push(`"${column.name}"`);
85
- }
86
-
87
-
88
- }
89
- });
90
- if (query?.sql == 1) return createTableSql;
91
- await pg.query(createTableSql);
92
-
93
- const insertSql = `
94
- insert into data."${name}" (
95
- id,${columnsArr.join(',')}
96
- )
97
- SELECT
98
- id,${columnsArrFormat.join(',')}
99
- FROM
100
-
101
- (
102
- select
103
- jsonb_build_object('id',object_id)||jsonb_object_agg(field_key,field_value) as row
104
- from site.content_data
105
- where content_id = (
106
- select content_id
107
- from site.contents
108
- where content_type_id = (
109
- select content_type_id
110
- from site.content_types
111
- where '${id}' in (name,content_type_id)
112
- limit 1
113
- )
114
- limit 1
115
- )
116
- group by object_id
117
- )q,
118
- jsonb_to_record(row) AS x(
119
- id text,${recordColumns.join(',')}
120
- )
121
- on conflict (id) do nothing;`;
122
- //return insertSql;
123
- if (query?.sql == 2) return insertSql;
124
- await pg.query(insertSql);
125
-
126
- await pg.one(`
127
- update site.content_types
128
- set table_name='${name}'
129
- where name='${name}'
130
- `);
131
-
132
- return reply.code(200).send({
133
- status: 200,
134
- message: `Табличку data.\"${name}\" успішно створено, дані колекції перенесено.`
135
- });
136
-
137
- }
1
+ export default async function collectionToCustom(req, reply) {
2
+ const { params, pg, query } = req;
3
+ const { id } = params;
4
+
5
+ if (!id) return reply.code(400).send({ status: 400, message: 'Невказаний id або slug колекції!' });
6
+
7
+ const selectTableStructure = `
8
+ select
9
+ name,
10
+ title,
11
+ columns,
12
+ type
13
+ from site.content_types
14
+ where '${id}' in (content_type_id,name)
15
+ limit 1
16
+ `;
17
+
18
+ const { name, title, columns, type } = await pg.one(selectTableStructure);
19
+
20
+ if (!name || !title) return reply.code(404).send({ status: 404, message: 'За вказаним параметром колекції не існує!' });
21
+ if (!columns || columns?.length === 0) return reply.code(400).send({ status: 400, message: 'У вказаної колекції відсутня структура колонок!' });
22
+ if (type !== 'collection') return reply.code(400).send({ status: 400, message: 'У вказаного об\'єкта тип не відповідає колекції' });
23
+
24
+ let createTableSql = `
25
+ CREATE TABLE IF NOT EXISTS data."${name}"(
26
+ id text not null DEFAULT next_id(),
27
+ slug text NOT NULL,
28
+ title text NOT NULL,
29
+ status text NOT NULL DEFAULT 'draft'::text,
30
+ published_at timestamp without time zone NOT NULL,
31
+ created_at timestamp without time zone NOT NULL DEFAULT now(),
32
+ updated_at timestamp without time zone NOT NULL DEFAULT now(),
33
+ CONSTRAINT "${name}_pkey" PRIMARY KEY (id)
34
+ );
35
+ COMMENT ON TABLE data."${name}" IS '${title}';
36
+ `;
37
+
38
+ let recordColumns = [];
39
+ let columnsArrFormat = [];
40
+ let columnsArr = [];
41
+
42
+ columns?.forEach(column => {
43
+ if (column?.name && column?.type) {
44
+ const columnType = (() => {
45
+ switch (column?.type) {
46
+ case 'text': return 'text';
47
+ case 'number': return 'numeric';
48
+ case 'integer': return 'integer';
49
+ case 'date': return 'date';
50
+ case 'datetime': return 'timestamp without time zone';
51
+ case 'select': return 'text';
52
+ case 'multiselect': return 'text[]';
53
+ case 'radio': return 'text[]';
54
+ case 'boolean': return 'boolean';
55
+ case 'array':
56
+ switch (column?.subtype) {
57
+ case 'text': return 'text[]';
58
+ case 'number': return 'numeric[]';
59
+ case 'integer': return 'integer[]';
60
+ case 'date': return 'date[]';
61
+ case 'datetime': return 'timestamp without time zone[]';
62
+ case 'boolean': return 'boolean[]';
63
+ default: return 'text[]';
64
+ }
65
+ case 'datalist': return 'json';
66
+ case 'image': return 'text';
67
+ case 'slug': return 'text';
68
+ case 'richtext': return 'text';
69
+ case 'FileList': return 'text[]';
70
+ default: return 'text';
71
+ }
72
+ })();
73
+
74
+ const columnSql = `\nALTER TABLE data."${name}" ADD COLUMN IF NOT EXISTS "${column.name}" ${columnType};\nCOMMENT ON COLUMN data."${name}"."${column.name}" IS '${column?.label}';
75
+ `;
76
+ createTableSql += columnSql;
77
+
78
+ const recordColumn = `"${column.name}" ${columnType}`;
79
+ recordColumns.push(recordColumn);
80
+ columnsArr.push(`"${column.name}"`);
81
+ if (columnType === 'json') {
82
+ columnsArrFormat.push(`replace(replace(replace("${column.name}"::text,'\"','"'),'"[','['), ']"',']')::json as "${column.name}"`);
83
+ } else {
84
+ columnsArrFormat.push(`"${column.name}"`);
85
+ }
86
+
87
+
88
+ }
89
+ });
90
+ if (query?.sql == 1) return createTableSql;
91
+ await pg.query(createTableSql);
92
+
93
+ const insertSql = `
94
+ insert into data."${name}" (
95
+ id,${columnsArr.join(',')}
96
+ )
97
+ SELECT
98
+ id,${columnsArrFormat.join(',')}
99
+ FROM
100
+
101
+ (
102
+ select
103
+ jsonb_build_object('id',object_id)||jsonb_object_agg(field_key,field_value) as row
104
+ from site.content_data
105
+ where content_id = (
106
+ select content_id
107
+ from site.contents
108
+ where content_type_id = (
109
+ select content_type_id
110
+ from site.content_types
111
+ where '${id}' in (name,content_type_id)
112
+ limit 1
113
+ )
114
+ limit 1
115
+ )
116
+ group by object_id
117
+ )q,
118
+ jsonb_to_record(row) AS x(
119
+ id text,${recordColumns.join(',')}
120
+ )
121
+ on conflict (id) do nothing;`;
122
+ //return insertSql;
123
+ if (query?.sql == 2) return insertSql;
124
+ await pg.query(insertSql);
125
+
126
+ await pg.one(`
127
+ update site.content_types
128
+ set table_name='${name}'
129
+ where name='${name}'
130
+ `);
131
+
132
+ return reply.code(200).send({
133
+ status: 200,
134
+ message: `Табличку data.\"${name}\" успішно створено, дані колекції перенесено.`
135
+ });
136
+
137
+ }
@@ -1,8 +1,8 @@
1
- import collectionToCustom from './controllers/collectionToCustom.js';
2
-
3
- const params = { config: { policy: ['public'] } };
4
-
5
- export default async function route(app) {
6
-
7
- app.get('/collection-to-custom/:id', params, collectionToCustom);
8
- }
1
+ import collectionToCustom from './controllers/collectionToCustom.js';
2
+
3
+ const params = { config: { policy: ['public'] } };
4
+
5
+ export default async function route(app) {
6
+
7
+ app.get('/collection-to-custom/:id', params, collectionToCustom);
8
+ }
@@ -1,8 +1,8 @@
1
- 'use strict'
2
-
3
- export default async function (fastify, opts) {
4
- fastify.get('/test', async function (request, reply) {
5
- return { root: true }
6
- });
7
-
8
- }
1
+ 'use strict'
2
+
3
+ export default async function (fastify, opts) {
4
+ fastify.get('/test', async function (request, reply) {
5
+ return { root: true }
6
+ });
7
+
8
+ }
@@ -1,25 +1,25 @@
1
- import { dataInsert } from "@opengis/fastify-table/utils.js";
2
-
3
- export default async function addTags(req, reply) {
4
- const { pg, body, user } = req;
5
-
6
- const { uid } = user || {};
7
-
8
- if (!uid) {
9
- return reply.code(401).send({ message: 'access restricted', status: 401 })
10
- }
11
-
12
- if (!body) {
13
- return reply.code(400).send({ message: 'body is empty!', status: 400 });
14
- }
15
-
16
- await dataInsert({
17
- pg,
18
- table: 'site.tags',
19
- data: body,
20
- uid,
21
- });
22
-
23
- return reply.code(201).send({ message: 'Tag added successfully', status: 201 });
24
-
1
+ import { dataInsert } from "@opengis/fastify-table/utils.js";
2
+
3
+ export default async function addTags(req, reply) {
4
+ const { pg, body, user } = req;
5
+
6
+ const { uid } = user || {};
7
+
8
+ if (!uid) {
9
+ return reply.code(401).send({ message: 'access restricted', status: 401 })
10
+ }
11
+
12
+ if (!body) {
13
+ return reply.code(400).send({ message: 'body is empty!', status: 400 });
14
+ }
15
+
16
+ await dataInsert({
17
+ pg,
18
+ table: 'site.tags',
19
+ data: body,
20
+ uid,
21
+ });
22
+
23
+ return reply.code(201).send({ message: 'Tag added successfully', status: 201 });
24
+
25
25
  }
@@ -1,20 +1,20 @@
1
- import { pgClients } from "@opengis/fastify-table/utils.js";
2
-
3
- export default async function delTags(req, reply) {
4
- const { pg = pgClients.client, user = {}, params = {} } = req;
5
- const { id } = params;
6
-
7
- const { uid } = user;
8
-
9
- if (!uid) {
10
- return reply.code(401).send('unauthorized');
11
- }
12
-
13
- if (!id) {
14
- return reply.code(400).send('id is required!');
15
- }
16
-
17
- await pg.query('delete from site.tags where tag_id=$1', [id]);
18
-
19
- return reply.code(200).send({ message: 'Tag deleted', status: 200 });
1
+ import { pgClients } from "@opengis/fastify-table/utils.js";
2
+
3
+ export default async function delTags(req, reply) {
4
+ const { pg = pgClients.client, user = {}, params = {} } = req;
5
+ const { id } = params;
6
+
7
+ const { uid } = user;
8
+
9
+ if (!uid) {
10
+ return reply.code(401).send('unauthorized');
11
+ }
12
+
13
+ if (!id) {
14
+ return reply.code(400).send('id is required!');
15
+ }
16
+
17
+ await pg.query('delete from site.tags where tag_id=$1', [id]);
18
+
19
+ return reply.code(200).send({ message: 'Tag deleted', status: 200 });
20
20
  };