block_lib_facade.js 1010 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Created by CSL on 2018-12-17.
  3. */
  4. let mongoose = require('mongoose');
  5. let blModel = mongoose.model('blockLibsModel');
  6. module.exports = {
  7. getLibNames: getLibNames,
  8. getLib: getLib,
  9. save: save,
  10. saveBlock: saveBlock
  11. };
  12. async function getLibNames(userID, compilationID) {
  13. let libNames = await blModel.find({userID: userID, compilationID: compilationID});
  14. return libNames;
  15. };
  16. async function getLib(libID) {
  17. let lib = await blModel.findOne({libID: libID});
  18. return lib;
  19. };
  20. async function save(data, callback) {
  21. //
  22. };
  23. async function saveBlock(data) {
  24. await blModel.update({libID: data.libID}, {"$addToSet": {"datas": data}});
  25. };
  26. // test Model and write DB functions.
  27. // function cbExec(err) {if (err) {console.log(err)} else {console.log('saved.')}};
  28. // async function testData(obj) {await blModel.create(obj, cbExec)};
  29. // let obj = {"userID":"2164","libID":25,"libName":"模板库25","datas":[],"share":{shareName: 'CSL共享库', shareTo: [2,3,4]}};
  30. // testData(obj);