glj_repository_model.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * 工料机数据源模块
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/6/23
  6. * @version
  7. */
  8. import BaseModel from "../../common/base/base_model";
  9. import GLJRepositorySchema from "./schemas/glj_repository";
  10. class GLJRepositoryModel extends BaseModel {
  11. /**
  12. * 构造函数
  13. *
  14. * @return {void}
  15. */
  16. constructor() {
  17. let parent = super();
  18. parent.model = GLJRepositorySchema;
  19. parent.init();
  20. }
  21. /**
  22. * 新增数据
  23. *
  24. * @param {object} data
  25. * @return {Promise} boolean
  26. */
  27. async add(data) {
  28. let result = false;
  29. try {
  30. result = await this.db.create(data);
  31. } catch (error) {
  32. if (error.name !== null && error.name === 'ValidationError') {
  33. // 这里是数据验证失败
  34. console.log('数据验证失败!');
  35. }
  36. result = false;
  37. }
  38. return result;
  39. }
  40. /**
  41. * 根据条件获取对应工料机数据
  42. *
  43. * @param {Object} condition
  44. * @return {Promise} Array
  45. */
  46. async getDataByCondition(condition) {
  47. let gljData = [];
  48. try {
  49. if (Object.keys(condition).length <= 0) {
  50. throw '筛选条件有误';
  51. }
  52. gljData = await this.db.find(condition);
  53. } catch (error) {
  54. console.log(error);
  55. gljData = [];
  56. }
  57. return gljData;
  58. }
  59. }
  60. export default GLJRepositoryModel;