@opengis/cms 0.0.57 → 0.0.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.
Files changed (149) hide show
  1. package/README.md +131 -131
  2. package/dist/AddNewItemInTree-05PSSEFi.js +76 -0
  3. package/dist/ArticlesPage-CFjE_cw_.js +298 -0
  4. package/dist/CollectionsBreadcrumb-BCxeRikP.js +4 -0
  5. package/dist/CollectionsBreadcrumb.vue_vue_type_script_setup_true_lang-umRzB5mY.js +53 -0
  6. package/dist/CollectionsPage-DHfPNql6.js +124 -0
  7. package/dist/{CreateForm-BMOBeP4G.js → CreateForm-5FvT45vH.js} +1 -1
  8. package/dist/Dashboard-C1eGscNd.js +358 -0
  9. package/dist/EditCollectionPage-DIr1tdtn.js +187 -0
  10. package/dist/{EmptyData-DaZt_nAm.js → EmptyData-DxPrSXhV.js} +1 -1
  11. package/dist/{MenuAddPage-Bf48Z-ah.js → MenuAddPage-D-p3gFgm.js} +40 -35
  12. package/dist/MenuBody-rN5j4YBu.js +125 -0
  13. package/dist/MenuItemPage-BoJw885D.js +1027 -0
  14. package/dist/MenuList-DFEBS0NB.js +172 -0
  15. package/dist/MenuPage-BCZB_S8j.js +107 -0
  16. package/dist/MenuWrapper-AZ_8s-zd.js +12 -0
  17. package/dist/MonacoEditor-Db-3Jc3E.js +4 -0
  18. package/dist/{UniversalTable.vue_vue_type_script_setup_true_lang-CJGTsd1V.js → UniversalTable-CzqPG-tY.js} +12 -12
  19. package/dist/{UniversalTablePagination.vue_vue_type_script_setup_true_lang-GYZd_gkA.js → UniversalTablePagination-4gL47A7I.js} +1 -1
  20. package/dist/VsFormTags-CMjiu9sY.js +114 -0
  21. package/dist/VsPreview-DwETkOpb.js +63 -0
  22. package/dist/contentForm-CtMhQTG0.js +489 -0
  23. package/dist/getField-CpwVE28P.js +179 -0
  24. package/dist/index.d.ts +8 -0
  25. package/dist/index.html +29 -29
  26. package/dist/index.js +72 -71
  27. package/dist/style.css +1 -1
  28. package/dist/vs-builder-edit-D-q1o8tF.js +604 -0
  29. package/dist/vs-builder-monaco-B3Jj0V31.js +33 -0
  30. package/dist/vs-builder-preview-BH4VAM3a.js +44 -0
  31. package/dist/vs-form-custom-datatable-BDZo48w3.js +317 -0
  32. package/dist/vs-form-integer-BZ855R3g.js +61 -0
  33. package/dist/vs-form-media-select-NY27EaG1.js +837 -0
  34. package/dist/vs-form-reference-list-Dtv8fJJU.js +1536 -0
  35. package/dist/vs-form-reletion-link-BhzNQszm.js +34 -0
  36. package/dist/vs-form-tiptap-DDFQjRjY.js +4 -0
  37. package/dist/vs-form-tiptap.vue_vue_type_script_setup_true_lang-DGgsqXwg.js +11 -0
  38. package/dist/vs-richtext-md-C098v_6Q.js +4 -0
  39. package/dist/vs-richtext-md.vue_vue_type_script_setup_true_lang-Ct8uTV-J.js +14 -0
  40. package/input-types.json +9 -9
  41. package/locales/en.json +815 -814
  42. package/locales/uk.json +813 -812
  43. package/module/cms/cls/content.status.json +17 -17
  44. package/module/cms/cls/user_type.json +9 -9
  45. package/module/cms/form/admin.users.form.json +77 -77
  46. package/module/cms/select/cms.page_type.sql +1 -1
  47. package/module/cms/select/news_tag_id.sql +11 -11
  48. package/module/cms/table/admin.users.table.json +53 -53
  49. package/module/cms/table/collection.default.table.json +96 -96
  50. package/module/cms/table/single.default.table.json +116 -116
  51. package/package.json +68 -68
  52. package/plugin.js +43 -43
  53. package/server/app.js +35 -35
  54. package/server/config.js +4 -4
  55. package/server/functions/getContent.js +45 -45
  56. package/server/functions/getDraftKey.js +22 -22
  57. package/server/functions/getSearchData.js +31 -31
  58. package/server/functions/getTags.js +30 -30
  59. package/server/functions/getUser.js +27 -27
  60. package/server/functions/utils/mock.reply.js +55 -55
  61. package/server/index.js +22 -22
  62. package/server/migrations/fixes.sql +129 -129
  63. package/server/migrations/site.sql +595 -595
  64. package/server/plugins/adminHook.js +78 -78
  65. package/server/plugins/hook.js +59 -59
  66. package/server/plugins/vite.js +75 -75
  67. package/server/routes/category/controllers/cms.category.delete.js +21 -21
  68. package/server/routes/category/controllers/cms.category.get.js +17 -17
  69. package/server/routes/category/controllers/cms.category.list.js +16 -16
  70. package/server/routes/category/controllers/cms.category.post.js +21 -21
  71. package/server/routes/category/controllers/cms.category.put.js +23 -23
  72. package/server/routes/category/index.mjs +22 -22
  73. package/server/routes/cms/controllers/cmsStat.js +55 -55
  74. package/server/routes/cms/controllers/cmsSuggest.js +57 -57
  75. package/server/routes/cms/controllers/deleteContent.js +113 -113
  76. package/server/routes/cms/controllers/deleteMedia.js +76 -76
  77. package/server/routes/cms/controllers/downloadMedia.js +84 -84
  78. package/server/routes/cms/controllers/getContent.js +113 -113
  79. package/server/routes/cms/controllers/getContentBySlug.js +93 -93
  80. package/server/routes/cms/controllers/insertContent.js +217 -217
  81. package/server/routes/cms/controllers/listMedia.js +155 -155
  82. package/server/routes/cms/controllers/metadataMedia.js +39 -39
  83. package/server/routes/cms/controllers/properties.get.js +18 -18
  84. package/server/routes/cms/controllers/properties.post.js +99 -99
  85. package/server/routes/cms/controllers/searchContent.js +214 -214
  86. package/server/routes/cms/controllers/translate.js +89 -89
  87. package/server/routes/cms/controllers/updateContent.js +266 -266
  88. package/server/routes/cms/controllers/uploadMedia.js +79 -79
  89. package/server/routes/cms/functions/getSettings.js +48 -48
  90. package/server/routes/cms/index.mjs +112 -112
  91. package/server/routes/cms/utils/additionalData.js +35 -35
  92. package/server/routes/cms/utils/getCollection.js +89 -89
  93. package/server/routes/cms/utils/getSingle.js +188 -188
  94. package/server/routes/cms/utils/inputTypes.js +5 -5
  95. package/server/routes/cms/utils/insertContentLocalization.js +104 -104
  96. package/server/routes/cms/utils/requestTranslation.js +85 -85
  97. package/server/routes/cms/utils/updateLocalization.js +47 -47
  98. package/server/routes/cmsSpace/controllers/deleteSpace.js +25 -25
  99. package/server/routes/cmsSpace/controllers/getSpaces.js +27 -27
  100. package/server/routes/cmsSpace/controllers/insertSpace.js +21 -21
  101. package/server/routes/cmsSpace/controllers/updateSpace.js +23 -23
  102. package/server/routes/cmsSpace/index.mjs +20 -20
  103. package/server/routes/contentType/controllers/addContentType.js +160 -160
  104. package/server/routes/contentType/controllers/contentTypeList.js +54 -54
  105. package/server/routes/contentType/controllers/delContentType.js +75 -75
  106. package/server/routes/contentType/controllers/editContentType.js +88 -88
  107. package/server/routes/contentType/controllers/getContentType.js +65 -65
  108. package/server/routes/contentType/index.mjs +35 -35
  109. package/server/routes/contentType/utils/updateContents.js +44 -44
  110. package/server/routes/contentType/utils/updateCustomContentTable.js +53 -53
  111. package/server/routes/feedback/controllers/email.list.js +24 -24
  112. package/server/routes/feedback/controllers/feedback.js +48 -48
  113. package/server/routes/feedback/controllers/feedback.list.js +37 -37
  114. package/server/routes/feedback/controllers/news.subscriptions.js +44 -44
  115. package/server/routes/feedback/index.mjs +71 -71
  116. package/server/routes/logs/controllers/export.user.logs.js +77 -77
  117. package/server/routes/logs/controllers/user.logs.js +44 -44
  118. package/server/routes/logs/index.mjs +9 -9
  119. package/server/routes/menu/controllers/addMenu.js +37 -37
  120. package/server/routes/menu/controllers/delMenu.js +31 -31
  121. package/server/routes/menu/controllers/editMenu.js +41 -41
  122. package/server/routes/menu/controllers/getMenu.js +24 -24
  123. package/server/routes/menu/functions/getMenu.js +50 -50
  124. package/server/routes/menu/index.mjs +13 -13
  125. package/server/routes/migration/controllers/collectionToCustom.js +137 -137
  126. package/server/routes/migration/index.mjs +8 -8
  127. package/server/routes/root.mjs +8 -8
  128. package/server/routes/tags/controllers/add.tags.js +24 -24
  129. package/server/routes/tags/controllers/del.tags.js +19 -19
  130. package/server/routes/tags/controllers/edit.tags.js +25 -25
  131. package/server/routes/tags/controllers/get.tags.js +15 -15
  132. package/server/routes/tags/index.mjs +14 -14
  133. package/server/templates/cls/cms.category_type.json +9 -9
  134. package/server/templates/cls/cms.content_review_status.json +9 -9
  135. package/server/templates/cls/cms.content_status.json +9 -9
  136. package/server/templates/cls/cms.content_type.json +9 -9
  137. package/server/templates/cls/cms.lang.json +9 -9
  138. package/server/templates/page/login.html +126 -126
  139. package/utils.d.ts +52 -52
  140. package/utils.js +8 -8
  141. package/dist/ArticlesPage-BcR1hbds.js +0 -286
  142. package/dist/BuilderPage-CK_osM89.js +0 -386
  143. package/dist/CollectionsBreadcrumb.vue_vue_type_script_setup_true_lang-CnOe9ORD.js +0 -45
  144. package/dist/CollectionsPage-JfmrHNR_.js +0 -110
  145. package/dist/EditCollectionPage-Cw3GQYRe.js +0 -809
  146. package/dist/MenuItemPage-CXn5HC8j.js +0 -1366
  147. package/dist/MenuPage-tJZtK46W.js +0 -106
  148. package/dist/contentForm-B6gHgGkz.js +0 -586
  149. package/dist/getField-Y5WXnRR0.js +0 -2948
