@opengis/cms 0.0.61 → 0.0.62

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 (109) hide show
  1. package/README.md +131 -131
  2. package/dist/{EditCollectionPage-3Q57ptN3.js → EditCollectionPage-C4uNmBJf.js} +1 -1
  3. package/dist/{contentForm-CLStrfSg.js → contentForm-CcFbUeal.js} +144 -146
  4. package/dist/index.js +1 -1
  5. package/dist/{vs-builder-preview-BH4VAM3a.js → vs-builder-preview-DL3RYMp7.js} +11 -12
  6. package/dist/vs-form-custom-datatable-D880w8gx.js +493 -0
  7. package/input-types.json +9 -9
  8. package/locales/en.json +815 -815
  9. package/locales/uk.json +813 -813
  10. package/module/cms/cls/content.status.json +17 -17
  11. package/module/cms/cls/user_type.json +9 -9
  12. package/module/cms/form/admin.users.form.json +77 -77
  13. package/module/cms/select/cms.page_type.sql +1 -1
  14. package/module/cms/select/news_tag_id.sql +11 -11
  15. package/module/cms/table/admin.users.table.json +53 -53
  16. package/module/cms/table/collection.default.table.json +96 -96
  17. package/module/cms/table/single.default.table.json +116 -116
  18. package/package.json +69 -69
  19. package/plugin.js +43 -43
  20. package/server/app.js +35 -35
  21. package/server/config.js +4 -4
  22. package/server/functions/getContent.js +45 -45
  23. package/server/functions/getDraftKey.js +22 -22
  24. package/server/functions/getSearchData.js +31 -31
  25. package/server/functions/getTags.js +30 -30
  26. package/server/functions/getUser.js +27 -27
  27. package/server/functions/utils/mock.reply.js +55 -55
  28. package/server/index.js +22 -22
  29. package/server/migrations/fixes.sql +132 -132
  30. package/server/migrations/site.sql +596 -596
  31. package/server/plugins/adminHook.js +78 -78
  32. package/server/plugins/hook.js +59 -59
  33. package/server/plugins/vite.js +75 -75
  34. package/server/routes/category/controllers/cms.category.delete.js +21 -21
  35. package/server/routes/category/controllers/cms.category.get.js +17 -17
  36. package/server/routes/category/controllers/cms.category.list.js +16 -16
  37. package/server/routes/category/controllers/cms.category.post.js +21 -21
  38. package/server/routes/category/controllers/cms.category.put.js +23 -23
  39. package/server/routes/category/index.mjs +22 -22
  40. package/server/routes/cms/controllers/cmsStat.js +55 -55
  41. package/server/routes/cms/controllers/cmsSuggest.js +57 -57
  42. package/server/routes/cms/controllers/deleteContent.js +113 -113
  43. package/server/routes/cms/controllers/deleteMedia.js +76 -76
  44. package/server/routes/cms/controllers/downloadMedia.js +84 -84
  45. package/server/routes/cms/controllers/getContent.js +113 -113
  46. package/server/routes/cms/controllers/getContentBySlug.js +93 -93
  47. package/server/routes/cms/controllers/insertContent.js +226 -226
  48. package/server/routes/cms/controllers/listMedia.js +155 -155
  49. package/server/routes/cms/controllers/metadataMedia.js +39 -39
  50. package/server/routes/cms/controllers/properties.get.js +18 -18
  51. package/server/routes/cms/controllers/properties.post.js +99 -99
  52. package/server/routes/cms/controllers/searchContent.js +214 -214
  53. package/server/routes/cms/controllers/translate.js +89 -89
  54. package/server/routes/cms/controllers/updateContent.js +231 -231
  55. package/server/routes/cms/controllers/uploadMedia.js +79 -79
  56. package/server/routes/cms/functions/getSettings.js +48 -48
  57. package/server/routes/cms/index.mjs +112 -112
  58. package/server/routes/cms/utils/additionalData.js +35 -35
  59. package/server/routes/cms/utils/getCollection.js +89 -89
  60. package/server/routes/cms/utils/getSingle.js +188 -188
  61. package/server/routes/cms/utils/inputTypes.js +5 -5
  62. package/server/routes/cms/utils/insertContentLocalization.js +104 -104
  63. package/server/routes/cms/utils/requestTranslation.js +135 -135
  64. package/server/routes/cms/utils/updateLocalization.js +42 -42
  65. package/server/routes/cmsSpace/controllers/deleteSpace.js +26 -26
  66. package/server/routes/cmsSpace/controllers/getSpaces.js +28 -28
  67. package/server/routes/cmsSpace/controllers/insertSpace.js +22 -22
  68. package/server/routes/cmsSpace/controllers/updateSpace.js +24 -24
  69. package/server/routes/cmsSpace/index.mjs +20 -20
  70. package/server/routes/contentType/controllers/addContentType.js +160 -160
  71. package/server/routes/contentType/controllers/contentTypeList.js +47 -47
  72. package/server/routes/contentType/controllers/delContentType.js +75 -75
  73. package/server/routes/contentType/controllers/editContentType.js +70 -70
  74. package/server/routes/contentType/controllers/getContentType.js +57 -57
  75. package/server/routes/contentType/index.mjs +35 -35
  76. package/server/routes/contentType/utils/updateContents.js +44 -44
  77. package/server/routes/contentType/utils/updateCustomContentTable.js +53 -53
  78. package/server/routes/feedback/controllers/email.list.js +24 -24
  79. package/server/routes/feedback/controllers/feedback.js +48 -48
  80. package/server/routes/feedback/controllers/feedback.list.js +37 -37
  81. package/server/routes/feedback/controllers/news.subscriptions.js +44 -44
  82. package/server/routes/feedback/index.mjs +71 -71
  83. package/server/routes/logs/controllers/export.user.logs.js +77 -77
  84. package/server/routes/logs/controllers/user.logs.js +44 -44
  85. package/server/routes/logs/index.mjs +9 -9
  86. package/server/routes/menu/controllers/addMenu.js +37 -37
  87. package/server/routes/menu/controllers/delMenu.js +31 -31
  88. package/server/routes/menu/controllers/editMenu.js +41 -41
  89. package/server/routes/menu/controllers/getMenu.js +24 -24
  90. package/server/routes/menu/functions/getMenu.js +50 -50
  91. package/server/routes/menu/index.mjs +13 -13
  92. package/server/routes/migration/controllers/collectionToCustom.js +137 -137
  93. package/server/routes/migration/index.mjs +8 -8
  94. package/server/routes/root.mjs +8 -8
  95. package/server/routes/tags/controllers/add.tags.js +24 -24
  96. package/server/routes/tags/controllers/del.tags.js +19 -19
  97. package/server/routes/tags/controllers/edit.tags.js +25 -25
  98. package/server/routes/tags/controllers/get.tags.js +15 -15
  99. package/server/routes/tags/index.mjs +14 -14
  100. package/server/templates/cls/cms.category_type.json +9 -9
  101. package/server/templates/cls/cms.content_review_status.json +9 -9
  102. package/server/templates/cls/cms.content_status.json +9 -9
  103. package/server/templates/cls/cms.content_type.json +9 -9
  104. package/server/templates/cls/cms.lang.json +9 -9
  105. package/server/templates/page/login.html +126 -126
  106. package/utils.d.ts +52 -52
  107. package/utils.js +8 -8
  108. package/dist/getField-CpwVE28P.js +0 -179
  109. package/dist/vs-form-custom-datatable-BDZo48w3.js +0 -317
