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.

47 lines
1.3 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. /**
  13. * Checks for post data regarding adding a new category.
  14. * If a post is made with add_category, it parses the url-- replaces spaces
  15. * with dashes -- and calls a insert method on the database
  16. *
  17. * @param res
  18. * @param postData
  19. * @return {*|Promise}
  20. */
  21. processPost: function(res, postData)
  22. {
  23. return new Promise(function(resolve, reject)
  24. {
  25. var post = qs.parse(postData);
  26. if(post.add_category)
  27. {
  28. var url = post.add_category.replace(/ /i, "-");
  29. var q = "insert into categories (name, url) values " +
  30. "('" + post.add_category + "','" + url + "')";
  31. console.log(q);
  32. if(sql.insert(q) != 0)
  33. {
  34. console.log("category added");
  35. }
  36. else
  37. {
  38. console.log("error adding category");
  39. }
  40. }
  41. resolve(postData);
  42. });
  43. }
  44. };