From e627fa4626c0b6da336e111d79994304426a123e Mon Sep 17 00:00:00 2001 From: b1ek Date: Thu, 2 Mar 2023 23:36:01 +1000 Subject: [PATCH] half baked new article --- models/article.js | 13 ++++++++++++- routes/articles.js | 42 ++++++++++++++++++++++++++++++++++++++++++ view/admin/panel.pug | 2 +- 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/models/article.js b/models/article.js index 9aac7ee..adb74b4 100644 --- a/models/article.js +++ b/models/article.js @@ -1,7 +1,18 @@ const { Model, DataTypes } = require('sequelize'); class Article extends Model { - + /** + * @param {{ + * title: string, + * body: string, + * shortText: string, + * gpgsign: string, + * as: import('./user').class + * }} data + */ + static async writenew(data) { + + } } Article.structure = { diff --git a/routes/articles.js b/routes/articles.js index 47554d7..9ecc0a4 100644 --- a/routes/articles.js +++ b/routes/articles.js @@ -1,5 +1,6 @@ const handler = require('express-async-handler'); const Helpers = require('../helpers'); +const db = require('../models'); const Sequelize = require('../models'); async function articles(req, res) { @@ -12,6 +13,47 @@ async function articles(req, res) { })); } +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; +} + module.exports = (router) => { router.get('/articles', handler(articles)); + + // editor + router.get('/articles/new', handler(new_article)); + router.post('/articles/new', handler(new_article_post)); } \ No newline at end of file diff --git a/view/admin/panel.pug b/view/admin/panel.pug index c4667c4..8ee1085 100644 --- a/view/admin/panel.pug +++ b/view/admin/panel.pug @@ -68,7 +68,7 @@ block content h5 Articles hr p - a(href='/admin/article/new') Create new article + a(href='/articles/new') Create new article if (access_level >= 4) br a(href='/admin/articles.csv') Download data (.CSV)