@opengis/cms 0.0.7 → 0.0.8
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/dist/cms.js +1505 -1494
- package/dist/cms.umd.cjs +11 -11
- package/package.json +6 -4
- package/server/app.js +25 -0
- package/server/config.js +5 -0
- package/server/index.js +23 -0
- package/server/migrations/media.sql +30 -0
- package/server/plugins/hook.js +91 -0
- package/server/plugins/vite.js +80 -0
- package/server/routes/builder/controllers/cms.builder.delete.js +21 -0
- package/server/routes/builder/controllers/cms.builder.get.js +17 -0
- package/server/routes/builder/controllers/cms.builder.list.js +16 -0
- package/server/routes/builder/controllers/cms.builder.post.js +21 -0
- package/server/routes/builder/controllers/cms.builder.put.js +23 -0
- package/server/routes/builder/index.mjs +22 -0
- package/server/routes/category/controllers/cms.category.delete.js +21 -0
- package/server/routes/category/controllers/cms.category.get.js +17 -0
- package/server/routes/category/controllers/cms.category.list.js +16 -0
- package/server/routes/category/controllers/cms.category.post.js +21 -0
- package/server/routes/category/controllers/cms.category.put.js +23 -0
- package/server/routes/category/index.mjs +22 -0
- package/server/routes/manager/controllers/cms.manager.delete.js +22 -0
- package/server/routes/manager/controllers/cms.manager.get.js +21 -0
- package/server/routes/manager/controllers/cms.manager.list.js +31 -0
- package/server/routes/manager/controllers/cms.manager.post.js +28 -0
- package/server/routes/manager/controllers/cms.manager.put.js +23 -0
- package/server/routes/manager/index.mjs +22 -0
- package/server/routes/media/controllers/delete.js +59 -0
- package/server/routes/media/controllers/edit.js +94 -0
- package/server/routes/media/controllers/list.js +74 -0
- package/server/routes/media/controllers/metadata.js +51 -0
- package/server/routes/media/controllers/preview.js +47 -0
- package/server/routes/media/controllers/upload.js +79 -0
- package/server/routes/media/index.mjs +16 -0
- package/server/routes/root.mjs +15 -0
- package/server/templates/cls/cms.category_type.json +10 -0
- package/server/templates/cls/cms.content_review_status.json +10 -0
- package/server/templates/cls/cms.content_status.json +10 -0
- package/server/templates/cls/cms.content_type.json +10 -0
- package/server/templates/cls/cms.lang.json +10 -0
- package/server/templates/page/login.html +59 -0
- package/server/templates/select/cms.category_id.sql +1 -0
- package/server/templates/select/cms.type_id.sql +1 -0
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengis/cms",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "cms",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Softpro",
|
|
7
7
|
"main": "dist/cms.js",
|
|
8
8
|
"license": "EULA",
|
|
9
9
|
"files": [
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
"dist/*",
|
|
11
|
+
"server",
|
|
12
|
+
"utils.js"
|
|
13
|
+
],
|
|
12
14
|
"scripts": {
|
|
13
15
|
"test": "node --test test/**/*.test.js",
|
|
14
16
|
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
|
|
@@ -49,4 +51,4 @@
|
|
|
49
51
|
"vitepress-plugin-tabs": "^0.5.0",
|
|
50
52
|
"vitepress-sidebar": "1.30.2"
|
|
51
53
|
}
|
|
52
|
-
}
|
|
54
|
+
}
|
package/server/app.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { config, execMigrations } from '@opengis/fastify-table/utils.js';
|
|
3
|
+
|
|
4
|
+
config.prefix = config.prefix || '/api';
|
|
5
|
+
const { prefix } = config;
|
|
6
|
+
|
|
7
|
+
const cwd = process.cwd();
|
|
8
|
+
|
|
9
|
+
export default async function (fastify) {
|
|
10
|
+
// core
|
|
11
|
+
fastify.register(import('./plugins/hook.js'));
|
|
12
|
+
|
|
13
|
+
fastify.register(import('@opengis/fastify-table'), config);
|
|
14
|
+
fastify.register(import('@opengis/fastify-auth'), config);
|
|
15
|
+
fastify.register(import('@opengis/fastify-file'), config);
|
|
16
|
+
|
|
17
|
+
fastify.register(import('./plugins/vite.js'));
|
|
18
|
+
// API
|
|
19
|
+
fastify.register(import('./routes/root.mjs'));
|
|
20
|
+
fastify.register(import('./routes/builder/index.mjs'), { prefix });
|
|
21
|
+
fastify.register(import('./routes/category/index.mjs'), { prefix });
|
|
22
|
+
fastify.register(import('./routes/manager/index.mjs'), { prefix });
|
|
23
|
+
fastify.register(import('./routes/media/index.mjs'), { prefix });
|
|
24
|
+
execMigrations(path.join(cwd, 'server/migrations')).catch(err => console.log(err));
|
|
25
|
+
}
|
package/server/config.js
ADDED
package/server/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Fastify from 'fastify';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import appService from './app.js';
|
|
5
|
+
import config from './config.js';
|
|
6
|
+
|
|
7
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
|
8
|
+
|
|
9
|
+
// Instantiate Fastify with some config
|
|
10
|
+
const app = Fastify({ logger: !isProduction });
|
|
11
|
+
|
|
12
|
+
// Register your application as a normal plugin.
|
|
13
|
+
|
|
14
|
+
app.register(appService);
|
|
15
|
+
|
|
16
|
+
process.env.PORT = process.env.PORT || config.port || 3000;
|
|
17
|
+
// Start listening.
|
|
18
|
+
app.listen({ host: '0.0.0.0', port: process.env.PORT }, (err) => {
|
|
19
|
+
if (err) {
|
|
20
|
+
app.log.error(err);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
create schema if not exists crm;
|
|
2
|
+
create table if not exists crm.media();
|
|
3
|
+
|
|
4
|
+
CREATE TABLE IF NOT EXISTS crm.media();
|
|
5
|
+
ALTER TABLE crm.media DROP CONSTRAINT IF EXISTS crm_media_id_pkey;
|
|
6
|
+
ALTER TABLE crm.media ADD COLUMN IF NOT EXISTS media_id text NOT NULL DEFAULT next_id();
|
|
7
|
+
|
|
8
|
+
ALTER TABLE crm.media ADD COLUMN IF NOT EXISTS uploaded_name text;
|
|
9
|
+
ALTER TABLE crm.media ADD COLUMN IF NOT EXISTS file_path text;
|
|
10
|
+
ALTER TABLE crm.media ADD COLUMN IF NOT EXISTS caption text;
|
|
11
|
+
ALTER TABLE crm.media ADD COLUMN IF NOT EXISTS altname text;
|
|
12
|
+
ALTER TABLE crm.media ADD COLUMN IF NOT EXISTS size numeric;
|
|
13
|
+
ALTER TABLE crm.media ADD COLUMN IF NOT EXISTS ext text;
|
|
14
|
+
ALTER TABLE crm.media ADD COLUMN IF NOT EXISTS tags text[];
|
|
15
|
+
ALTER TABLE crm.media ADD COLUMN IF NOT EXISTS uid text;
|
|
16
|
+
ALTER TABLE crm.media ADD COLUMN IF NOT EXISTS files json;
|
|
17
|
+
ALTER TABLE crm.media ADD COLUMN IF NOT EXISTS cdate timestamp without time zone DEFAULT (now())::timestamp without time zone;
|
|
18
|
+
ALTER TABLE crm.media ADD COLUMN IF NOT EXISTS editor_id text;
|
|
19
|
+
ALTER TABLE crm.media ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
|
|
20
|
+
ALTER TABLE crm.media ADD CONSTRAINT crm_media_id_pkey PRIMARY KEY (media_id);
|
|
21
|
+
|
|
22
|
+
comment on table crm.media is 'Медіа файли';
|
|
23
|
+
|
|
24
|
+
comment on column crm.media.uploaded_name is 'Назва файлу';
|
|
25
|
+
comment on column crm.media.file_path is 'Відносний шлях до файлу';
|
|
26
|
+
comment on column crm.media.caption is 'Заголовок';
|
|
27
|
+
comment on column crm.media.altname is 'Альтернативна назва';
|
|
28
|
+
comment on column crm.media.size is 'Розмір файлу';
|
|
29
|
+
comment on column crm.media.ext is 'Розширення файлу';
|
|
30
|
+
comment on column crm.media.tags is 'Теги файлу';
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import fp from 'fastify-plugin';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import config from '../config.js';
|
|
4
|
+
|
|
5
|
+
// the use of fastify-plugin is required to be able
|
|
6
|
+
// to export the decorators to the outer scope
|
|
7
|
+
|
|
8
|
+
async function plugin(fastify) {
|
|
9
|
+
fastify.decorate('config', config);
|
|
10
|
+
|
|
11
|
+
// pre Request
|
|
12
|
+
fastify.addHook('onRequest', async (req) => {
|
|
13
|
+
req.funcs = fastify;
|
|
14
|
+
const { user } = req.session?.passport || {};
|
|
15
|
+
req.user = user;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// preSerialization
|
|
19
|
+
fastify.addHook('preSerialization', async (req, reply, payload) => {
|
|
20
|
+
if (req.url.includes('/suggest/') && !req.query.json) {
|
|
21
|
+
return payload?.data;
|
|
22
|
+
}
|
|
23
|
+
/* if (payload.redirect) {
|
|
24
|
+
return reply.redirect(payload.redirect);
|
|
25
|
+
}*/
|
|
26
|
+
if (reply.sent) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
if (!payload) {
|
|
30
|
+
return payload;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (['200', '400', '500', '403', '404'].includes(payload.status)) {
|
|
34
|
+
reply.status(payload.status);
|
|
35
|
+
}
|
|
36
|
+
/* if (payload.headers) {
|
|
37
|
+
reply.headers(payload.headers);
|
|
38
|
+
} */
|
|
39
|
+
if (payload.buffer) {
|
|
40
|
+
return payload.buffer;
|
|
41
|
+
}
|
|
42
|
+
if (payload.file) {
|
|
43
|
+
// const buffer = await readFile(payload.file);
|
|
44
|
+
// return reply.send(buffer);
|
|
45
|
+
const stream = fs.createReadStream(payload.file);
|
|
46
|
+
return stream;
|
|
47
|
+
// return reply.send(stream);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (payload.message) {
|
|
51
|
+
return payload.message;
|
|
52
|
+
}
|
|
53
|
+
return payload;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// preValidation
|
|
57
|
+
fastify.addHook('preValidation', async (req) => {
|
|
58
|
+
const parseRawBody = ['POST', 'PUT'].includes(req.method) && req.body && typeof req.body === 'string'
|
|
59
|
+
&& req.body.trim(/\r\n/g).startsWith('{')
|
|
60
|
+
&& req.body.trim(/\r\n/g).endsWith('}');
|
|
61
|
+
if (parseRawBody) {
|
|
62
|
+
try {
|
|
63
|
+
req.body = JSON.parse(req.body || '{}');
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
// throw new Error('invalid body');
|
|
67
|
+
// return { error: 'invalid body', status: 400 };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// allow upload file
|
|
73
|
+
const kIsMultipart = Symbol.for('[FastifyMultipart.isMultipart]');
|
|
74
|
+
fastify.addContentTypeParser('multipart', (request, _, done) => {
|
|
75
|
+
request[kIsMultipart] = true;
|
|
76
|
+
done(null);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// parse Body
|
|
80
|
+
function contentParser(req, body, done) {
|
|
81
|
+
const parseBody = decodeURIComponent(body.toString()).split('&').reduce((acc, el) => {
|
|
82
|
+
const [key, val] = el.split('=');
|
|
83
|
+
return { ...acc, [key]: val };
|
|
84
|
+
}, {});
|
|
85
|
+
done(null, parseBody);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
fastify.addContentTypeParser('application/x-www-form-urlencoded', { parseAs: 'buffer' }, contentParser);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export default fp(plugin);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path, { dirname } from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
|
|
5
|
+
const dir = dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
const root = `${dir}/../..`;
|
|
7
|
+
import config from '../config.js';
|
|
8
|
+
|
|
9
|
+
const isProduction = process.env.NODE_ENV === 'production' || config.production;
|
|
10
|
+
|
|
11
|
+
async function plugin(fastify) {
|
|
12
|
+
// vite server
|
|
13
|
+
if (!isProduction) {
|
|
14
|
+
const vite = await import('vite');
|
|
15
|
+
|
|
16
|
+
const viteServer = await vite.createServer({
|
|
17
|
+
root: `${root}`,
|
|
18
|
+
server: {
|
|
19
|
+
middlewareMode: true,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// add root to watch
|
|
24
|
+
viteServer.watcher.add(root);
|
|
25
|
+
|
|
26
|
+
// hot relaod template
|
|
27
|
+
viteServer.watcher.on('all', (d, t) => {
|
|
28
|
+
if (!t.includes('module')) return;
|
|
29
|
+
console.log(d, t);
|
|
30
|
+
viteServer.ws.send({ type: 'full-reload' });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// this is middleware for vite's dev servert
|
|
34
|
+
fastify.addHook('onRequest', async (req, reply) => {
|
|
35
|
+
const { user } = req.session?.passport || {};
|
|
36
|
+
const { disableAuth } = req.funcs?.config || {};
|
|
37
|
+
if (!user && !disableAuth) {
|
|
38
|
+
return reply.redirect('/login');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const next = () => new Promise((resolve) => {
|
|
42
|
+
viteServer.middlewares(req.raw, reply.raw, () => resolve());
|
|
43
|
+
});
|
|
44
|
+
await next();
|
|
45
|
+
});
|
|
46
|
+
fastify.get('*', async () => { });
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// From Build
|
|
51
|
+
fastify.get('*', async (req, reply) => {
|
|
52
|
+
const { user } = req.session?.passport || {};
|
|
53
|
+
const assetsDir = '/dist';
|
|
54
|
+
if (!user) return reply.redirect('/login');
|
|
55
|
+
const stream = fs.createReadStream(`${assetsDir}/index.html`);
|
|
56
|
+
return reply.type('text/html').send(stream);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const fileSize = {};
|
|
60
|
+
async function staticFile(req, reply) {
|
|
61
|
+
const assetsDir = '/dist';
|
|
62
|
+
const filePath = path.join(root, assetsDir, req.url);
|
|
63
|
+
const ext = path.extname(filePath);
|
|
64
|
+
|
|
65
|
+
if (!fs.existsSync(filePath)) return { status: 404, message: 'not found' };
|
|
66
|
+
fileSize[filePath] = fileSize[filePath] || fs.statSync(filePath).size;
|
|
67
|
+
const mime = {
|
|
68
|
+
'.js': 'text/javascript', '.css': 'text/css', '.woff2': 'application/font-woff', '.png': 'image/png', '.svg': 'image/svg+xml', '.jpg': 'image/jpg',
|
|
69
|
+
}[ext];
|
|
70
|
+
reply.headers({ 'Cache-control': 'max-age=3600, public', 'Content-length': fileSize[filePath], 'Content-Encoding': 'identity' });
|
|
71
|
+
|
|
72
|
+
const stream = fs.createReadStream(filePath);
|
|
73
|
+
return mime ? reply.type(mime).send(stream) : stream;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
fastify.get('/assets/*', staticFile);
|
|
77
|
+
fastify.get('/public/*', staticFile);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default plugin;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { dataDelete, getMeta } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
export default async function builderDelete({ user = {}, params = {} }) {
|
|
4
|
+
|
|
5
|
+
if (!params.id) {
|
|
6
|
+
return { message: 'id is required', status: 400 };
|
|
7
|
+
}
|
|
8
|
+
const { pk } = await getMeta({ table: 'site.content_types' });
|
|
9
|
+
|
|
10
|
+
if (!pk) {
|
|
11
|
+
return { message: 'table not found', status: 404 };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const res = await dataDelete({
|
|
15
|
+
table: 'site.content_types',
|
|
16
|
+
id: params.id,
|
|
17
|
+
uid: user?.uid
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return { id: res.content_id, rows: [res] };
|
|
21
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { pgClients, getMeta } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
export default async function builderGet({ pg = pgClients.client, params = {} }) {
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const { pk } = await getMeta({ table: 'site.content_types' });
|
|
7
|
+
|
|
8
|
+
if (!pk) {
|
|
9
|
+
return { message: 'table not found', status: 404 };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const { rows, rowCount: total } = await pg.query(
|
|
13
|
+
`select a.content_type_id as id, a.* FROM site.content_types a
|
|
14
|
+
where a.content_type_id=$1`, [params.id]
|
|
15
|
+
);
|
|
16
|
+
return { message: { total, rows }, status: 200 };
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { pgClients, getMeta } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
export default async function builderList({ pg = pgClients.client, query = {} }) {
|
|
4
|
+
|
|
5
|
+
const { pk } = await getMeta({ table: 'site.content_types' });
|
|
6
|
+
|
|
7
|
+
if (!pk) {
|
|
8
|
+
return { message: 'table not found', status: 404 };
|
|
9
|
+
}
|
|
10
|
+
const sql = `select a.content_type_id as id, a.* FROM site.content_types a
|
|
11
|
+
where ${query.content_type_id ? 'content_type_id=$1' : '1=1'}`
|
|
12
|
+
|
|
13
|
+
const { rows, rowCount: total } = await pg.query(sql, [query.content_type_id].filter((el) => el));
|
|
14
|
+
|
|
15
|
+
return { message: { total, rows }, status: 200 };
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { dataInsert, getMeta } from "@opengis/fastify-table/utils.js";
|
|
2
|
+
|
|
3
|
+
export default async function builderPost(req) {
|
|
4
|
+
const { user = {}, body = {} } = req;
|
|
5
|
+
|
|
6
|
+
const { pk } = await getMeta({ table: "site.content_types" });
|
|
7
|
+
|
|
8
|
+
if (!pk) {
|
|
9
|
+
return { message: "table not found", status: 404 };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const resData = await dataInsert({
|
|
13
|
+
table: "site.content_types",
|
|
14
|
+
data: body,
|
|
15
|
+
uid: user?.uid,
|
|
16
|
+
});
|
|
17
|
+
// console.log(resData);
|
|
18
|
+
const res = resData?.rows[0];
|
|
19
|
+
|
|
20
|
+
return { id: res.content_type_id, rows: [res] };
|
|
21
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { dataUpdate, getMeta } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
export default async function builderPut(req) {
|
|
4
|
+
const { user = {}, body = {}, params = {} } = req;
|
|
5
|
+
if (!params.id) {
|
|
6
|
+
return { message: 'id is required', status: 400 };
|
|
7
|
+
}
|
|
8
|
+
const { pk } = await getMeta({ table: 'site.content_types' });
|
|
9
|
+
|
|
10
|
+
if (!pk) {
|
|
11
|
+
return { message: 'table not found', status: 404 };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const resData = await dataUpdate({
|
|
15
|
+
table: 'site.content_types',
|
|
16
|
+
data: body,
|
|
17
|
+
id: params.id,
|
|
18
|
+
});
|
|
19
|
+
// console.log(resData)
|
|
20
|
+
const res = resData;
|
|
21
|
+
|
|
22
|
+
return { id: res.content_type_id, rows: [res] };
|
|
23
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import cmsBuilderGet from './controllers/cms.builder.get.js';
|
|
2
|
+
import cmsBuilderList from './controllers/cms.builder.list.js';
|
|
3
|
+
import cmsBuilderPut from './controllers/cms.builder.put.js';
|
|
4
|
+
import cmsBuilderPost from './controllers/cms.builder.post.js';
|
|
5
|
+
import cmsBuilderDelete from './controllers/cms.builder.delete.js';
|
|
6
|
+
|
|
7
|
+
export default async function route(app) {
|
|
8
|
+
// builder add
|
|
9
|
+
app.post('/cms-builder', { config: { policy: ['site'] }}, cmsBuilderPost);
|
|
10
|
+
|
|
11
|
+
// builder edit
|
|
12
|
+
app.put('/cms-builder/:id', { config: { policy: ['site'] }}, cmsBuilderPut);
|
|
13
|
+
|
|
14
|
+
// builder list
|
|
15
|
+
app.get('/cms-builder', { config: { policy: ['site'] }}, cmsBuilderList);
|
|
16
|
+
|
|
17
|
+
// builder get
|
|
18
|
+
app.get('/cms-builder/:id', { config: { policy: ['site'] }}, cmsBuilderGet);
|
|
19
|
+
|
|
20
|
+
// builder delete
|
|
21
|
+
app.delete('/cms-builder/:id', { config: { policy: ['site'] }}, cmsBuilderDelete);
|
|
22
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { dataDelete, getMeta } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
export default async function categoryDelete({ user = {}, params = {} }) {
|
|
4
|
+
|
|
5
|
+
if (!params.id) {
|
|
6
|
+
return { message: 'id is required', status: 400 };
|
|
7
|
+
}
|
|
8
|
+
const { pk } = await getMeta({ table: 'site.categories' });
|
|
9
|
+
|
|
10
|
+
if (!pk) {
|
|
11
|
+
return { message: 'table not found', status: 404 };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const res = await dataDelete({
|
|
15
|
+
table: 'site.categories',
|
|
16
|
+
id: params.id,
|
|
17
|
+
uid: user?.uid
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return { id: res.category_id, rows: [res] };
|
|
21
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { pgClients, getMeta, getTemplate } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
export default async function categoryGet({ pg = pgClients.client, params = {} }) {
|
|
4
|
+
|
|
5
|
+
const { pk } = await getMeta({ table: 'site.categories' });
|
|
6
|
+
|
|
7
|
+
if (!pk) {
|
|
8
|
+
return { message: 'table not found', status: 404 };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const { rows, rowCount: total } = await pg.query(
|
|
12
|
+
`select a.category_id as id, a.* FROM site.categories a
|
|
13
|
+
where a.category_id=$1`,
|
|
14
|
+
[params.id]
|
|
15
|
+
);
|
|
16
|
+
return { message: { total, rows }, status: 200 };
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { pgClients, getTemplate, getMeta } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
export default async function categoryList({ pg = pgClients.client, query = {} }) {
|
|
4
|
+
|
|
5
|
+
const { pk } = await getMeta({ table: 'site.categories' });
|
|
6
|
+
|
|
7
|
+
if (!pk) {
|
|
8
|
+
return { message: 'table not found', status: 404 };
|
|
9
|
+
}
|
|
10
|
+
const sql = `select a.category_id as id, a.* FROM site.categories a
|
|
11
|
+
where ${query.category_id ? 'category_id=$1' : '1=1'}`
|
|
12
|
+
|
|
13
|
+
const { rows, rowCount: total } = await pg.query(sql, [query.category_id].filter((el) => el));
|
|
14
|
+
|
|
15
|
+
return { message: { total, rows }, status: 200 };
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { dataInsert, getMeta } from "@opengis/fastify-table/utils.js";
|
|
2
|
+
|
|
3
|
+
export default async function categoryPost(req) {
|
|
4
|
+
const { user = {}, body = {} } = req;
|
|
5
|
+
|
|
6
|
+
const { pk } = await getMeta({ table: "site.categories" });
|
|
7
|
+
|
|
8
|
+
if (!pk) {
|
|
9
|
+
return { message: "table not found", status: 404 };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const resData = await dataInsert({
|
|
13
|
+
table: "site.categories",
|
|
14
|
+
data: body,
|
|
15
|
+
uid: user?.uid,
|
|
16
|
+
});
|
|
17
|
+
// console.log(resData);
|
|
18
|
+
const res = resData?.rows[0];
|
|
19
|
+
|
|
20
|
+
return { id: res.category_id, rows: [res] };
|
|
21
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { dataUpdate, getMeta } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
export default async function categoryPut({ body = {}, params = {} }) {
|
|
4
|
+
|
|
5
|
+
if (!params.id) {
|
|
6
|
+
return { message: 'id is required', status: 400 };
|
|
7
|
+
}
|
|
8
|
+
const { pk } = await getMeta({ table: 'site.categories' });
|
|
9
|
+
|
|
10
|
+
if (!pk) {
|
|
11
|
+
return { message: 'table not found', status: 404 };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const resData = await dataUpdate({
|
|
15
|
+
table: 'site.categories',
|
|
16
|
+
data: body,
|
|
17
|
+
id: params.id,
|
|
18
|
+
});
|
|
19
|
+
// console.log(resData)
|
|
20
|
+
const res = resData;
|
|
21
|
+
|
|
22
|
+
return { id: res.category_id, rows: [res] };
|
|
23
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import cmsCategoryGet from './controllers/cms.category.get.js';
|
|
2
|
+
import cmsCategoryList from './controllers/cms.category.list.js';
|
|
3
|
+
import cmsCategoryPut from './controllers/cms.category.put.js';
|
|
4
|
+
import cmsCategoryPost from './controllers/cms.category.post.js';
|
|
5
|
+
import cmsCategoryDelete from './controllers/cms.category.delete.js'
|
|
6
|
+
|
|
7
|
+
export default async function route(app) {
|
|
8
|
+
// category add
|
|
9
|
+
app.post('/cms-category', {}, cmsCategoryPost);
|
|
10
|
+
|
|
11
|
+
// category edit
|
|
12
|
+
app.put('/cms-category/:id', {}, cmsCategoryPut);
|
|
13
|
+
|
|
14
|
+
// category list
|
|
15
|
+
app.get('/cms-category', { config: { policy: ['site'] }}, cmsCategoryList);
|
|
16
|
+
|
|
17
|
+
// category get
|
|
18
|
+
app.get('/cms-category/:id', {}, cmsCategoryGet);
|
|
19
|
+
|
|
20
|
+
// category delete
|
|
21
|
+
app.delete('/cms-category/:id', { config: { policy: ['site'] }}, cmsCategoryDelete);
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { dataDelete, getMeta } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
export default async function managerDelete({ user = {}, params = {} }) {
|
|
4
|
+
|
|
5
|
+
if (!params.id) {
|
|
6
|
+
return { message: 'id is required', status: 400 };
|
|
7
|
+
}
|
|
8
|
+
const { pk } = await getMeta({ table: 'site.contents' });
|
|
9
|
+
|
|
10
|
+
if (!pk) {
|
|
11
|
+
return { message: 'table not found', status: 404 };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const res = await dataDelete({
|
|
15
|
+
table: 'site.contents',
|
|
16
|
+
id: params.id,
|
|
17
|
+
uid: user?.uid
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
return { id: res.content_id, rows: [res] };
|
|
22
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { pgClients, getMeta } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
export default async function managerGet({ pg = pgClients.client, params = {} }) {
|
|
4
|
+
|
|
5
|
+
if (!params.template && params.id) return { message: 'bad request', status: 400 }
|
|
6
|
+
|
|
7
|
+
const { pk } = await getMeta({ table: 'site.contents' });
|
|
8
|
+
|
|
9
|
+
if (!pk) {
|
|
10
|
+
return { message: 'table not found', status: 404 };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const { rows, rowCount: total } = await pg.query(
|
|
14
|
+
`select a.content_id as id, a.* FROM site.contents a
|
|
15
|
+
where template=$1 and content_id=$2`, [params.template, params.id]
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const { rows: type } = await pg.query(`select name, template, description, type from site.content_types where template=$1`, [params.template])
|
|
19
|
+
|
|
20
|
+
return { message: { total, rows, type: type[0] }, status: 200 };
|
|
21
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { pgClients, getMeta } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
const types = {
|
|
4
|
+
enabled: 'Switcher'
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export default async function builderList({ pg = pgClients.client, params = {} }) {
|
|
8
|
+
if (!params.template) {
|
|
9
|
+
return { message: 'not enougn params: template', status: 400 }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (!pg.pk?.['site.contents']) {
|
|
13
|
+
return { message: 'table not found', status: 404 };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const { columns = [] } = await getMeta({ table: 'site.contents' });
|
|
17
|
+
|
|
18
|
+
const { rows, rowCount: total } = await pg.query(
|
|
19
|
+
`select a.content_id as id, a.* FROM site.contents a
|
|
20
|
+
where template=$1`, [params.template]
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const { rows: type } = await pg.query(`select name, template, description, type, columns from site.content_types where template=$1`, [params.template])
|
|
24
|
+
|
|
25
|
+
const columns1 = (type[0]?.columns || []).concat(
|
|
26
|
+
columns
|
|
27
|
+
.filter(el => !['cdate', 'editor_date', 'uid', 'editor_date'].includes(el.name))
|
|
28
|
+
.map(({ title, name }) => ({ title, name, type: types[name] || 'Text' }))
|
|
29
|
+
);
|
|
30
|
+
return { message: { total, rows, type: type[0], columns: columns1 }, status: 200 };
|
|
31
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { dataInsert, getMeta } from "@opengis/fastify-table/utils.js";
|
|
2
|
+
|
|
3
|
+
export default async function builderPost(req) {
|
|
4
|
+
const { user = {}, params= {}, body = {} } = req;
|
|
5
|
+
|
|
6
|
+
if (!params.template) return { message: 'bad request', status: 400 }
|
|
7
|
+
|
|
8
|
+
const { pk } = await getMeta({ table: "site.contents" });
|
|
9
|
+
|
|
10
|
+
if (!pk) {
|
|
11
|
+
return { message: "table not found", status: 404 };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const bodyModified = Object.assign(body, {
|
|
15
|
+
template: params.template
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
const resData = await dataInsert({
|
|
20
|
+
table: "site.contents",
|
|
21
|
+
data: bodyModified,
|
|
22
|
+
uid: user?.uid,
|
|
23
|
+
});
|
|
24
|
+
// console.log(resData);
|
|
25
|
+
const res = resData?.rows[0];
|
|
26
|
+
|
|
27
|
+
return { id: res.content_id, rows: [res] };
|
|
28
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { dataUpdate, getMeta } from '@opengis/fastify-table/utils.js';
|
|
2
|
+
|
|
3
|
+
export default async function managerPut({ body = {}, params = {} }) {
|
|
4
|
+
|
|
5
|
+
if (!params.id) {
|
|
6
|
+
return { message: 'id is required', status: 400 };
|
|
7
|
+
}
|
|
8
|
+
const { pk } = await getMeta({ table: 'site.contents' });
|
|
9
|
+
|
|
10
|
+
if (!pk) {
|
|
11
|
+
return { message: 'table not found', status: 404 };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const resData = await dataUpdate({
|
|
15
|
+
table: 'site.contents',
|
|
16
|
+
data: body,
|
|
17
|
+
id: params.id,
|
|
18
|
+
});
|
|
19
|
+
// console.log(resData)
|
|
20
|
+
const res = resData;
|
|
21
|
+
|
|
22
|
+
return { id: res.content_id, rows: [res] };
|
|
23
|
+
}
|