This commit is contained in:
chaosBreaking
2019-08-31 14:59:13 +08:00
commit dc5423d356
65 changed files with 3813 additions and 0 deletions

View File

@@ -0,0 +1,81 @@
"use strict";
const Board = require('./sysBoard.model');
module.exports = {
async publish (req, res) {
const { data = {} } = req.body;
new Board(data).save().then(anno => {
return res.json({
code: 0,
data: anno
});
}).catch(err => {
mylog.error(err);
return res.json({
code: 1,
error: JSON.stringify(err)
});
});
},
async getList (req, res) {
const { config } = req.query;
return Board.find(config, 'id title short url option createdAt').then(data => {
return res.json({
code: 0,
data
});
}).catch(err => {
mylog.error(err);
return res.json({
code: 1,
error: JSON.stringify(err)
});
});
},
async getOne (req, res) {
const { id } = req.query;
return Board.findById(id, 'id title url option body author').then(data => {
return res.json({
code: 0,
data
}).catch(err => {
mylog.error(err);
return res.json({
code: 1,
error: JSON.stringify(err)
});
});
});
},
async updateOne (req, res) {
const { id, data } = req.body;
return Board.findByIdAndUpdate(id, data).then(data => {
return res.json({
code: 0,
data
}).catch(err => {
mylog.error(err);
return res.json({
code: 1,
error: JSON.stringify(err)
});
});
});
},
async deleteOne (req, res) {
const { id, data } = req.body;
return Board.findByIdAndDelete(id).then(data => {
return res.json({
code: 0,
data
}).catch(err => {
mylog.error(err);
return res.json({
code: 1,
error: JSON.stringify(err)
});
});
});
},
};

View File

@@ -0,0 +1,31 @@
'use strict';
const mongoose = require('mongoose');
const SysBoardSchema = new mongoose.Schema({
title: {
type: String,
required: true,
},
author: {
type: String,
},
short: {
type: String,
},
url: {
type: String,
},
body: {
type: {}
},
option: {
type: {}
}
},{
timestamps: {}
});
const SysBoardModel = mongoose.model('SysBoard', SysBoardSchema);
module.exports = SysBoardModel;

View File

@@ -0,0 +1,37 @@
"use strict";
const indexRoute = '/sysboard';
const controller = require('./sysBoard.controller');
const services = [
{
url: '/publish',
method: 'POST',
controller: controller.publish
},
{
url: '/update',
method: 'POST',
controller: controller.updateOne
},
{
url: '/list',
method: 'GET',
controller: controller.getList
},
{
url: '/detail',
method: 'GET',
controller: controller.getOne
},
{
url: '/delete',
method: 'POST',
controller: controller.deleteOne
},
];
module.exports = services.map(service => {
// 可以在此处对要导出的服务map进行统一处理
service.url = indexRoute + service.url;
return service;
});