@@ -1,70 +1,70 @@
1
- import { dataInsert, dataUpdate, pgClients, getTemplate } from '@opengis/fastify-table/utils.js';
2
-
3
- import updateCustomContentTable from '../utils/updateCustomContentTable.js';
4
- import updateContents from '../utils/updateContents.js';
5
-
6
- export default async function builderPut(req, reply) {
7
- const { pg = pgClients.client, body = {}, params = {}, user = {} } = req;
8
- if (!params.id) {
9
- return reply.status(400).send('not enough params: id');
10
- }
11
-
12
- if (!pg?.pk?.['site.content_types']) {
13
- return reply.status(404).send('table not found');
14
- }
15
-
16
- const single = await pg.query(
17
- `select content_id as id, content_type_id, slug FROM site.contents
18
- where $1 in (content_id, content_type_id, slug)`, [params.id]
19
- ).then(el => el.rows?.[0]);
20
-
21
- const { cid, table } = await pg.query(
22
- `select content_type_id as cid, table_name as table, type from site.content_types where $1 in (content_type_id, name)`,
23
- [params.id],
24
- ).then(el => el.rows?.[0] || {});
25
-
26
- if (!cid && !single) {
27
- return reply.status(404).send('content type not found');
28
- }
29
-
30
- const columns = (body.fields || body.columns)?.filter?.(el => el.name)?.map?.(el => Object.assign(el, { name: el.name.toLowerCase() })); // for rest crud
31
-
32
- const client = await pg.connect();
33
-
34
- client.options = pg.options;
35
- client.tlist = pg.tlist;
36
- client.pgType = pg.pgType;
37
- client.relkinds = pg.relkinds;
38
- client.pk = pg.pk;
39
-
40
- try {
41
- await client.query('begin');
42
-
43
- const cid1 = cid || single?.content_type_id;
44
-
45
- if (table) {
46
- await updateCustomContentTable({ pg: client, id: cid1, columns });
47
- }
48
-
49
- const name = body.name === 'pages' ? (single?.slug || params.id) : (body.name || body.slug);
50
-
51
- await dataUpdate({
52
- pg: client,
53
- table: 'site.content_types',
54
- id: cid1,
55
- data: { ...body, content_type_id: cid1, name },
56
- uid: user?.uid,
57
- });
58
-
59
- const row = await updateContents(client, cid1, { ...body, slug: name }, user?.uid);
60
-
61
- await client.query('commit');
62
-
63
- return { id: row?.content_type_id, rows: [row].filter(Boolean) };
64
- } catch (err) {
65
- await client.query('rollback');
66
- throw err;
67
- } finally {
68
- client.release();
69
- }
70
- }
1
+ import { dataInsert, dataUpdate, pgClients, getTemplate } from '@opengis/fastify-table/utils.js';
2
+
3
+ import updateCustomContentTable from '../utils/updateCustomContentTable.js';
4
+ import updateContents from '../utils/updateContents.js';
5
+
6
+ export default async function builderPut(req, reply) {
7
+ const { pg = pgClients.client, body = {}, params = {}, user = {} } = req;
8
+ if (!params.id) {
9
+ return reply.status(400).send('not enough params: id');
10
+ }
11
+
12
+ if (!pg?.pk?.['site.content_types']) {
13
+ return reply.status(404).send('table not found');
14
+ }
15
+
16
+ const single = await pg.query(
17
+ `select content_id as id, content_type_id, slug FROM site.contents
18
+ where $1 in (content_id, content_type_id, slug)`, [params.id]
19
+ ).then(el => el.rows?.[0]);
20
+
21
+ const { cid, table } = await pg.query(
22
+ `select content_type_id as cid, table_name as table, type from site.content_types where $1 in (content_type_id, name)`,
23
+ [params.id],
24
+ ).then(el => el.rows?.[0] || {});
25
+
26
+ if (!cid && !single) {
27
+ return reply.status(404).send('content type not found');
28
+ }
29
+
30
+ const columns = (body.fields || body.columns)?.filter?.(el => el.name)?.map?.(el => Object.assign(el, { name: el.name.toLowerCase() })); // for rest crud
31
+
32
+ const client = await pg.connect();
33
+
34
+ client.options = pg.options;
35
+ client.tlist = pg.tlist;
36
+ client.pgType = pg.pgType;
37
+ client.relkinds = pg.relkinds;
38
+ client.pk = pg.pk;
39
+
40
+ try {
41
+ await client.query('begin');
42
+
43
+ const cid1 = cid || single?.content_type_id;
44
+
45
+ if (table) {
46
+ await updateCustomContentTable({ pg: client, id: cid1, columns });
47
+ }
48
+
49
+ const name = body.name === 'pages' ? (single?.slug || params.id) : (body.name || body.slug);
50
+
51
+ await dataUpdate({
52
+ pg: client,
53
+ table: 'site.content_types',
54
+ id: cid1,
55
+ data: { ...body, content_type_id: cid1, name },
56
+ uid: user?.uid,
57
+ });
58
+
59
+ const row = await updateContents(client, cid1, { ...body, slug: name }, user?.uid);
60
+
61
+ await client.query('commit');
62
+
63
+ return { id: row?.content_type_id, rows: [row].filter(Boolean) };
64
+ } catch (err) {
65
+ await client.query('rollback');
66
+ throw err;
67
+ } finally {
68
+ client.release();
69
+ }
70
+ }
@@ -1,57 +1,57 @@
1
- import { pgClients, getTemplate } from '@opengis/fastify-table/utils.js';
2
-
3
- export default async function builderGet({ pg = pgClients.client, params = {} }, reply) {
4
- if (!params.id) {
5
- return reply.status(400).send({ error: 'not enough params: id', code: 400 });
6
- }
7
-
8
- if (!pg?.pk?.['site.content_types']) {
9
- return reply.status(404).send({ error: 'table not found', code: 404 });
10
- }
11
-
12
- const single = await pg.query(
13
- `select content_id as id, * FROM site.contents
14
- where $1 in (content_id, content_type_id, slug)`, [params.id]
15
- ).then(el => el.rows?.[0]);
16
-
17
- // new ? 1 : 2
18
- const isNew = single && single.content_type_id === params.id;
19
- const row = isNew
20
- ? await pg.query(
21
- `select content_type_id as id, * FROM site.content_types
22
- where $1 in (content_type_id, name)`, [params.id]
23
- ).then(el => el.rows?.[0])
24
- : await pg.query(`SELECT content_type_id as id, * FROM site.content_types WHERE content_type_id in (select content_type_id from site.contents where content_id=$1) limit 1`, [params.id]).then(el => el.rows?.[0]);
25
-
26
- if (!isNew && single.content_type_id === 'pages') {
27
- Object.assign(row, { id: params.id, type: 'single', title: single.title || params.id, content_type_id: params.id, name: single.slug || params.id });
28
- }
29
-
30
- if (single && !row) {
31
- const loadTable = await getTemplate('table', 'single.default.table');
32
- const { columns: defaultColumns } = loadTable || {};
33
- (defaultColumns || []).forEach(col => Object.assign(col, { defaultColumn: true }));
34
- const columns = (defaultColumns || []).filter(col => !col.hidden);
35
- return reply.status(200).send({ default: true, id: single.id, name: single.slug, type: 'single', ...single, columns });
36
- }
37
-
38
- if (!row) {
39
- return reply.status(404).send({ error: 'content type not found', code: 404 });
40
- }
41
-
42
- const loadTable = params.id === 'pages'
43
- ? await getTemplate('table', 'single.default.table')
44
- : await getTemplate('table', 'collection.default.table');
45
- const { columns: defaultColumns = [] } = loadTable || {};
46
- defaultColumns.forEach(col => Object.assign(col, { defaultColumn: true }));
47
- const columns = (defaultColumns || []).concat((row.columns || []).filter(col => !defaultColumns.map(el => el.name).includes(col.name)));
48
-
49
- Object.assign(row, { columns });
50
-
51
- // filter system / hidden
52
- if (Array.isArray(row.columns)) {
53
- row.columns.filter(col => !col.hidden);
54
- }
55
-
56
- return reply.status(200).send(row);
57
- }
1
+ import { pgClients, getTemplate } from '@opengis/fastify-table/utils.js';
2
+
3
+ export default async function builderGet({ pg = pgClients.client, params = {} }, reply) {
4
+ if (!params.id) {
5
+ return reply.status(400).send({ error: 'not enough params: id', code: 400 });
6
+ }
7
+
8
+ if (!pg?.pk?.['site.content_types']) {
9
+ return reply.status(404).send({ error: 'table not found', code: 404 });
10
+ }
11
+
12
+ const single = await pg.query(
13
+ `select content_id as id, * FROM site.contents
14
+ where $1 in (content_id, content_type_id, slug)`, [params.id]
15
+ ).then(el => el.rows?.[0]);
16
+
17
+ // new ? 1 : 2
18
+ const isNew = single && single.content_type_id === params.id;
19
+ const row = isNew
20
+ ? await pg.query(
21
+ `select content_type_id as id, * FROM site.content_types
22
+ where $1 in (content_type_id, name)`, [params.id]
23
+ ).then(el => el.rows?.[0])
24
+ : await pg.query(`SELECT content_type_id as id, * FROM site.content_types WHERE content_type_id in (select content_type_id from site.contents where content_id=$1) limit 1`, [params.id]).then(el => el.rows?.[0]);
25
+
26
+ if (!isNew && single.content_type_id === 'pages') {
27
+ Object.assign(row, { id: params.id, type: 'single', title: single.title || params.id, content_type_id: params.id, name: single.slug || params.id });
28
+ }
29
+
30
+ if (single && !row) {
31
+ const loadTable = await getTemplate('table', 'single.default.table');
32
+ const { columns: defaultColumns } = loadTable || {};
33
+ (defaultColumns || []).forEach(col => Object.assign(col, { defaultColumn: true }));
34
+ const columns = (defaultColumns || []).filter(col => !col.hidden);
35
+ return reply.status(200).send({ default: true, id: single.id, name: single.slug, type: 'single', ...single, columns });
36
+ }
37
+
38
+ if (!row) {
39
+ return reply.status(404).send({ error: 'content type not found', code: 404 });
40
+ }
41
+
42
+ const loadTable = params.id === 'pages'
43
+ ? await getTemplate('table', 'single.default.table')
44
+ : await getTemplate('table', 'collection.default.table');
45
+ const { columns: defaultColumns = [] } = loadTable || {};
46
+ defaultColumns.forEach(col => Object.assign(col, { defaultColumn: true }));
47
+ const columns = (defaultColumns || []).concat((row.columns || []).filter(col => !defaultColumns.map(el => el.name).includes(col.name)));
48
+
49
+ Object.assign(row, { columns });
50
+
51
+ // filter system / hidden
52
+ if (Array.isArray(row.columns)) {
53
+ row.columns.filter(col => !col.hidden);
54
+ }
55
+
56
+ return reply.status(200).send(row);
57
+ }
@@ -1,35 +1,35 @@
1
- import getContentType from './controllers/getContentType.js';
2
- import contentTypeList from './controllers/contentTypeList.js';
3
- import editContentType from './controllers/editContentType.js';
4
- import addContentType from './controllers/addContentType.js';
5
- import delContentType from './controllers/delContentType.js';
6
-
7
- const params = { config: { policy: ['public'] } };
8
-
9
- export default async function route(app) {
10
- const schema = {
11
- params: {
12
- type: 'object',
13
- properties: {
14
- id: {
15
- type: 'string'
16
- },
17
- },
18
- },
19
- body: {
20
- type: 'object',
21
- required: ['name'],
22
- properties: {
23
- name: { type: 'string' }
24
- }
25
- }
26
- };
27
-
28
- app.get('/cms', params, contentTypeList);
29
- app.get('/cms-type', params, contentTypeList);
30
-
31
- app.post('/cms-type', { ...params, schema }, addContentType);
32
- app.put('/cms-type/:id', { ...params, schema }, editContentType);
33
- app.get('/cms-type/:id', params, getContentType);
34
- app.delete('/cms-type/:id', params, delContentType);
35
- }
1
+ import getContentType from './controllers/getContentType.js';
2
+ import contentTypeList from './controllers/contentTypeList.js';
3
+ import editContentType from './controllers/editContentType.js';
4
+ import addContentType from './controllers/addContentType.js';
5
+ import delContentType from './controllers/delContentType.js';
6
+
7
+ const params = { config: { policy: ['public'] } };
8
+
9
+ export default async function route(app) {
10
+ const schema = {
11
+ params: {
12
+ type: 'object',
13
+ properties: {
14
+ id: {
15
+ type: 'string'
16
+ },
17
+ },
18
+ },
19
+ body: {
20
+ type: 'object',
21
+ required: ['name'],
22
+ properties: {
23
+ name: { type: 'string' }
24
+ }
25
+ }
26
+ };
27
+
28
+ app.get('/cms', params, contentTypeList);
29
+ app.get('/cms-type', params, contentTypeList);
30
+
31
+ app.post('/cms-type', { ...params, schema }, addContentType);
32
+ app.put('/cms-type/:id', { ...params, schema }, editContentType);
33
+ app.get('/cms-type/:id', params, getContentType);
34
+ app.delete('/cms-type/:id', params, delContentType);
35
+ }
@@ -1,45 +1,45 @@
1
- import { dataInsert, dataUpdate } from "@opengis/fastify-table/utils.js";
2
-
3
- export default async function updateContents(pg, id, data, uid) {
4
- if (!pg?.pk || !id) return null;
5
-
6
- const single = await pg.query(
7
- `select 1 from site.contents where content_id=$1`,
8
- [id],
9
- ).then(el => el.rowCount || 0);
10
-
11
- if (single) {
12
- const result = await dataUpdate({
13
- pg,
14
- table: 'site.contents',
15
- id,
16
- data,
17
- uid,
18
- });
19
- return result;
20
- }
21
-
22
- const contentId = await pg.query(
23
- `select content_id from site.contents where content_type_id = $1 order by content_id=content_type_id desc limit 1`, // update pages collection, avoid singles
24
- [id],
25
- ).then(el => el.rows?.[0]?.content_id);
26
-
27
- if (contentId) {
28
- const result = await dataUpdate({
29
- pg,
30
- id: data?.type === 'single' ? id : contentId,
31
- table: 'site.contents',
32
- data,
33
- uid,
34
- });
35
- return result;
36
- }
37
-
38
- const result = await dataInsert({
39
- pg,
40
- table: 'site.contents',
41
- data: { ...data || {}, content_type_id: id },
42
- uid,
43
- }).then(el => el.rows?.[0]);
44
- return result;
1
+ import { dataInsert, dataUpdate } from "@opengis/fastify-table/utils.js";
2
+
3
+ export default async function updateContents(pg, id, data, uid) {
4
+ if (!pg?.pk || !id) return null;
5
+
6
+ const single = await pg.query(
7
+ `select 1 from site.contents where content_id=$1`,
8
+ [id],
9
+ ).then(el => el.rowCount || 0);
10
+
11
+ if (single) {
12
+ const result = await dataUpdate({
13
+ pg,
14
+ table: 'site.contents',
15
+ id,
16
+ data,
17
+ uid,
18
+ });
19
+ return result;
20
+ }
21
+
22
+ const contentId = await pg.query(
23
+ `select content_id from site.contents where content_type_id = $1 order by content_id=content_type_id desc limit 1`, // update pages collection, avoid singles
24
+ [id],
25
+ ).then(el => el.rows?.[0]?.content_id);
26
+
27
+ if (contentId) {
28
+ const result = await dataUpdate({
29
+ pg,
30
+ id: data?.type === 'single' ? id : contentId,
31
+ table: 'site.contents',
32
+ data,
33
+ uid,
34
+ });
35
+ return result;
36
+ }
37
+
38
+ const result = await dataInsert({
39
+ pg,
40
+ table: 'site.contents',
41
+ data: { ...data || {}, content_type_id: id },
42
+ uid,
43
+ }).then(el => el.rows?.[0]);
44
+ return result;
45
45
  }
@@ -1,54 +1,54 @@
1
- import { getMeta } from '@opengis/fastify-table/utils.js';
2
-
3
- import inputTypes from '../../cms/utils/inputTypes.js';
4
-
5
- const types = {
6
- number: 'numeric',
7
- datetime: 'timestamp without time zone',
8
- boolean: 'boolean',
9
- date: 'date',
10
- array: 'text[]',
11
- FileList: 'text[]',
12
- };
13
-
14
- export default async function updateCustomContentTable({ pg, id, columns = [] }) {
15
- if (!pg?.pk || !id) return null;
16
-
17
- const { table_name: tablename, dbcolumns } = await pg.query(
18
- `select table_name, columns as dbcolumns from site.content_types where content_type_id = $1`,
19
- [id],
20
- ).then(el => el.rows?.[0] || {});
21
-
22
- if (!tablename) return null;
23
-
24
- const droppedColumns = (dbcolumns || []).filter(el => columns.findIndex(col => col.name === el.name) === -1);
25
- // console.log(droppedColumns);
26
-
27
- const q = `create table if not exists data."${tablename}"
28
- ( id text not null default next_id() PRIMARY KEY );
29
- ${droppedColumns.map(col => `
30
- alter table data."${tablename}" add column if not exists "${col.name}" text;
31
- alter table data."${tablename}" alter column "${col.name}" drop not null;`).join('\n')}
32
- ${columns?.filter?.(col => col.name)?.map?.(col => `
33
- alter table data."${tablename}" add column if not exists "${col.name}" ${types[col.type] || inputTypes[col.type] || 'text'} ${col.required ? ' not null ' : ''};
34
- alter table data."${tablename}" alter column "${col.name}" ${col.required ? ' set ' : ' drop '} not null;
35
- alter table data."${tablename}" alter column "${col.name}" set default ${col.default ? col.default : 'null'};
36
- comment on column data."${tablename}"."${col.name}" is ${col.label ? `'${col.label.replace(/'/g, "''")}'` : 'null'} `
37
- ).join(';') || ''}`;
38
- await pg.query(q);
39
- await pg.query(`alter table data."${tablename}" add column if not exists created_at timestamp with time zone not null default now()`);
40
- await pg.query(`alter table data."${tablename}" add column if not exists updated_at timestamp with time zone not null default now()`);
41
- await pg.query(`alter table data."${tablename}" add column if not exists created_by text`);
42
- await pg.query(`alter table data."${tablename}" add column if not exists updated_by text`);
43
- await pg.query(`alter table data."${tablename}" drop constraint if exists c${id}_slug_unique;alter table data."${tablename}" add constraint c${id}_slug_unique UNIQUE (slug);`);
44
-
45
- // force meta columns refresh to avoid crud skips
46
- await getMeta({ pg, table: `data.${tablename}` }, true);
47
-
48
- // if (pg?.pk && pg.tlist && !pg.tlist.find(el => el === `data.${tablename}`)) {
49
- // pg.pk[`data.${tablename}`] = 'id';
50
- // pg.tlist?.push?.(`data.${tablename}`);
51
- // }
52
-
53
- return null;
1
+ import { getMeta } from '@opengis/fastify-table/utils.js';
2
+
3
+ import inputTypes from '../../cms/utils/inputTypes.js';
4
+
5
+ const types = {
6
+ number: 'numeric',
7
+ datetime: 'timestamp without time zone',
8
+ boolean: 'boolean',
9
+ date: 'date',
10
+ array: 'text[]',
11
+ FileList: 'text[]',
12
+ };
13
+
14
+ export default async function updateCustomContentTable({ pg, id, columns = [] }) {
15
+ if (!pg?.pk || !id) return null;
16
+
17
+ const { table_name: tablename, dbcolumns } = await pg.query(
18
+ `select table_name, columns as dbcolumns from site.content_types where content_type_id = $1`,
19
+ [id],
20
+ ).then(el => el.rows?.[0] || {});
21
+
22
+ if (!tablename) return null;
23
+
24
+ const droppedColumns = (dbcolumns || []).filter(el => columns.findIndex(col => col.name === el.name) === -1);
25
+ // console.log(droppedColumns);
26
+
27
+ const q = `create table if not exists data."${tablename}"
28
+ ( id text not null default next_id() PRIMARY KEY );
29
+ ${droppedColumns.map(col => `
30
+ alter table data."${tablename}" add column if not exists "${col.name}" text;
31
+ alter table data."${tablename}" alter column "${col.name}" drop not null;`).join('\n')}
32
+ ${columns?.filter?.(col => col.name)?.map?.(col => `
33
+ alter table data."${tablename}" add column if not exists "${col.name}" ${types[col.type] || inputTypes[col.type] || 'text'} ${col.required ? ' not null ' : ''};
34
+ alter table data."${tablename}" alter column "${col.name}" ${col.required ? ' set ' : ' drop '} not null;
35
+ alter table data."${tablename}" alter column "${col.name}" set default ${col.default ? col.default : 'null'};
36
+ comment on column data."${tablename}"."${col.name}" is ${col.label ? `'${col.label.replace(/'/g, "''")}'` : 'null'} `
37
+ ).join(';') || ''}`;
38
+ await pg.query(q);
39
+ await pg.query(`alter table data."${tablename}" add column if not exists created_at timestamp with time zone not null default now()`);
40
+ await pg.query(`alter table data."${tablename}" add column if not exists updated_at timestamp with time zone not null default now()`);
41
+ await pg.query(`alter table data."${tablename}" add column if not exists created_by text`);
42
+ await pg.query(`alter table data."${tablename}" add column if not exists updated_by text`);
43
+ await pg.query(`alter table data."${tablename}" drop constraint if exists c${id}_slug_unique;alter table data."${tablename}" add constraint c${id}_slug_unique UNIQUE (slug);`);
44
+
45
+ // force meta columns refresh to avoid crud skips
46
+ await getMeta({ pg, table: `data.${tablename}` }, true);
47
+
48
+ // if (pg?.pk && pg.tlist && !pg.tlist.find(el => el === `data.${tablename}`)) {
49
+ // pg.pk[`data.${tablename}`] = 'id';
50
+ // pg.tlist?.push?.(`data.${tablename}`);
51
+ // }
52
+
53
+ return null;
54
54
  }
@@ -1,25 +1,25 @@
1
- export default async function feedbackList(req, reply) {
2
- const { pg, user = {}, query } = req;
3
- const { uid } = user;
4
- if (!uid) return reply.code(401).send({ message: 'Not authorized', status: 401 });
5
-
6
- const { page = 1, limit = 16 } = query;
7
- const offset = limit * (page - 1) || 0;
8
-
9
- const { total, filtered } = await pg.one(`select count(*)::int as total from site.feedback`)
10
-
11
- const { rows = [] } = await pg.query(`
12
- select
13
- row_number() over(order by created_at desc) as num,
14
- subscription_id,
15
- email,
16
- created_at,
17
- enabled
18
- from site.subscription
19
- order by created_at desc
20
- limit ${limit} offset ${offset}
21
- `);
22
-
23
- const status = rows?.length ? 200 : 204;
24
- return reply.code(status).send({ message: { total, filtered, rows }, status })
1
+ export default async function feedbackList(req, reply) {
2
+ const { pg, user = {}, query } = req;
3
+ const { uid } = user;
4
+ if (!uid) return reply.code(401).send({ message: 'Not authorized', status: 401 });
5
+
6
+ const { page = 1, limit = 16 } = query;
7
+ const offset = limit * (page - 1) || 0;
8
+
9
+ const { total, filtered } = await pg.one(`select count(*)::int as total from site.feedback`)
10
+
11
+ const { rows = [] } = await pg.query(`
12
+ select
13
+ row_number() over(order by created_at desc) as num,
14
+ subscription_id,
15
+ email,
16
+ created_at,
17
+ enabled
18
+ from site.subscription
19
+ order by created_at desc
20
+ limit ${limit} offset ${offset}
21
+ `);
22
+
23
+ const status = rows?.length ? 200 : 204;
24
+ return reply.code(status).send({ message: { total, filtered, rows }, status })
25
25
  }