createDBController.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const {
  2. selectDataAll,
  3. Vendor,
  4. insertData,
  5. Processor,
  6. VideoCard,
  7. logIN,
  8. } = require("./dataBase");
  9. function createDataBase(req, res) {
  10. if (logIN) {
  11. selectDataAll(Vendor)
  12. .then((Vendor) => {
  13. res.render("create.hbs", {
  14. title: "create",
  15. vendor: Vendor,
  16. });
  17. })
  18. .catch((err) => console.log(err));
  19. } else {
  20. res.redirect("/");
  21. }
  22. }
  23. function postCreateDataBase(req, res) {
  24. if (logIN) {
  25. if (!req.body) return res.sendStatus(400);
  26. console.log(req.body);
  27. let newNote = {
  28. modelName: req.body.modelName,
  29. vendor_id: req.body.hardVendor,
  30. };
  31. let Modul;
  32. if (req.body.hardType === "Processor") {
  33. Modul = Processor;
  34. } else if (req.body.hardType === "VideoCard") Modul = VideoCard;
  35. insertData(Modul, newNote);
  36. setTimeout(() => {
  37. res.redirect("/dataBase/hards");
  38. }, 1000);
  39. } else {
  40. res.redirect("/");
  41. }
  42. }
  43. module.exports = {
  44. createDataBase,
  45. postCreateDataBase,
  46. };