deleteBDController.js 3.7 KB

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