subjEdit.js 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * РЕДАКТИРОВАНИЕ НАЗВАНИЯ ДОПОЛНИТЕЛЬНОГО ПРЕДМЕТА В КОЛЛЕКЦИИ CURRIC
  3. * Copyright © 2019, А.М.Гольдин. Modified BSD License
  4. */
  5. "use strict";
  6. // Возвращает "success" либо "none"
  7. module.exports = async newSubj => {
  8. try {
  9. // Проверяем, что пришло
  10. const newSubjKey = newSubj[0].trim() || 'a',
  11. newSubjName = newSubj[1].trim() || 'a',
  12. reSubjKey = /^[ds]{1}\d{3}$/,
  13. reSubjName = /^[A-Za-z0-9А-Яа-яЁё(). \-]{2,30}$/;
  14. if (!reSubjKey.test(newSubjKey) || !reSubjName.test(newSubjName))
  15. return "none";
  16. // Проверяем, есть ли такой предмет в коллекции;
  17. // если есть - редактируем, если нет - возвращаем ошибку
  18. let res = await dbFind("curric", {type: "subj", sbKod: newSubjKey});
  19. if (res.length) {
  20. db.curric.update(
  21. {type: "subj", sbKod: newSubjKey},
  22. {type: "subj", sbKod: newSubjKey, sbName: newSubjName}, {}
  23. );
  24. return "success";
  25. }
  26. else return "none";
  27. }
  28. catch(e) {return "none";}
  29. };