{"size": 1799, "ext": "js", "max_stars_repo_path": "server/apis/news.js", "max_stars_repo_name": "ddpicc/haha", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/apis/news.js", "max_issues_repo_name": "ddpicc/haha", "max_issues_repo_issues_event_min_datetime": "2022-02-19T07:28:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T13:47:34.000Z", "max_forks_repo_path": "server/apis/news.js", "max_forks_repo_name": "ddpicc/haha", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 26.8507462687, "max_line_length": 96, "alphanum_fraction": 0.615897721}
const sqlMap = require('../sqlMaps/newsSqlMap');
var db = require('../db/query'); //引入db


module.exports = {
	getAllNews(req, res, next) {
    console.log('api - getAllNews');

		var sql = sqlMap.getAllNews;
		db.query(sql,(err, result) => {
			if(err)
				console.log(err);
			res.json(result);
    })
  },

	getNewsById(req, res, next) {
    console.log('api - getNewsById');
    var id = req.query.id;

		var sql = sqlMap.getNewsById;
		db.query(sql, [id],(err, result) => {
			if(err)
				console.log(err);
			res.json(result);
 
    })
  },

	deleteNewsById(req, res, next) {
    console.log('api - deleteNewsById');
    var id = req.query.id;
      var sql = sqlMap.deleteNewsById;
      db.query(sql, [id], (err, result) => {
        if(err)
          console.log(err);
        res.json(result);
    })
  },

	createNews(req, res, next) {
    console.log('api - createNews');
    var title = req.body.title, summary = req.body.summary;
		var content = req.body.content, created_at = req.body.created_at;
    var stay_top = req.body.stay_top, to_storageNm = req.body.to_storageNm;
    var sql = sqlMap.createNews;
    db.query(sql, [title,summary,content,created_at,stay_top,to_storageNm], (err, result) => {
      if(err)
        console.log(err);
      res.json(result);
    })
  },

	updateNews(req, res, next) {
    console.log('api - updateNews');
    var title = req.body.title, summary = req.body.summary;
		var content = req.body.content, update_at = req.body.update_at;
    var stay_top = req.body.stay_top, to_storageNm = req.body.to_storageNm;
		var id = req.body.blogId;
    var sql = sqlMap.updateNews;
    db.query(sql, [title,summary,content,update_at,stay_top,to_storageNm,id], (err, result) => {
      if(err)
        console.log(err);  
      res.json(result);
    })
  },
}