createDBController.js 933 B

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