@@ -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 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 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
  };
@@ -1,26 +1,26 @@
1
- import { dataUpdate } from "@opengis/fastify-table/utils.js";
2
-
3
- export default async function editTags({ pg, body, user, params }, reply) {
4
- const { uid } = user || {};
5
-
6
- if (!uid) {
7
- return reply.code(401).send({ message: 'access restricted', status: 401 });
8
- }
9
-
10
- if (!params?.id) {
11
- return reply.code(400).send({ message: 'id is required!', status: 400 });
12
- }
13
- if (!body) {
14
- return reply.code(400).send({ message: 'body is empty!', status: 400 });
15
- }
16
-
17
- await dataUpdate({
18
- pg,
19
- id: params.id,
20
- table: 'site.tags',
21
- data: body,
22
- uid,
23
- });
24
-
25
- return reply.code(200).send({ message: 'Tag updated successfully', status: 200 });
1
+ import { dataUpdate } from "@opengis/fastify-table/utils.js";
2
+
3
+ export default async function editTags({ pg, body, user, params }, reply) {
4
+ const { uid } = user || {};
5
+
6
+ if (!uid) {
7
+ return reply.code(401).send({ message: 'access restricted', status: 401 });
8
+ }
9
+
10
+ if (!params?.id) {
11
+ return reply.code(400).send({ message: 'id is required!', status: 400 });
12
+ }
13
+ if (!body) {
14
+ return reply.code(400).send({ message: 'body is empty!', status: 400 });
15
+ }
16
+
17
+ await dataUpdate({
18
+ pg,
19
+ id: params.id,
20
+ table: 'site.tags',
21
+ data: body,
22
+ uid,
23
+ });
24
+
25
+ return reply.code(200).send({ message: 'Tag updated successfully', status: 200 });
26
26
  }
@@ -1,16 +1,16 @@
1
- export default async function getTags(req, reply) {
2
- const { pg, query } = req;
3
- const { page = 1, limit = 16, search } = query;
4
- const offset = limit * (page - 1) || 0;
5
-
6
- const { total, filtered } = await pg.one(`select count(*)::int as total, (count(*) filter (where 1=1 ${search ? `and value ilike'%${search}%'` : ''}))::int as filtered from site.tags`);
7
-
8
- const selectSql = `select *,(select count(*)::int as count_data from site.tag_data where tag_id=a.tag_id) from site.tags a
9
- where 1=1 ${search ? `and value ilike'%${search}%'` : ''}
10
- order by created_at desc limit ${limit} offset ${offset}`;
11
-
12
- const { rows } = await pg.query(selectSql);
13
-
14
- return reply.status(200).send({ message: { total, filtered, rows }, status: 200 })
15
-
1
+ export default async function getTags(req, reply) {
2
+ const { pg, query } = req;
3
+ const { page = 1, limit = 16, search } = query;
4
+ const offset = limit * (page - 1) || 0;
5
+
6
+ const { total, filtered } = await pg.one(`select count(*)::int as total, (count(*) filter (where 1=1 ${search ? `and value ilike'%${search}%'` : ''}))::int as filtered from site.tags`);
7
+
8
+ const selectSql = `select *,(select count(*)::int as count_data from site.tag_data where tag_id=a.tag_id) from site.tags a
9
+ where 1=1 ${search ? `and value ilike'%${search}%'` : ''}
10
+ order by created_at desc limit ${limit} offset ${offset}`;
11
+
12
+ const { rows } = await pg.query(selectSql);
13
+
14
+ return reply.status(200).send({ message: { total, filtered, rows }, status: 200 })
15
+
16
16
  }
@@ -1,14 +1,14 @@
1
- import getTags from './controllers/get.tags.js';
2
- import addTags from './controllers/add.tags.js';
3
- import editTags from './controllers/edit.tags.js';
4
- import delTags from './controllers/del.tags.js';
5
-
6
- const policyPublic = { config: { policy: ['public'] } };
7
-
8
- export default async function route(app) {
9
- app.get('/tags', policyPublic, getTags);
10
- app.post('/tags', policyPublic, addTags);
11
- app.put('/tags/:id', policyPublic, editTags);
12
- app.delete('/tags/:id', policyPublic, delTags);
13
-
14
- }
1
+ import getTags from './controllers/get.tags.js';
2
+ import addTags from './controllers/add.tags.js';
3
+ import editTags from './controllers/edit.tags.js';
4
+ import delTags from './controllers/del.tags.js';
5
+
6
+ const policyPublic = { config: { policy: ['public'] } };
7
+
8
+ export default async function route(app) {
9
+ app.get('/tags', policyPublic, getTags);
10
+ app.post('/tags', policyPublic, addTags);
11
+ app.put('/tags/:id', policyPublic, editTags);
12
+ app.delete('/tags/:id', policyPublic, delTags);
13
+
14
+ }
@@ -1,10 +1,10 @@
1
- [
2
- {
3
- "id": "1",
4
- "text": "Important"
5
- },
6
- {
7
- "id": "2",
8
- "text": "Common"
9
- }
1
+ [
2
+ {
3
+ "id": "1",
4
+ "text": "Important"
5
+ },
6
+ {
7
+ "id": "2",
8
+ "text": "Common"
9
+ }
10
10
  ]
@@ -1,10 +1,10 @@
1
- [
2
- {
3
- "id": "1",
4
- "text": "Pending"
5
- },
6
- {
7
- "id": "2",
8
- "text": "Approved"
9
- }
1
+ [
2
+ {
3
+ "id": "1",
4
+ "text": "Pending"
5
+ },
6
+ {
7
+ "id": "2",
8
+ "text": "Approved"
9
+ }
10
10
  ]
@@ -1,10 +1,10 @@
1
- [
2
- {
3
- "id": "1",
4
- "text": "Draft"
5
- },
6
- {
7
- "id": "2",
8
- "text": "Publish"
9
- }
1
+ [
2
+ {
3
+ "id": "1",
4
+ "text": "Draft"
5
+ },
6
+ {
7
+ "id": "2",
8
+ "text": "Publish"
9
+ }
10
10
  ]
@@ -1,10 +1,10 @@
1
- [
2
- {
3
- "id": "1",
4
- "text": "Single"
5
- },
6
- {
7
- "id": "2",
8
- "text": "Collection"
9
- }
1
+ [
2
+ {
3
+ "id": "1",
4
+ "text": "Single"
5
+ },
6
+ {
7
+ "id": "2",
8
+ "text": "Collection"
9
+ }
10
10
  ]
@@ -1,10 +1,10 @@
1
- [
2
- {
3
- "id": "uk",
4
- "text": "Українська"
5
- },
6
- {
7
- "id": "en",
8
- "text": "English"
9
- }
1
+ [
2
+ {
3
+ "id": "uk",
4
+ "text": "Українська"
5
+ },
6
+ {
7
+ "id": "en",
8
+ "text": "English"
9
+ }
10
10
  ]