@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.
- package/README.md +98 -98
- package/dist/index-W-qQIppj-DunG40EG.js +2452 -0
- package/dist/index.html +28 -28
- package/dist/index.js +12683 -6702
- package/dist/index.umd.cjs +87 -41
- package/dist/style.css +1 -0
- package/package.json +68 -68
- package/plugin.js +76 -76
- package/server/app.js +35 -35
- package/server/config.js +4 -4
- package/server/functions/getDraftKey.js +22 -22
- package/server/index.js +22 -22
- package/server/migrations/fixes.sql +123 -123
- package/server/migrations/site.sql +545 -545
- package/server/plugins/adminHook.js +78 -78
- package/server/plugins/hook.js +59 -59
- package/server/plugins/vite.js +84 -84
- package/server/routes/category/controllers/cms.category.delete.js +21 -21
- package/server/routes/category/controllers/cms.category.get.js +17 -17
- package/server/routes/category/controllers/cms.category.list.js +16 -16
- package/server/routes/category/controllers/cms.category.post.js +21 -21
- package/server/routes/category/controllers/cms.category.put.js +23 -23
- package/server/routes/category/index.mjs +22 -22
- package/server/routes/cms/controllers/cmsStat.js +55 -55
- package/server/routes/cms/controllers/cmsSuggest.js +57 -57
- package/server/routes/cms/controllers/deleteContent.js +114 -114
- package/server/routes/cms/controllers/deleteMedia.js +75 -75
- package/server/routes/cms/controllers/downloadMedia.js +48 -48
- package/server/routes/cms/controllers/getContent.js +110 -110
- package/server/routes/cms/controllers/getContentBySlug.js +95 -95
- package/server/routes/cms/controllers/getPermissions.js +15 -15
- package/server/routes/cms/controllers/insertContent.js +218 -218
- package/server/routes/cms/controllers/listMedia.js +93 -93
- package/server/routes/cms/controllers/metadataMedia.js +38 -38
- package/server/routes/cms/controllers/properties.get.js +53 -53
- package/server/routes/cms/controllers/properties.post.js +99 -99
- package/server/routes/cms/controllers/searchContent.js +205 -205
- package/server/routes/cms/controllers/setPermissions.js +49 -49
- package/server/routes/cms/controllers/translate.js +89 -89
- package/server/routes/cms/controllers/updateContent.js +238 -238
- package/server/routes/cms/controllers/uploadMedia.js +78 -78
- package/server/routes/cms/index.mjs +114 -114
- package/server/routes/cms/utils/additionalData.js +35 -35
- package/server/routes/cms/utils/getCollection.js +81 -81
- package/server/routes/cms/utils/getSingle.js +187 -187
- package/server/routes/cms/utils/insertContentLocalization.js +86 -86
- package/server/routes/cms/utils/requestTranslation.js +85 -85
- package/server/routes/cms/utils/updateLocalization.js +47 -47
- package/server/routes/cmsSpace/controllers/deleteSpace.js +25 -25
- package/server/routes/cmsSpace/controllers/getSpaces.js +27 -27
- package/server/routes/cmsSpace/controllers/insertSpace.js +21 -21
- package/server/routes/cmsSpace/controllers/updateSpace.js +23 -23
- package/server/routes/cmsSpace/index.mjs +20 -20
- package/server/routes/contentType/controllers/addContentType.js +162 -162
- package/server/routes/contentType/controllers/contentTypeList.js +54 -54
- package/server/routes/contentType/controllers/delContentType.js +75 -75
- package/server/routes/contentType/controllers/editContentType.js +61 -61
- package/server/routes/contentType/controllers/getContentType.js +37 -37
- package/server/routes/contentType/index.mjs +35 -35
- package/server/routes/contentType/utils/updateContents.js +28 -28
- package/server/routes/contentType/utils/updateCustomContentTable.js +55 -55
- package/server/routes/feedback/controllers/email.list.js +24 -24
- package/server/routes/feedback/controllers/feedback.js +48 -48
- package/server/routes/feedback/controllers/feedback.list.js +37 -37
- package/server/routes/feedback/controllers/news.subscriptions.js +44 -44
- package/server/routes/feedback/index.mjs +71 -71
- package/server/routes/logs/controllers/export.user.logs.js +77 -77
- package/server/routes/logs/controllers/user.logs.js +44 -44
- package/server/routes/logs/index.mjs +9 -9
- package/server/routes/menu/controllers/addMenu.js +37 -37
- package/server/routes/menu/controllers/delMenu.js +31 -31
- package/server/routes/menu/controllers/editMenu.js +41 -41
- package/server/routes/menu/controllers/getMenu.js +42 -42
- package/server/routes/menu/index.mjs +13 -13
- package/server/routes/migration/controllers/collectionToCustom.js +137 -137
- package/server/routes/migration/index.mjs +8 -8
- package/server/routes/root.mjs +8 -8
- package/server/routes/tags/controllers/add.tags.js +24 -24
- package/server/routes/tags/controllers/del.tags.js +19 -19
- package/server/routes/tags/controllers/edit.tags.js +25 -25
- package/server/routes/tags/controllers/get.tags.js +15 -15
- package/server/routes/tags/index.mjs +14 -14
- package/server/templates/cls/cms.category_type.json +9 -9
- package/server/templates/cls/cms.content_review_status.json +9 -9
- package/server/templates/cls/cms.content_status.json +9 -9
- package/server/templates/cls/cms.content_type.json +9 -9
- package/server/templates/cls/cms.lang.json +9 -9
- package/server/templates/page/login.html +126 -126
- package/server/templates/select/core.user_mentioned.sql +1 -1
- package/dist/index-W-qQIppj-DRzFSjU1.js +0 -2452
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
import { config } from "@opengis/fastify-table/utils.js";
|
|
2
|
-
|
|
3
|
-
const { host = 'https://translate.softpro.ua', key = '' } = config.integrations?.translation || {};
|
|
4
|
-
|
|
5
|
-
const divider = ' <divider> ';
|
|
6
|
-
|
|
7
|
-
// Wrap dot notation keys in quotes
|
|
8
|
-
export const arrayToPhrases = (arr, prefix = 'item') => {
|
|
9
|
-
if (!arr || !arr.length) return [];
|
|
10
|
-
return arr.flatMap((obj, idx) =>
|
|
11
|
-
Object.entries(obj).map(([key, value]) => ({
|
|
12
|
-
prefix,
|
|
13
|
-
value,
|
|
14
|
-
// phrase: `"${prefix}"."${key}".${idx}: ${value}`,
|
|
15
|
-
key,
|
|
16
|
-
idx
|
|
17
|
-
}))
|
|
18
|
-
);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export default async function requestTranslation(entries, from = 'uk', to) {
|
|
22
|
-
// Flatten all phrases
|
|
23
|
-
const phrasesWithMeta = entries.flatMap(([key, value]) =>
|
|
24
|
-
Array.isArray(value) ? arrayToPhrases(value, key) : [{ key, value, prefix: key }]
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
// Translate each phrase independently
|
|
28
|
-
const translatedPhrases = await Promise.all(
|
|
29
|
-
phrasesWithMeta.map(async ({ key, idx, prefix, value }) => {
|
|
30
|
-
if (!value || typeof value === 'number' || value?.startsWith?.('/files/')) {
|
|
31
|
-
return { key, idx, prefix, value, skip: true }; // fallback to original
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
const parts = value.startsWith('<') && value.endsWith('>')
|
|
36
|
-
? [...value.matchAll(/(<[^>]+>)([^<]*)(<\/[^>]+>)/g)].map(([, openTag, str, closeTag]) => ({ openTag, str, closeTag }))
|
|
37
|
-
: [{ str: value }];
|
|
38
|
-
|
|
39
|
-
const q = parts.map(({ str }) => str).join(divider);
|
|
40
|
-
|
|
41
|
-
const resp = await fetch(`${host}/translate`, {
|
|
42
|
-
method: "POST",
|
|
43
|
-
headers: { "Content-Type": "application/json" },
|
|
44
|
-
body: JSON.stringify({
|
|
45
|
-
q,
|
|
46
|
-
source: from || "auto",
|
|
47
|
-
target: to,
|
|
48
|
-
format: "text",
|
|
49
|
-
api_key: key
|
|
50
|
-
}),
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
if (resp.status !== 200 || resp.headers.get('content-type') !== 'application/json') {
|
|
54
|
-
const err = await resp.text();
|
|
55
|
-
console.warn('translation request error', resp.status, err);
|
|
56
|
-
return { key, idx, prefix, value, error: err }; // fallback to original
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const body = await resp.json();
|
|
60
|
-
const resultValue = body.translatedText ? parts.map(({ openTag, str, closeTag }, i) => `${openTag || ''}${body.translatedText.split(divider)[i] || str || ''}${closeTag || ''}`).join(' ') : null;
|
|
61
|
-
return { key, idx, prefix, value: resultValue || value };
|
|
62
|
-
} catch (err) {
|
|
63
|
-
console.warn('translation request failed', err.toString());
|
|
64
|
-
return { key, idx, prefix, value, error: err.toString() }; // fallback
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
const result = translatedPhrases.reduce((acc, { key, idx, prefix, value }) => {
|
|
70
|
-
if (!acc[`${prefix}:${to}`]) acc[`${prefix}:${to}`] = Array.isArray(entries.find(e => e[0] === prefix)[1]) ? [] : null;
|
|
71
|
-
|
|
72
|
-
if (Array.isArray(entries.find(e => e[0] === prefix)[1])) {
|
|
73
|
-
if (!acc[`${prefix}:${to}`][idx]) acc[`${prefix}:${to}`][idx] = {};
|
|
74
|
-
acc[`${prefix}:${to}`][idx][key] = value;
|
|
75
|
-
} else {
|
|
76
|
-
acc[`${prefix}:${to}`] = value;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return acc;
|
|
80
|
-
}, {});
|
|
81
|
-
|
|
82
|
-
const errors = translatedPhrases.filter(({ error }) => !!error).length;
|
|
83
|
-
|
|
84
|
-
return { result, errors };
|
|
85
|
-
}
|
|
1
|
+
import { config } from "@opengis/fastify-table/utils.js";
|
|
2
|
+
|
|
3
|
+
const { host = 'https://translate.softpro.ua', key = '' } = config.integrations?.translation || {};
|
|
4
|
+
|
|
5
|
+
const divider = ' <divider> ';
|
|
6
|
+
|
|
7
|
+
// Wrap dot notation keys in quotes
|
|
8
|
+
export const arrayToPhrases = (arr, prefix = 'item') => {
|
|
9
|
+
if (!arr || !arr.length) return [];
|
|
10
|
+
return arr.flatMap((obj, idx) =>
|
|
11
|
+
Object.entries(obj).map(([key, value]) => ({
|
|
12
|
+
prefix,
|
|
13
|
+
value,
|
|
14
|
+
// phrase: `"${prefix}"."${key}".${idx}: ${value}`,
|
|
15
|
+
key,
|
|
16
|
+
idx
|
|
17
|
+
}))
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default async function requestTranslation(entries, from = 'uk', to) {
|
|
22
|
+
// Flatten all phrases
|
|
23
|
+
const phrasesWithMeta = entries.flatMap(([key, value]) =>
|
|
24
|
+
Array.isArray(value) ? arrayToPhrases(value, key) : [{ key, value, prefix: key }]
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
// Translate each phrase independently
|
|
28
|
+
const translatedPhrases = await Promise.all(
|
|
29
|
+
phrasesWithMeta.map(async ({ key, idx, prefix, value }) => {
|
|
30
|
+
if (!value || typeof value === 'number' || value?.startsWith?.('/files/')) {
|
|
31
|
+
return { key, idx, prefix, value, skip: true }; // fallback to original
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
const parts = value.startsWith('<') && value.endsWith('>')
|
|
36
|
+
? [...value.matchAll(/(<[^>]+>)([^<]*)(<\/[^>]+>)/g)].map(([, openTag, str, closeTag]) => ({ openTag, str, closeTag }))
|
|
37
|
+
: [{ str: value }];
|
|
38
|
+
|
|
39
|
+
const q = parts.map(({ str }) => str).join(divider);
|
|
40
|
+
|
|
41
|
+
const resp = await fetch(`${host}/translate`, {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: { "Content-Type": "application/json" },
|
|
44
|
+
body: JSON.stringify({
|
|
45
|
+
q,
|
|
46
|
+
source: from || "auto",
|
|
47
|
+
target: to,
|
|
48
|
+
format: "text",
|
|
49
|
+
api_key: key
|
|
50
|
+
}),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
if (resp.status !== 200 || resp.headers.get('content-type') !== 'application/json') {
|
|
54
|
+
const err = await resp.text();
|
|
55
|
+
console.warn('translation request error', resp.status, err);
|
|
56
|
+
return { key, idx, prefix, value, error: err }; // fallback to original
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const body = await resp.json();
|
|
60
|
+
const resultValue = body.translatedText ? parts.map(({ openTag, str, closeTag }, i) => `${openTag || ''}${body.translatedText.split(divider)[i] || str || ''}${closeTag || ''}`).join(' ') : null;
|
|
61
|
+
return { key, idx, prefix, value: resultValue || value };
|
|
62
|
+
} catch (err) {
|
|
63
|
+
console.warn('translation request failed', err.toString());
|
|
64
|
+
return { key, idx, prefix, value, error: err.toString() }; // fallback
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const result = translatedPhrases.reduce((acc, { key, idx, prefix, value }) => {
|
|
70
|
+
if (!acc[`${prefix}:${to}`]) acc[`${prefix}:${to}`] = Array.isArray(entries.find(e => e[0] === prefix)[1]) ? [] : null;
|
|
71
|
+
|
|
72
|
+
if (Array.isArray(entries.find(e => e[0] === prefix)[1])) {
|
|
73
|
+
if (!acc[`${prefix}:${to}`][idx]) acc[`${prefix}:${to}`][idx] = {};
|
|
74
|
+
acc[`${prefix}:${to}`][idx][key] = value;
|
|
75
|
+
} else {
|
|
76
|
+
acc[`${prefix}:${to}`] = value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return acc;
|
|
80
|
+
}, {});
|
|
81
|
+
|
|
82
|
+
const errors = translatedPhrases.filter(({ error }) => !!error).length;
|
|
83
|
+
|
|
84
|
+
return { result, errors };
|
|
85
|
+
}
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import { dataInsert, getTemplate } from "@opengis/fastify-table/utils.js";
|
|
2
|
-
|
|
3
|
-
export default async function updateLocalization(pg, id, body, contentTypeId, uid) {
|
|
4
|
-
if (!pg || !id || !body || !contentTypeId) { return null };
|
|
5
|
-
|
|
6
|
-
const contentColumns = await pg.query('select content_type_id as ctid, name as ctname, table_name as dbtable, columns from site.content_types where content_type_id in (select content_type_id from site.contents where content_id=$1) or content_type_id=$2 order by content_type_id = \'pages\'', [id, contentTypeId]).then(el => el.rows?.[0]?.columns || []);
|
|
7
|
-
|
|
8
|
-
// const contentColumns = await pg.query('select columns from site.content_types where content_type_id=$1', [contentTypeId])
|
|
9
|
-
// .then(el => el.rows?.[0]?.columns || []);
|
|
10
|
-
|
|
11
|
-
const loadTable = contentTypeId === 'pages' ? await getTemplate('table', 'single.default.table') : {};
|
|
12
|
-
|
|
13
|
-
const columns = contentTypeId === 'pages'
|
|
14
|
-
? (loadTable?.columns || []).concat(contentColumns.filter(col => loadTable?.columns.findIndex(el => el.name === col.name) === -1))
|
|
15
|
-
: contentColumns;
|
|
16
|
-
|
|
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
|
-
|
|
19
|
-
await pg.query('delete from site.localization where object_id=$1', [id]);
|
|
20
|
-
|
|
21
|
-
// localization disable for current space
|
|
22
|
-
if (!locales?.length) { return null; }
|
|
23
|
-
|
|
24
|
-
const schemaKeys = columns.filter(el => el?.name && el.localization).map(el => el.name);
|
|
25
|
-
|
|
26
|
-
const bodyKeys = Object.keys(body || {}).filter(key => body[key] && key.includes(':') && key.split(':').pop() && locales.includes(key.split(':').pop()) && schemaKeys.includes(key.split(':').shift()));
|
|
27
|
-
const obj = bodyKeys.reduce((acc, curr) => ({ ...acc, [curr]: body[curr] }), {});
|
|
28
|
-
|
|
29
|
-
if (bodyKeys.length === 0) { return null; }
|
|
30
|
-
|
|
31
|
-
const arr = Object.keys(obj).reduce((acc, curr) => {
|
|
32
|
-
acc.push({
|
|
33
|
-
field_key: curr,
|
|
34
|
-
field_value: body[curr],
|
|
35
|
-
object_id: id,
|
|
36
|
-
});
|
|
37
|
-
return acc;
|
|
38
|
-
}, []);
|
|
39
|
-
|
|
40
|
-
await Promise.all(arr.map(async row => dataInsert({
|
|
41
|
-
pg,
|
|
42
|
-
table: 'site.localization',
|
|
43
|
-
data: row,
|
|
44
|
-
uid,
|
|
45
|
-
})));
|
|
46
|
-
|
|
47
|
-
return obj;
|
|
1
|
+
import { dataInsert, getTemplate } from "@opengis/fastify-table/utils.js";
|
|
2
|
+
|
|
3
|
+
export default async function updateLocalization(pg, id, body, contentTypeId, uid) {
|
|
4
|
+
if (!pg || !id || !body || !contentTypeId) { return null };
|
|
5
|
+
|
|
6
|
+
const contentColumns = await pg.query('select content_type_id as ctid, name as ctname, table_name as dbtable, columns from site.content_types where content_type_id in (select content_type_id from site.contents where content_id=$1) or content_type_id=$2 order by content_type_id = \'pages\'', [id, contentTypeId]).then(el => el.rows?.[0]?.columns || []);
|
|
7
|
+
|
|
8
|
+
// const contentColumns = await pg.query('select columns from site.content_types where content_type_id=$1', [contentTypeId])
|
|
9
|
+
// .then(el => el.rows?.[0]?.columns || []);
|
|
10
|
+
|
|
11
|
+
const loadTable = contentTypeId === 'pages' ? await getTemplate('table', 'single.default.table') : {};
|
|
12
|
+
|
|
13
|
+
const columns = contentTypeId === 'pages'
|
|
14
|
+
? (loadTable?.columns || []).concat(contentColumns.filter(col => loadTable?.columns.findIndex(el => el.name === col.name) === -1))
|
|
15
|
+
: contentColumns;
|
|
16
|
+
|
|
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
|
+
|
|
19
|
+
await pg.query('delete from site.localization where object_id=$1', [id]);
|
|
20
|
+
|
|
21
|
+
// localization disable for current space
|
|
22
|
+
if (!locales?.length) { return null; }
|
|
23
|
+
|
|
24
|
+
const schemaKeys = columns.filter(el => el?.name && el.localization).map(el => el.name);
|
|
25
|
+
|
|
26
|
+
const bodyKeys = Object.keys(body || {}).filter(key => body[key] && key.includes(':') && key.split(':').pop() && locales.includes(key.split(':').pop()) && schemaKeys.includes(key.split(':').shift()));
|
|
27
|
+
const obj = bodyKeys.reduce((acc, curr) => ({ ...acc, [curr]: body[curr] }), {});
|
|
28
|
+
|
|
29
|
+
if (bodyKeys.length === 0) { return null; }
|
|
30
|
+
|
|
31
|
+
const arr = Object.keys(obj).reduce((acc, curr) => {
|
|
32
|
+
acc.push({
|
|
33
|
+
field_key: curr,
|
|
34
|
+
field_value: body[curr],
|
|
35
|
+
object_id: id,
|
|
36
|
+
});
|
|
37
|
+
return acc;
|
|
38
|
+
}, []);
|
|
39
|
+
|
|
40
|
+
await Promise.all(arr.map(async row => dataInsert({
|
|
41
|
+
pg,
|
|
42
|
+
table: 'site.localization',
|
|
43
|
+
data: row,
|
|
44
|
+
uid,
|
|
45
|
+
})));
|
|
46
|
+
|
|
47
|
+
return obj;
|
|
48
48
|
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { dataDelete, pgClients } from '@opengis/fastify-table/utils.js';
|
|
2
|
-
|
|
3
|
-
export default async function deleteSpace({ pg = pgClients.client, user, params, headers = {} }, reply) {
|
|
4
|
-
if (!params?.id) { return reply.status(400).send('not enough params: id'); }
|
|
5
|
-
if (!pg?.pk) { return reply.status(400).send('empty pg'); }
|
|
6
|
-
if (!pg?.pk?.['site.spaces']) { return reply.status(400).send('table not found: site.spaces'); }
|
|
7
|
-
|
|
8
|
-
if (params?.id && params.id === 'default') {
|
|
9
|
-
return reply.status(400).send('default space cannot be deleted');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const exists = await pg.query('select space_id from site.spaces where space_id=$1', [params.id]).then(el => el.rows?.[0]?.space_id);
|
|
13
|
-
if (!exists) { return reply.status(404).send('space not found: ' + params.id); }
|
|
14
|
-
|
|
15
|
-
const { referer } = headers;
|
|
16
|
-
|
|
17
|
-
const res = await dataDelete({
|
|
18
|
-
pg,
|
|
19
|
-
table: 'site.spaces',
|
|
20
|
-
id: params?.id,
|
|
21
|
-
uid: user?.uid,
|
|
22
|
-
referer,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
return { id: params.id, ...res || {} };
|
|
1
|
+
import { dataDelete, pgClients } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
export default async function deleteSpace({ pg = pgClients.client, user, params, headers = {} }, reply) {
|
|
4
|
+
if (!params?.id) { return reply.status(400).send('not enough params: id'); }
|
|
5
|
+
if (!pg?.pk) { return reply.status(400).send('empty pg'); }
|
|
6
|
+
if (!pg?.pk?.['site.spaces']) { return reply.status(400).send('table not found: site.spaces'); }
|
|
7
|
+
|
|
8
|
+
if (params?.id && params.id === 'default') {
|
|
9
|
+
return reply.status(400).send('default space cannot be deleted');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const exists = await pg.query('select space_id from site.spaces where space_id=$1', [params.id]).then(el => el.rows?.[0]?.space_id);
|
|
13
|
+
if (!exists) { return reply.status(404).send('space not found: ' + params.id); }
|
|
14
|
+
|
|
15
|
+
const { referer } = headers;
|
|
16
|
+
|
|
17
|
+
const res = await dataDelete({
|
|
18
|
+
pg,
|
|
19
|
+
table: 'site.spaces',
|
|
20
|
+
id: params?.id,
|
|
21
|
+
uid: user?.uid,
|
|
22
|
+
referer,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return { id: params.id, ...res || {} };
|
|
26
26
|
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { pgClients } from '@opengis/fastify-table/utils.js';
|
|
2
|
-
|
|
3
|
-
const maxLimit = 100;
|
|
4
|
-
const defaultLimit = 20;
|
|
5
|
-
|
|
6
|
-
export default async function getSpaces({ pg = pgClients.client, user, params = {}, query = {} }, reply) {
|
|
7
|
-
if (!pg?.pk) { return reply.status(400).send('empty pg'); }
|
|
8
|
-
if (!pg?.pk?.['site.spaces']) { return reply.status(400).send('table not found: site.spaces'); }
|
|
9
|
-
|
|
10
|
-
const limit = Math.min(maxLimit, +(query.limit || defaultLimit));
|
|
11
|
-
const offset = query.page && query.page > 0 && !params.id ? (query.page - 1) * limit : 0;
|
|
12
|
-
|
|
13
|
-
const q = `select * from site.spaces where ${params.id ? 'space_id=$1' : '1=1'} limit ${limit} offset ${offset}`;
|
|
14
|
-
if (query.sql && user?.uid) return q;
|
|
15
|
-
|
|
16
|
-
const { rows = [] } = await pg.query(q, [params.id].filter(Boolean));
|
|
17
|
-
|
|
18
|
-
const total = await pg.queryCache('select count(*) from site.spaces', { table: 'site.spaces' }).then(el => el.rows?.[0]?.count || 0);
|
|
19
|
-
|
|
20
|
-
rows.forEach(row => Object.assign(row, { id: row.space_id }));
|
|
21
|
-
|
|
22
|
-
if (params.id) {
|
|
23
|
-
if (!rows.length) { return reply.status(404).send('space not found: ' + params.id); }
|
|
24
|
-
return reply.status(200).send(rows[0]);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return { total, filtered: rows.length, rows };
|
|
1
|
+
import { pgClients } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
const maxLimit = 100;
|
|
4
|
+
const defaultLimit = 20;
|
|
5
|
+
|
|
6
|
+
export default async function getSpaces({ pg = pgClients.client, user, params = {}, query = {} }, reply) {
|
|
7
|
+
if (!pg?.pk) { return reply.status(400).send('empty pg'); }
|
|
8
|
+
if (!pg?.pk?.['site.spaces']) { return reply.status(400).send('table not found: site.spaces'); }
|
|
9
|
+
|
|
10
|
+
const limit = Math.min(maxLimit, +(query.limit || defaultLimit));
|
|
11
|
+
const offset = query.page && query.page > 0 && !params.id ? (query.page - 1) * limit : 0;
|
|
12
|
+
|
|
13
|
+
const q = `select * from site.spaces where ${params.id ? 'space_id=$1' : '1=1'} limit ${limit} offset ${offset}`;
|
|
14
|
+
if (query.sql && user?.uid) return q;
|
|
15
|
+
|
|
16
|
+
const { rows = [] } = await pg.query(q, [params.id].filter(Boolean));
|
|
17
|
+
|
|
18
|
+
const total = await pg.queryCache('select count(*) from site.spaces', { table: 'site.spaces' }).then(el => el.rows?.[0]?.count || 0);
|
|
19
|
+
|
|
20
|
+
rows.forEach(row => Object.assign(row, { id: row.space_id }));
|
|
21
|
+
|
|
22
|
+
if (params.id) {
|
|
23
|
+
if (!rows.length) { return reply.status(404).send('space not found: ' + params.id); }
|
|
24
|
+
return reply.status(200).send(rows[0]);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return { total, filtered: rows.length, rows };
|
|
28
28
|
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { dataInsert, pgClients } from '@opengis/fastify-table/utils.js';
|
|
2
|
-
|
|
3
|
-
export default async function insertSpace({ pg = pgClients.client, user, params, headers = {}, body = {} }, reply) {
|
|
4
|
-
if (!pg?.pk) { return reply.status(400).send('empty pg'); }
|
|
5
|
-
if (!pg?.pk?.['site.spaces']) { return reply.status(400).send('table not found: site.spaces'); }
|
|
6
|
-
|
|
7
|
-
const exists = params?.id ? await pg.query('select space_id from site.spaces where space_id=$1', [params.id]).then(el => el.rows?.[0]?.space_id) : false;
|
|
8
|
-
if (exists) { return reply.status(400).send('space aleady exists: ' + params?.id); }
|
|
9
|
-
|
|
10
|
-
const { referer } = headers;
|
|
11
|
-
|
|
12
|
-
const res = await dataInsert({
|
|
13
|
-
pg,
|
|
14
|
-
table: 'site.spaces',
|
|
15
|
-
data: body,
|
|
16
|
-
id: params?.id,
|
|
17
|
-
uid: user?.uid,
|
|
18
|
-
referer,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
return { id: res?.rows?.[0]?.space_id, rows: res?.rows || [] };
|
|
1
|
+
import { dataInsert, pgClients } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
export default async function insertSpace({ pg = pgClients.client, user, params, headers = {}, body = {} }, reply) {
|
|
4
|
+
if (!pg?.pk) { return reply.status(400).send('empty pg'); }
|
|
5
|
+
if (!pg?.pk?.['site.spaces']) { return reply.status(400).send('table not found: site.spaces'); }
|
|
6
|
+
|
|
7
|
+
const exists = params?.id ? await pg.query('select space_id from site.spaces where space_id=$1', [params.id]).then(el => el.rows?.[0]?.space_id) : false;
|
|
8
|
+
if (exists) { return reply.status(400).send('space aleady exists: ' + params?.id); }
|
|
9
|
+
|
|
10
|
+
const { referer } = headers;
|
|
11
|
+
|
|
12
|
+
const res = await dataInsert({
|
|
13
|
+
pg,
|
|
14
|
+
table: 'site.spaces',
|
|
15
|
+
data: body,
|
|
16
|
+
id: params?.id,
|
|
17
|
+
uid: user?.uid,
|
|
18
|
+
referer,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return { id: res?.rows?.[0]?.space_id, rows: res?.rows || [] };
|
|
22
22
|
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { dataUpdate, pgClients } from '@opengis/fastify-table/utils.js';
|
|
2
|
-
|
|
3
|
-
export default async function updateSpace({ pg = pgClients.client, user, params, headers = {}, body = {} }, reply) {
|
|
4
|
-
// if (!params?.id) { return reply.status(400).send('not enough params: id'); }
|
|
5
|
-
if (!pg?.pk) { return reply.status(400).send('empty pg'); }
|
|
6
|
-
if (!pg?.pk?.['site.spaces']) { return reply.status(400).send('table not found: site.spaces'); }
|
|
7
|
-
|
|
8
|
-
const id = 'default';
|
|
9
|
-
const exists = await pg.query('select space_id from site.spaces where space_id=$1', [id]).then(el => el.rows?.[0]?.space_id);
|
|
10
|
-
if (!exists) { return reply.status(404).send('space not found: ' + id); }
|
|
11
|
-
|
|
12
|
-
const { referer } = headers;
|
|
13
|
-
|
|
14
|
-
const res = await dataUpdate({
|
|
15
|
-
pg,
|
|
16
|
-
table: 'site.spaces',
|
|
17
|
-
data: body,
|
|
18
|
-
id,
|
|
19
|
-
uid: user?.uid,
|
|
20
|
-
referer,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
return { id, ...res || {} };
|
|
1
|
+
import { dataUpdate, pgClients } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
export default async function updateSpace({ pg = pgClients.client, user, params, headers = {}, body = {} }, reply) {
|
|
4
|
+
// if (!params?.id) { return reply.status(400).send('not enough params: id'); }
|
|
5
|
+
if (!pg?.pk) { return reply.status(400).send('empty pg'); }
|
|
6
|
+
if (!pg?.pk?.['site.spaces']) { return reply.status(400).send('table not found: site.spaces'); }
|
|
7
|
+
|
|
8
|
+
const id = 'default';
|
|
9
|
+
const exists = await pg.query('select space_id from site.spaces where space_id=$1', [id]).then(el => el.rows?.[0]?.space_id);
|
|
10
|
+
if (!exists) { return reply.status(404).send('space not found: ' + id); }
|
|
11
|
+
|
|
12
|
+
const { referer } = headers;
|
|
13
|
+
|
|
14
|
+
const res = await dataUpdate({
|
|
15
|
+
pg,
|
|
16
|
+
table: 'site.spaces',
|
|
17
|
+
data: body,
|
|
18
|
+
id,
|
|
19
|
+
uid: user?.uid,
|
|
20
|
+
referer,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return { id, ...res || {} };
|
|
24
24
|
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
// space
|
|
2
|
-
import getSpaces from './controllers/getSpaces.js';
|
|
3
|
-
import insertSpace from './controllers/insertSpace.js';
|
|
4
|
-
import updateSpace from './controllers/updateSpace.js';
|
|
5
|
-
import deleteSpace from './controllers/deleteSpace.js';
|
|
6
|
-
|
|
7
|
-
const params = {
|
|
8
|
-
config: {
|
|
9
|
-
policy: [
|
|
10
|
-
'public'
|
|
11
|
-
]
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export default async function route(app) {
|
|
16
|
-
app.get('/cms-space/:id?', params, getSpaces);
|
|
17
|
-
app.post('/cms-space/:id?', params, insertSpace);
|
|
18
|
-
app.put('/cms-space/:id?', params, updateSpace);
|
|
19
|
-
app.delete('/cms-space/:id', params, deleteSpace);
|
|
20
|
-
}
|
|
1
|
+
// space
|
|
2
|
+
import getSpaces from './controllers/getSpaces.js';
|
|
3
|
+
import insertSpace from './controllers/insertSpace.js';
|
|
4
|
+
import updateSpace from './controllers/updateSpace.js';
|
|
5
|
+
import deleteSpace from './controllers/deleteSpace.js';
|
|
6
|
+
|
|
7
|
+
const params = {
|
|
8
|
+
config: {
|
|
9
|
+
policy: [
|
|
10
|
+
'public'
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default async function route(app) {
|
|
16
|
+
app.get('/cms-space/:id?', params, getSpaces);
|
|
17
|
+
app.post('/cms-space/:id?', params, insertSpace);
|
|
18
|
+
app.put('/cms-space/:id?', params, updateSpace);
|
|
19
|
+
app.delete('/cms-space/:id', params, deleteSpace);
|
|
20
|
+
}
|