modelUtil.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * 模型类模板代码消除工具。
  3. */
  4. "use strict";
  5. let log = require("./log.js");
  6. let MODEL_EVENTS = require("../include/commons").MODEL_EVENTS;
  7. /**
  8. * 发送模型数据成功获取消息。
  9. *
  10. * @param eventEmitter
  11. * @param data
  12. */
  13. module.exports.emitData = function (eventEmitter, data) {
  14. eventEmitter.emit(MODEL_EVENTS.OK, data);
  15. };
  16. /**
  17. * 发送模型未取得数据消息。
  18. *
  19. * @param eventEmitter
  20. * @param description
  21. */
  22. module.exports.emitDataNotFound = function (eventEmitter, description) {
  23. eventEmitter.emit(MODEL_EVENTS.DataNotFound, description);
  24. };
  25. /**
  26. * 发送模型读取数据失败消息。
  27. *
  28. * @param eventEmitter
  29. * @param err
  30. * @param description
  31. */
  32. module.exports.emitDbError = function (eventEmitter, description, err) {
  33. logError(description, err);
  34. eventEmitter.emit(MODEL_EVENTS.Error, {message: description});
  35. };
  36. /**
  37. * 只记录错误。
  38. *
  39. * @type {logError}
  40. */
  41. function logError(description, err) {
  42. log.error(description, ':', err);
  43. }
  44. module.exports.logError = logError;