deleteBDController.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. const {
  2. Vendor,
  3. VideoCard,
  4. deleteData,
  5. Processor,
  6. selectDataAll,
  7. selectDataAllFiltr,
  8. ErrorStatusOnProcessor,
  9. ProcessorStatusOnLinux,
  10. ErrorStatusOnVideoCard,
  11. VideoCardStatusOnLinux,
  12. logIN,
  13. } = require("./dataBase");
  14. function deleteProcDB(req, res) {
  15. if (logIN) {
  16. const procID = req.params.procID;
  17. selectDataAll(Vendor)
  18. .then((vendor) => {
  19. selectDataAllFiltr(Processor, { id: procID }).then((proc) => {
  20. Vendor.findByPk(proc[0].vendor_id).then((vendorID) =>
  21. res.render("delete.hbs", {
  22. obj: proc[0],
  23. vendor: vendor,
  24. venID: vendorID.companyName,
  25. })
  26. );
  27. });
  28. })
  29. .catch((err) => console.log(err));
  30. } else {
  31. res.redirect("/");
  32. }
  33. }
  34. function deleteVideoCardDB(req, res) {
  35. if (logIN) {
  36. const videoCardID = req.params.videoCardID;
  37. selectDataAll(Vendor)
  38. .then((vendor) => {
  39. selectDataAllFiltr(VideoCard, { id: videoCardID }).then(
  40. (videoCard) => {
  41. Vendor.findByPk(videoCard[0].vendor_id).then(
  42. (vendorID) =>
  43. res.render("delete.hbs", {
  44. obj: videoCard[0],
  45. vendor: vendor,
  46. venID: vendorID.companyName,
  47. })
  48. );
  49. }
  50. );
  51. })
  52. .catch((err) => console.log(err));
  53. } else {
  54. res.redirect("/");
  55. }
  56. }
  57. function postDeleteProcDB(req, res) {
  58. if (logIN) {
  59. console.log("proc");
  60. if (!req.params) return res.sendStatus(400);
  61. console.log(req.params);
  62. ErrorStatusOnProcessor.findAll({
  63. raw: true,
  64. where: { Processor_id: req.params.procID },
  65. })
  66. .then((ESONP) => {
  67. if (ESONP !== null)
  68. ESONP.forEach((el) => {
  69. ErrorStatusOnProcessor.destroy({
  70. where: { id: el.id },
  71. });
  72. });
  73. })
  74. .then(
  75. ProcessorStatusOnLinux.findAll({
  76. where: { Processor_id: req.params.procID },
  77. })
  78. .then((PSOL) => {
  79. if (PSOL !== null)
  80. PSOL.forEach((el) => {
  81. ProcessorStatusOnLinux.destroy({
  82. where: { id: el.id },
  83. });
  84. });
  85. })
  86. .then(() =>
  87. Processor.destroy({ where: { id: req.params.procID } })
  88. )
  89. .then(() => res.redirect("/dataBase/hards"))
  90. );
  91. } else {
  92. res.redirect("/");
  93. }
  94. }
  95. function postDeleteVideoCardDB(req, res) {
  96. if (logIN) {
  97. if (!req.params) return res.sendStatus(400);
  98. console.log(req.params);
  99. ErrorStatusOnVideoCard.findAll({
  100. where: { VideoCard_id: req.params.videoCardID },
  101. })
  102. .then((EROVC) => {
  103. if (EROVC !== null)
  104. EROVC.forEach((el) => {
  105. ErrorStatusOnVideoCard.destroy({
  106. where: { id: el.id },
  107. });
  108. });
  109. })
  110. .then(() =>
  111. VideoCardStatusOnLinux.findAll({
  112. where: { VideoCard_id: req.params.videoCardID },
  113. })
  114. .then((VCSOL) => {
  115. if (VCSOL !== null)
  116. VCSOL.forEach((el) =>
  117. VideoCardStatusOnLinux.destroy({
  118. where: { id: el.id },
  119. })
  120. );
  121. })
  122. .then(
  123. VideoCard.destroy({
  124. where: { id: req.params.videoCardID },
  125. })
  126. )
  127. .then(() => res.redirect("/dataBase/hards"))
  128. );
  129. } else {
  130. res.redirect("/");
  131. }
  132. }
  133. module.exports = {
  134. deleteProcDB,
  135. deleteVideoCardDB,
  136. postDeleteVideoCardDB,
  137. postDeleteProcDB,
  138. };