topic.endpoint.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * 会话接口。
  3. *
  4. * author: Sand
  5. * since: 12/15/2016
  6. */
  7. "use strict";
  8. let express = require('express');
  9. let router = express.Router();
  10. let http = require('http');
  11. let log = require('../util/log.js');
  12. let ObjectUtil = require("../util/object.util.js");
  13. let ControllerUtil = require('../util/controller.util');
  14. let Topics = require('../models/sessions/topics');
  15. const APIv1 = require('../include/endpoints').APIv1;
  16. /**
  17. * 获取用户的聊天列表
  18. */
  19. router.get(APIv1.Topics.Topics,function(req,res){
  20. let topicId = req.query.topicId;
  21. let topic = new Topics();
  22. ControllerUtil.regModelEventHandler(topic, res);
  23. topic.getTopicMessages(topicId);
  24. });
  25. router.post(APIv1.Topics.StartTopic,function(req,res){
  26. let data = req.body;
  27. // data.topicName ="topicstest1";
  28. // data.topicId ="12132312";
  29. // data.healthDoctor ="1";
  30. // data.doctor ="2";
  31. // data.message ={description:"咨询:猥琐大叔大",title:"测试咨询",img:"img/sada.jpg",patient:"topicpatient",patientName:"甘宁"};
  32. //if (!ObjectUtil.isJsonObject(data)) {
  33. // throw {httpStatus: 406, message: 'Problems parsing JSON.'};
  34. //}
  35. //if (!ObjectUtil.isJsonObject(data)) {
  36. // throw {httpStatus: 406, message: 'Problems parsing JSON.'};
  37. //}
  38. //let testing = ObjectUtil.fieldsCheck(data.message, "description", "title", "img", "patient","patientName");
  39. //if (!testing.description) {
  40. // throw {httpStatus: 406, message: "miss message.description"};
  41. //}
  42. //if (!testing.title) {
  43. // throw {httpStatus: 406, message:"miss message.title"};
  44. //}
  45. //if (!testing.patient) {
  46. // throw {httpStatus: 406, message:"miss message.patient"};
  47. //}
  48. //if (!testing.patientName) {
  49. // throw {httpStatus: 406, message:"miss message.patientName"};
  50. //}
  51. let topic = new Topics();
  52. ControllerUtil.regModelEventHandler(topic, res);
  53. topic.createTopics(data.topicName,data.topicId,data.message.patient,data.healthDoctor,data.doctor,data.message);
  54. });
  55. router.get(APIv1.Topics.EndTopic,function(req,res){
  56. let data = req.body;
  57. let endUser = data.endUser;
  58. let endUserName = data.endUserName;
  59. let topicId = data.topicId
  60. let topic = new Topics();
  61. ControllerUtil.regModelEventHandler(topic, res);
  62. topic.endTopic(topicId,endUser,endUserName);
  63. });
  64. module.exports = router;