labour_coe_facade.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * Created by CSL on 2017-10-10.
  3. */
  4. const uuidV1 = require('uuid/v1');
  5. let logger = require("../../../logs/log_helper").logger;
  6. let mongoose = require('mongoose');
  7. let stdLabourCoesModel = mongoose.model('std_labour_coes');
  8. let projectLabourCoesModel = mongoose.model('labour_coes');
  9. module.exports = {
  10. newProjectLabourCoe: newProjectLabourCoe,
  11. getProjectLabourCoe: getProjectLabourCoe,
  12. getStdLabourCoe: getStdLabourCoe
  13. };
  14. async function newProjectLabourCoe(data) {
  15. let stdLC = await getStdLabourCoe(data.libID);
  16. let doc={
  17. ID: uuidV1(),
  18. projectID: data.projectID,
  19. name: data.name,
  20. libID: stdLC.ID,
  21. libName: stdLC.libName,
  22. coes: stdLC.coes
  23. };
  24. console.log(doc);
  25. await projectLabourCoesModel.create(doc);
  26. let newLC = {ID: doc.ID, name: doc.name};
  27. return newLC;
  28. };
  29. async function getProjectLabourCoe(ID) {
  30. let projLC = await projectLabourCoesModel.findOne({ID:ID});
  31. return projLC;
  32. };
  33. async function getStdLabourCoe(libID) {
  34. let stdLC = await stdLabourCoesModel.findOne({ID:libID});
  35. return stdLC;
  36. };