/** * 会话接口。 * * author: Sand * since: 12/15/2016 */ "use strict"; let express = require('express'); let router = express.Router(); let http = require('http'); let log = require('../util/log.js'); let ObjectUtil = require("../util/object.util.js"); let ControllerUtil = require('../util/controller.util'); let Topics = require('../models/sessions/topics'); const APIv1 = require('../include/endpoints').APIv1; /** * 获取用户的聊天列表 */ router.get(APIv1.Topics.Topics,function(req,res){ let topicId = req.query.topicId; let topic = new Topics(); ControllerUtil.regModelEventHandler(topic, res); topic.getTopicMessages(topicId); }); router.post(APIv1.Topics.StartTopic,function(req,res){ let data = req.body; // data.topicName ="topicstest1"; // data.topicId ="12132312"; // data.healthDoctor ="1"; // data.doctor ="2"; // data.message ={description:"咨询:猥琐大叔大",title:"测试咨询",img:"img/sada.jpg",patient:"topicpatient",patientName:"甘宁"}; //if (!ObjectUtil.isJsonObject(data)) { // throw {httpStatus: 406, message: 'Problems parsing JSON.'}; //} //if (!ObjectUtil.isJsonObject(data)) { // throw {httpStatus: 406, message: 'Problems parsing JSON.'}; //} //let testing = ObjectUtil.fieldsCheck(data.message, "description", "title", "img", "patient","patientName"); //if (!testing.description) { // throw {httpStatus: 406, message: "miss message.description"}; //} //if (!testing.title) { // throw {httpStatus: 406, message:"miss message.title"}; //} //if (!testing.patient) { // throw {httpStatus: 406, message:"miss message.patient"}; //} //if (!testing.patientName) { // throw {httpStatus: 406, message:"miss message.patientName"}; //} let topic = new Topics(); ControllerUtil.regModelEventHandler(topic, res); topic.createTopics(data.topicName,data.topicId,data.message.patient,data.healthDoctor,data.doctor,data.message); }); router.get(APIv1.Topics.EndTopic,function(req,res){ let data = req.body; let endUser = data.endUser; let endUserName = data.endUserName; let topicId = data.topicId let topic = new Topics(); ControllerUtil.regModelEventHandler(topic, res); topic.endTopic(topicId,endUser,endUserName); }); module.exports = router;