topic.endpoint.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 log = require('../../util/log.js');
  11. let ObjectUtil = require("../../util/object.util.js");
  12. let ControllerUtil = require('../../util/controller.util');
  13. let Topics = require('../../models/sessions/topics');
  14. const APIv2 = require('../../include/endpoints').APIv2;
  15. /**
  16. * 获取用户的聊天列表
  17. */
  18. router.get(APIv2.Sessions.Topics, function (req, res) {
  19. let topicId = req.query.topicId;
  20. let topic = new Topics();
  21. ControllerUtil.regModelEventHandler(topic, res);
  22. topic.getTopicMessages(topicId);
  23. });
  24. router.post(APIv2.Sessions.Topics, function (req, res) {
  25. /**
  26. * // data.topicName ="topicstest1";
  27. // data.topicId ="12132312";
  28. // data.healthDoctor ="1";
  29. // data.doctor ="2";
  30. // data.message ={description:"咨询:猥琐大叔大",title:"测试咨询",img:"img/sada.jpg",patient:"topicpatient",patientName:"甘宁"};
  31. //let testing = ObjectUtil.fieldsCheck(data.message, "description", "title", "img", "patient","patientName");
  32. //if (!testing.description) {
  33. // throw {httpStatus: 406, message: "miss message.description"};
  34. //}
  35. //if (!testing.title) {
  36. // throw {httpStatus: 406, message:"miss message.title"};
  37. //}
  38. //if (!testing.patient) {
  39. // throw {httpStatus: 406, message:"miss message.patient"};
  40. //}
  41. //if (!testing.patientName) {
  42. // throw {httpStatus: 406, message:"miss message.patientName"};
  43. //}
  44. */
  45. let payload = req.body;
  46. let testing = ObjectUtil.fieldsCheck(payload, "topicId", "topicName", "participants", "messages", "sessionId");
  47. if (!testing.pass) {
  48. throw {httpStatus: 406, message: testing.message}
  49. }
  50. let topic = new Topics();
  51. ControllerUtil.regModelEventHandler(topic, res);
  52. topic.createTopics(payload.topicName, payload.topicId,payload.sessionId,JSON.parse(payload.participants), JSON.parse(payload.messages));
  53. });
  54. router.put(APIv2.Sessions.Topics, function (req, res) {
  55. let data = req.body;
  56. let topicId = data.topic_id;
  57. let jsonValue = data.data;
  58. let topic = new Topics();
  59. ControllerUtil.regModelEventHandler(topic, res);
  60. topic.updateTopic(topicId,jsonValue);
  61. });
  62. router.post(APIv2.Sessions.TopicEnded, function (req, res) {
  63. let data = req.body;
  64. let endUser = data.end_user;
  65. let endUserName = data.end_user_name;
  66. let topicId = data.topic_id;
  67. let topic = new Topics();
  68. ControllerUtil.regModelEventHandler(topic, res);
  69. topic.endTopic(topicId, endUser, endUserName);
  70. });
  71. module.exports = router;