dataBaseController.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. const {
  2. selectDataAll,
  3. Vendor,
  4. Processor,
  5. VideoCard,
  6. selectDataOne,
  7. selectDataAllFiltr,
  8. ProcessorStatusOnLinux,
  9. VideoCardStatusOnLinux,
  10. DistroLinux,
  11. Errors,
  12. } = require("./dataBase");
  13. function showHards(req, res) {
  14. selectDataAll(Processor).then((proc) => {
  15. selectDataAll(VideoCard).then((videoCard) => {
  16. res.render("Hards.hbs", {
  17. title: "Hards",
  18. proc: proc,
  19. videoCard: videoCard,
  20. });
  21. });
  22. });
  23. }
  24. function showDistros(req, res) {
  25. selectDataAll(DistroLinux).then((distr) => {
  26. res.render("Distros.hbs", {
  27. title: "Distros",
  28. distr: distr,
  29. });
  30. });
  31. }
  32. function showErrors(req, res) {
  33. selectDataAll(Errors).then((err) => {
  34. res.render("Errors.hbs", {
  35. title: "Errors",
  36. err: err,
  37. });
  38. });
  39. }
  40. function indexDataBase(req, res) {
  41. res.render("dataBase.hbs");
  42. }
  43. function searchDataBase(req, res, next) {
  44. selectDataAll(Vendor)
  45. .then((Vendor) => {
  46. selectDataAll(Processor).then((Processor) => {
  47. selectDataAll(VideoCard).then((VideoCard) => {
  48. res.render("DBsearch.hbs", {
  49. title: "Search",
  50. vendor: Vendor,
  51. processor: Processor,
  52. videoCard: VideoCard,
  53. });
  54. });
  55. });
  56. })
  57. .catch((err) => console.log(err));
  58. }
  59. async function postSearchDataBase(req, res) {
  60. let hardStatus = [];
  61. Processor.findOne({ where: { modelName: req.body.procModel } }).then(
  62. (processor) => {
  63. ProcessorStatusOnLinux.findAll({
  64. where: { Processor_id: processor.id },
  65. })
  66. .then((procStatusLinux) => {
  67. procStatusLinux.forEach((pSL) => {
  68. DistroLinux.findAll({
  69. where: { id: pSL.DistLinux_id },
  70. }).then((procData) => {
  71. hardStatus.push({
  72. hardModel: processor.modelName,
  73. OS: procData[0].vendor,
  74. status: pSL.Status,
  75. });
  76. });
  77. });
  78. })
  79. .then(() => {
  80. VideoCard.findOne({
  81. where: { modelName: req.body.videoCardModel },
  82. }).then((videoCard) => {
  83. VideoCardStatusOnLinux.findAll({
  84. where: { VideoCard_id: videoCard.id },
  85. })
  86. .then((videoCardStatusLinux) => {
  87. videoCardStatusLinux.forEach((vcSL) => {
  88. DistroLinux.findAll({
  89. where: { id: vcSL.DistLinux_id },
  90. }).then((videoCardData) => {
  91. hardStatus.push({
  92. hardModel: videoCard.modelName,
  93. OS: videoCardData[0].vendor,
  94. status: vcSL.Status,
  95. });
  96. });
  97. });
  98. })
  99. .then(() =>
  100. setTimeout(function () {
  101. res.render("results.hbs", {
  102. title: "result",
  103. result: hardStatus,
  104. });
  105. console.log(hardStatus);
  106. }, 2000)
  107. );
  108. });
  109. });
  110. }
  111. );
  112. }
  113. module.exports = {
  114. indexDataBase,
  115. searchDataBase,
  116. postSearchDataBase,
  117. showHards,
  118. showDistros,
  119. showDistros,
  120. showErrors,
  121. };