@opengis/cms 0.0.56 → 0.0.57
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/package.json +2 -2
- package/server/routes/cms/controllers/getContent.js +3 -3
- package/server/routes/cms/controllers/insertContent.js +1 -1
- package/server/routes/cms/controllers/updateContent.js +7 -5
- package/server/routes/cms/utils/getSingle.js +10 -5
- package/server/routes/cms/utils/updateLocalization.js +1 -1
- package/server/routes/contentType/controllers/editContentType.js +16 -9
- package/server/routes/contentType/controllers/getContentType.js +13 -5
- package/server/routes/contentType/utils/updateContents.js +10 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengis/cms",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.57",
|
|
4
4
|
"description": "cms",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Softpro",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@fastify/compress": "^8.1.0",
|
|
43
43
|
"@opengis/core": "^0.0.30",
|
|
44
|
-
"@opengis/fastify-table": "^2.0.
|
|
44
|
+
"@opengis/fastify-table": "^2.0.147",
|
|
45
45
|
"@opengis/filter": "^0.1.31",
|
|
46
46
|
"@opengis/form": "^0.0.109",
|
|
47
47
|
"@opengis/richtext": "0.0.45",
|
|
@@ -65,7 +65,7 @@ export default async function getContent(req, reply, opt) {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
const { contentId, contentTypeId, meta } = params.type === 'pages'
|
|
68
|
-
?
|
|
68
|
+
? await pg.query(`select content_id as "contentId", content_type_id as "contentTypeId", meta from site.contents where content_id=$1`, [params.type]).then(el => el.rows?.[0] || {})
|
|
69
69
|
: await pg.query(`select content_id as "contentId", content_type_id as "contentTypeId", meta from site.contents where $1 in (slug, content_id, content_type_id)`, [params.type]).then(el => el.rows?.[0] || {});
|
|
70
70
|
|
|
71
71
|
if (!contentId) {
|
|
@@ -77,7 +77,7 @@ export default async function getContent(req, reply, opt) {
|
|
|
77
77
|
[contentTypeId],
|
|
78
78
|
).then(el => el.rows?.[0] || {});
|
|
79
79
|
|
|
80
|
-
if (!contentType) {
|
|
80
|
+
if (!contentType && params.type !== 'pages') {
|
|
81
81
|
return reply.status(404).send('content type not found');
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -97,7 +97,7 @@ export default async function getContent(req, reply, opt) {
|
|
|
97
97
|
fields, defaultFields, defaultFilters, called,
|
|
98
98
|
}, reply, pg)
|
|
99
99
|
: await getSingle({
|
|
100
|
-
contentId, id, limit, maxLimit, tags, search, filter, locale, statusQuery, user, sql, page, defaultColumns, fields, defaultFields, defaultFilters,
|
|
100
|
+
contentId, contentTypeId, id, limit, maxLimit, tags, search, filter, locale, statusQuery, user, sql, page, defaultColumns, fields, defaultFields, defaultFilters,
|
|
101
101
|
}, pg);
|
|
102
102
|
|
|
103
103
|
if (!result) {
|
|
@@ -65,7 +65,7 @@ export default async function insertContent(req, reply) {
|
|
|
65
65
|
const loadTable = (ctypeId || type) === 'pages' ? await getTemplate('table', 'single.default.table') : {};
|
|
66
66
|
|
|
67
67
|
const columns = (ctypeId || type) === 'pages'
|
|
68
|
-
? (loadTable?.columns || []).concat(contentColumns.filter(col => loadTable?.columns.findIndex(el => el.name === col.name) === -1))
|
|
68
|
+
? (loadTable?.columns || []).concat((contentColumns || []).filter(col => loadTable?.columns.findIndex(el => el.name === col.name) === -1))
|
|
69
69
|
: contentColumns;
|
|
70
70
|
|
|
71
71
|
// site.content_data, includes singletone
|
|
@@ -60,7 +60,7 @@ export default async function updateContent(req, reply) {
|
|
|
60
60
|
|
|
61
61
|
const loadTable = type === 'pages' ? await getTemplate('table', 'single.default.table') : {};
|
|
62
62
|
const columns = type === 'pages'
|
|
63
|
-
? (loadTable?.columns || []).concat(contentColumns.filter(col => loadTable?.columns.findIndex(el => el.name === col.name) === -1))
|
|
63
|
+
? (loadTable?.columns || []).concat((contentColumns || []).filter(col => loadTable?.columns.findIndex(el => el.name === col.name) === -1))
|
|
64
64
|
: contentColumns;
|
|
65
65
|
|
|
66
66
|
// const xss = checkXSS({ body });
|
|
@@ -121,9 +121,9 @@ export default async function updateContent(req, reply) {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
const single = await pg.query(
|
|
124
|
-
`select
|
|
124
|
+
`select content_id, content_type_id, slug FROM site.contents
|
|
125
125
|
where content_id=$1`, [params.id]
|
|
126
|
-
).then(el => el.
|
|
126
|
+
).then(el => el.rows?.[0]);
|
|
127
127
|
|
|
128
128
|
const customCtExists = await pg.query(
|
|
129
129
|
`select 1 FROM site.content_types
|
|
@@ -137,12 +137,14 @@ export default async function updateContent(req, reply) {
|
|
|
137
137
|
|
|
138
138
|
const res = {};
|
|
139
139
|
|
|
140
|
-
if (single && !customCtExists) {
|
|
140
|
+
if (single && !customCtExists && (single?.content_type_id === 'pages' || single?.content_type_id === params.id)) {
|
|
141
|
+
// const loadTable = await getTemplate('table', 'single.default.table');
|
|
142
|
+
// const { columns: defaultColumns } = loadTable || {};
|
|
141
143
|
const res1 = await dataInsert({
|
|
142
144
|
pg: client,
|
|
143
145
|
table: 'site.content_types',
|
|
144
146
|
id: params.id,
|
|
145
|
-
data: body,
|
|
147
|
+
data: { ...body, type: 'single', name: body.name === 'pages' ? (single.slug || params.id) : (body.name || body.slug) /*, columns: defaultColumns*/ },
|
|
146
148
|
uid: user?.uid,
|
|
147
149
|
});
|
|
148
150
|
Object.assign(res, res1);
|
|
@@ -6,14 +6,19 @@ import inputTypes from '../utils/inputTypes.js';
|
|
|
6
6
|
import additionalData from "./additionalData.js";
|
|
7
7
|
|
|
8
8
|
export default async function getSingle({
|
|
9
|
-
contentId: contentId1, id: id1, limit: queryLimit, maxLimit, search, filter, locale, statusQuery, user, sql, page, defaultColumns = [], fields, defaultFields = [], defaultFilters = [],
|
|
9
|
+
contentId: contentId1, contentTypeId, id: id1, limit: queryLimit, maxLimit, search, filter, locale, statusQuery, user, sql, page, defaultColumns = [], fields, defaultFields = [], defaultFilters = [],
|
|
10
10
|
}, pg = pgClients.client) {
|
|
11
11
|
const id = id1 || (contentId1 === 'pages' ? undefined : contentId1) || '';
|
|
12
12
|
const contentId = id1 ? contentId1 : "pages";
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
// new ? 1 : 2
|
|
15
|
+
const customColumns = contentTypeId === (id || contentId)
|
|
16
|
+
? await pg.query(
|
|
17
|
+
`SELECT columns FROM site.content_types WHERE content_type_id=$1`, [id || contentId]
|
|
18
|
+
).then(el => el.rows?.[0]?.columns || [])
|
|
19
|
+
: await pg.query(`
|
|
20
|
+
SELECT columns FROM site.content_types WHERE content_type_id in (select content_type_id from site.contents where content_id=$1) limit 1
|
|
21
|
+
`, [id || contentId]).then(el => el.rows?.[0]?.columns || []);
|
|
17
22
|
|
|
18
23
|
const contentQuery = contentId === 'pages' || !id
|
|
19
24
|
? `(type = 'single' or content_type_id = 'pages')`
|
|
@@ -168,7 +173,7 @@ export default async function getSingle({
|
|
|
168
173
|
});
|
|
169
174
|
|
|
170
175
|
// temporary solution, before front makes changes to call by id, not type
|
|
171
|
-
rows1.forEach(row => Object.assign(row, { content_type_id: row.content_id }));
|
|
176
|
+
rows1.forEach(row => Object.assign(row, { content_type_id: !row.content_type_id || row.content_type_id === 'pages' ? row.content_id : row.content_type_id }));
|
|
172
177
|
|
|
173
178
|
return {
|
|
174
179
|
locales,
|
|
@@ -12,7 +12,7 @@ export default async function updateLocalization(pg, id, body, contentTypeId, ui
|
|
|
12
12
|
? await getTemplate('table', 'single.default.table')
|
|
13
13
|
: await getTemplate('table', 'collection.default.table');
|
|
14
14
|
|
|
15
|
-
const columns = (loadTable?.columns || []).concat(contentColumns.filter(col => loadTable?.columns.findIndex(el => el.name === col.name) === -1));
|
|
15
|
+
const columns = (loadTable?.columns || []).concat((contentColumns || []).filter(col => loadTable?.columns.findIndex(el => el.name === col.name) === -1));
|
|
16
16
|
|
|
17
17
|
const locales = await pg.query('select locales from site.spaces where space_id = $1 limit 1', ['default']).then(el => el.rows?.[0]?.locales || []);
|
|
18
18
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { dataInsert, dataUpdate, pgClients } from '@opengis/fastify-table/utils.js';
|
|
1
|
+
import { dataInsert, dataUpdate, pgClients, getTemplate } from '@opengis/fastify-table/utils.js';
|
|
2
2
|
|
|
3
3
|
import updateCustomContentTable from '../utils/updateCustomContentTable.js';
|
|
4
4
|
import updateContents from '../utils/updateContents.js';
|
|
@@ -14,8 +14,8 @@ export default async function builderPut(req, reply) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const single = await pg.query(
|
|
17
|
-
`select content_id as id FROM site.contents
|
|
18
|
-
where $1 in (content_id, slug)`, [params.id]
|
|
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
19
|
).then(el => el.rows?.[0]);
|
|
20
20
|
|
|
21
21
|
const customCtExists = await pg.query(
|
|
@@ -45,29 +45,36 @@ export default async function builderPut(req, reply) {
|
|
|
45
45
|
try {
|
|
46
46
|
await client.query('begin');
|
|
47
47
|
|
|
48
|
+
const cid1 = cid || single?.content_type_id;
|
|
49
|
+
|
|
48
50
|
if (table) {
|
|
49
|
-
await updateCustomContentTable({ pg: client, id:
|
|
51
|
+
await updateCustomContentTable({ pg: client, id: cid1, columns });
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
const name = body.name === 'pages' ? (single?.slug || params.id) : (body.name || body.slug);
|
|
55
|
+
|
|
56
|
+
// insert new,
|
|
57
|
+
if (single && !customCtExists && (single?.content_type_id === 'pages' || single?.content_type_id === params.id)) {
|
|
58
|
+
// const loadTable = await getTemplate('table', 'single.default.table');
|
|
59
|
+
// const { columns: defaultColumns } = loadTable || {};
|
|
53
60
|
await dataInsert({
|
|
54
61
|
pg,
|
|
55
62
|
table: 'site.content_types',
|
|
56
63
|
id: params.id,
|
|
57
|
-
data: body,
|
|
64
|
+
data: { ...body, type: 'single', name /*, columns: defaultColumns */ },
|
|
58
65
|
uid: user?.uid,
|
|
59
66
|
});
|
|
60
67
|
} else {
|
|
61
68
|
await dataUpdate({
|
|
62
69
|
pg: client,
|
|
63
70
|
table: 'site.content_types',
|
|
64
|
-
id:
|
|
65
|
-
data: body,
|
|
71
|
+
id: cid1,
|
|
72
|
+
data: { ...body, content_type_id: cid1, name },
|
|
66
73
|
uid: user?.uid,
|
|
67
74
|
});
|
|
68
75
|
}
|
|
69
76
|
|
|
70
|
-
const row = await updateContents(client,
|
|
77
|
+
const row = await updateContents(client, cid1, { ...body, slug: name }, user?.uid);
|
|
71
78
|
|
|
72
79
|
await client.query('commit');
|
|
73
80
|
|
|
@@ -11,13 +11,21 @@ export default async function builderGet({ pg = pgClients.client, params = {} },
|
|
|
11
11
|
|
|
12
12
|
const single = await pg.query(
|
|
13
13
|
`select content_id as id, * FROM site.contents
|
|
14
|
-
where $1 in (content_id, slug)`, [params.id]
|
|
14
|
+
where $1 in (content_id, content_type_id, slug)`, [params.id]
|
|
15
15
|
).then(el => el.rows?.[0]);
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
19
22
|
where $1 in (content_type_id, name)`, [params.id]
|
|
20
|
-
|
|
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
|
+
}
|
|
21
29
|
|
|
22
30
|
if (single && !row) {
|
|
23
31
|
const loadTable = await getTemplate('table', 'single.default.table');
|
|
@@ -44,7 +52,7 @@ export default async function builderGet({ pg = pgClients.client, params = {} },
|
|
|
44
52
|
: await getTemplate('table', 'collection.default.table');
|
|
45
53
|
const { columns: defaultColumns = [] } = loadTable || {};
|
|
46
54
|
defaultColumns.forEach(col => Object.assign(col, { default: true }));
|
|
47
|
-
const columns = (defaultColumns || []).concat(row.columns.filter(col => !defaultColumns.map(el => el.name).includes(col.name)));
|
|
55
|
+
const columns = (defaultColumns || []).concat((row.columns || []).filter(col => !defaultColumns.map(el => el.name).includes(col.name)));
|
|
48
56
|
|
|
49
57
|
Object.assign(row, { columns });
|
|
50
58
|
|
|
@@ -3,32 +3,32 @@ import { dataInsert, dataUpdate } from "@opengis/fastify-table/utils.js";
|
|
|
3
3
|
export default async function updateContents(pg, id, data, uid) {
|
|
4
4
|
if (!pg?.pk || !id) return null;
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
`select
|
|
6
|
+
const single = await pg.query(
|
|
7
|
+
`select 1 from site.contents where content_id=$1`,
|
|
8
8
|
[id],
|
|
9
|
-
).then(el => el.
|
|
9
|
+
).then(el => el.rowCount || 0);
|
|
10
10
|
|
|
11
|
-
if (
|
|
11
|
+
if (single) {
|
|
12
12
|
const result = await dataUpdate({
|
|
13
13
|
pg,
|
|
14
|
-
id: contentId,
|
|
15
14
|
table: 'site.contents',
|
|
15
|
+
id,
|
|
16
16
|
data,
|
|
17
17
|
uid,
|
|
18
18
|
});
|
|
19
19
|
return result;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const
|
|
23
|
-
`select content_id from site.contents where content_id
|
|
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
24
|
[id],
|
|
25
|
-
).then(el => el.
|
|
25
|
+
).then(el => el.rows?.[0]?.content_id);
|
|
26
26
|
|
|
27
|
-
if (
|
|
27
|
+
if (contentId) {
|
|
28
28
|
const result = await dataUpdate({
|
|
29
29
|
pg,
|
|
30
|
+
id: data?.type === 'single' ? id : contentId,
|
|
30
31
|
table: 'site.contents',
|
|
31
|
-
id,
|
|
32
32
|
data,
|
|
33
33
|
uid,
|
|
34
34
|
});
|