homepage.js/routes/articles.js

59 lines
1.4 KiB
JavaScript
Raw Normal View History

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();
2023-03-11 16:54:53 +01:00
res.template('articles/articles.pug', {
2023-02-22 14:55:17 +01:00
current_route: res.originalUrl,
articles
2023-03-11 16:54:53 +01:00
});
2023-02-22 14:55:17 +01:00
}
2023-03-02 14:36:01 +01:00
async function new_article(req, res) {
2023-03-11 16:54:53 +01:00
res.template('admin/data_edit.pug', {
2023-03-02 14:36:01 +01:00
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'
2023-03-11 16:54:53 +01:00
});
2023-03-02 14:36:01 +01:00
}
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
}