1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- /**
- * 会话接口。
- *
- * author: Sand
- * since: 12/15/2016
- */
- "use strict";
- let express = require('express');
- let router = express.Router();
- 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 APIv2 = require('../../include/endpoints').APIv2;
- /**
- * 获取用户的聊天列表
- */
- router.get(APIv2.Sessions.Topics, function (req, res) {
- let topicId = req.query.topicId;
- let topic = new Topics();
- ControllerUtil.regModelEventHandler(topic, res);
- topic.getTopicMessages(topicId);
- });
- router.post(APIv2.Sessions.Topics, function (req, res) {
- /**
- * // data.topicName ="topicstest1";
- // data.topicId ="12132312";
- // data.healthDoctor ="1";
- // data.doctor ="2";
- // data.message ={description:"咨询:猥琐大叔大",title:"测试咨询",img:"img/sada.jpg",patient:"topicpatient",patientName:"甘宁"};
- //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 payload = req.body;
- let testing = ObjectUtil.fieldsCheck(payload, "topicId", "topicName", "participants", "messages", "sessionId");
- if (!testing.pass) {
- throw {httpStatus: 406, message: testing.message}
- }
- let topic = new Topics();
- ControllerUtil.regModelEventHandler(topic, res);
- topic.createTopics(payload.topicName, payload.topicId,payload.sessionId,JSON.parse(payload.participants), JSON.parse(payload.messages));
- });
- router.put(APIv2.Sessions.Topics, function (req, res) {
- let data = req.body;
- let topicId = data.topic_id;
- let jsonValue = data.data;
- let topic = new Topics();
- ControllerUtil.regModelEventHandler(topic, res);
- topic.updateTopic(topicId,jsonValue);
- });
- router.post(APIv2.Sessions.TopicEnded, function (req, res) {
- let data = req.body;
- let endUser = data.end_user;
- let endUserName = data.end_user_name;
- let topicId = data.topic_id;
- let topic = new Topics();
- ControllerUtil.regModelEventHandler(topic, res);
- topic.endTopic(topicId, endUser, endUserName);
- });
- module.exports = router;
|