init
This commit is contained in:
81
src/modules/sysBoard/sysBoard.controller.js
Normal file
81
src/modules/sysBoard/sysBoard.controller.js
Normal 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)
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user