2023-02-22 14:55:17 +01:00
|
|
|
const handler = require('express-async-handler');
|
|
|
|
const Helpers = require('../helpers');
|
2023-03-02 14:36:01 +01:00
|
|
|
const db = require('../models');
|
2023-02-22 14:55:17 +01:00
|
|
|
const Sequelize = require('../models');
|
|
|
|
|
|
|
|
async function articles(req, res) {
|
|
|
|
|
|
|
|
const articles = await Sequelize.Article.findAll();
|
|
|
|
|
|
|
|
res.send(await Helpers.ViewLoader.load('articles/articles.pug', {
|
|
|
|
current_route: res.originalUrl,
|
|
|
|
articles
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2023-03-02 14:36:01 +01:00
|
|
|
async function new_article(req, res) {
|
|
|
|
res.send(await Helpers.ViewLoader.load('admin/data_edit.pug', {
|
|
|
|
current_route: req.originalUrl,
|
|
|
|
data: {
|
|
|
|
'title': {
|
|
|
|
name: 'Title',
|
|
|
|
type: 'text'
|
|
|
|
},
|
|
|
|
'body': {
|
|
|
|
name: 'Contents',
|
|
|
|
type: 'textarea'
|
|
|
|
},
|
|
|
|
'shortText': {
|
|
|
|
name: 'Short description',
|
|
|
|
type: 'textarea'
|
|
|
|
},
|
|
|
|
'gpgsign': {
|
|
|
|
name: 'Body sign',
|
|
|
|
type: 'codearea'
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
description: 'Write a new article',
|
|
|
|
title: 'New article',
|
|
|
|
endpoint: '/articles/new',
|
|
|
|
pref_method: 'POST'
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
async function new_article_post(req, res) {
|
|
|
|
|
|
|
|
// let data = await db.Article.
|
|
|
|
|
|
|
|
res.send(req.body);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-02-22 14:55:17 +01:00
|
|
|
module.exports = (router) => {
|
|
|
|
router.get('/articles', handler(articles));
|
2023-03-02 14:36:01 +01:00
|
|
|
|
|
|
|
// editor
|
|
|
|
router.get('/articles/new', handler(new_article));
|
|
|
|
router.post('/articles/new', handler(new_article_post));
|
2023-02-22 14:55:17 +01:00
|
|
|
}
|