Personal blog written from scratch using Node.js, Bootstrap, and MySQL. https://jrtechs.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.0 KiB

  1. const utils = require('../utils/utils.js');
  2. const sql = require('../utils/sql');
  3. const qs = require('querystring');
  4. var Promise = require('promise');
  5. module.exports=
  6. {
  7. main: function(res, postData)
  8. {
  9. utils.include(res, "./admin/addCategory.html");
  10. return this.processPost(res, postData);
  11. },
  12. processPost: function(res, postData)
  13. {
  14. return new Promise(function(resolve, reject)
  15. {
  16. var post = qs.parse(postData);
  17. if(post.add_category)
  18. {
  19. var url = post.add_category.replace(/ /i, "-");
  20. var q = "insert into categories (name, url) values " +
  21. "('" + post.add_category + "','" + url + "')";
  22. console.log(q);
  23. if(sql.insert(q) != 0)
  24. {
  25. console.log("category added");
  26. }
  27. else
  28. {
  29. console.log("error adding category");
  30. }
  31. }
  32. resolve();
  33. });
  34. }
  35. };