editDBController.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. const {
  2. updateData,
  3. Processor,
  4. selectDataAllFiltr,
  5. Vendor,
  6. selectDataAll,
  7. selectDataOne,
  8. VideoCard,
  9. DistroLinux,
  10. ProcessorStatusOnLinux,
  11. VideoCardStatusOnLinux,
  12. } = require("./dataBase");
  13. function editProc(req, res) {
  14. const procID = req.params.procID;
  15. Vendor.findAll()
  16. .then((vendors) => {
  17. Processor.findOne({ where: { id: procID } }).then((proc) => {
  18. Vendor.findByPk(proc.vendor_id).then((vendor) => {
  19. DistroLinux.findAll().then((linux) =>
  20. res.render("Edit.hbs", {
  21. obj: proc,
  22. linux: linux,
  23. vendor: vendors,
  24. venID: vendor.companyName,
  25. })
  26. );
  27. });
  28. });
  29. })
  30. .catch((err) => console.log(err));
  31. }
  32. function editVideoCard(req, res) {
  33. const videoCardID = req.params.videoCardID;
  34. Vendor.findAll()
  35. .then((vendors) => {
  36. VideoCard.findOne({ where: { id: videoCardID } }).then(
  37. (videoCard) => {
  38. Vendor.findByPk(videoCard.vendor_id).then((vendor) => {
  39. DistroLinux.findAll().then((linux) =>
  40. res.render("Edit.hbs", {
  41. obj: videoCard,
  42. linux: linux,
  43. vendor: vendors,
  44. venID: vendor.companyName,
  45. })
  46. );
  47. });
  48. }
  49. );
  50. })
  51. .catch((err) => console.log(err));
  52. }
  53. function postEditProc(req, res) {
  54. if (!req.body) return res.sendStatus(400);
  55. console.log(req.body);
  56. console.log(req.params);
  57. Processor.update(
  58. {
  59. modelName: req.body.modelName,
  60. vendor_id: req.body.Vendor,
  61. },
  62. {
  63. where: {
  64. id: req.params.procID,
  65. },
  66. }
  67. )
  68. .then(() => {
  69. if (req.body.LinuxStatus !== null) {
  70. ProcessorStatusOnLinux.findOne({
  71. where: {
  72. Processor_id: req.params.procID,
  73. DistLinux_id: req.body.linuxVendor,
  74. },
  75. }).then((PSOL) => {
  76. if (PSOL !== null) {
  77. ProcessorStatusOnLinux.update(
  78. { Status: req.body.linuxStatus },
  79. {
  80. where: {
  81. Processor_id: req.params.procID,
  82. DistLinux_id: req.body.linuxVendor,
  83. },
  84. }
  85. );
  86. } else {
  87. ProcessorStatusOnLinux.create({
  88. Processor_id: req.params.procID,
  89. DistLinux_id: req.body.linuxVendor,
  90. Status: req.body.linuxStatus,
  91. });
  92. }
  93. });
  94. }
  95. })
  96. .then(() => res.redirect("/dataBase/hards"));
  97. }
  98. function postEditVideoCard(req, res) {
  99. if (!req.body) return res.sendStatus(400);
  100. console.log(req.body);
  101. console.log(req.params);
  102. VideoCard.update(
  103. {
  104. modelName: req.body.modelName,
  105. vendor_id: req.body.Vendor,
  106. },
  107. {
  108. where: {
  109. id: req.params.videoCardID,
  110. },
  111. }
  112. )
  113. .then(() => {
  114. if (req.body.LinuxStatus !== null) {
  115. VideoCardStatusOnLinux.findOne({
  116. where: {
  117. VideoCard_id: req.params.videoCardID,
  118. DistLinux_id: req.body.linuxVendor,
  119. },
  120. }).then((PSOL) => {
  121. if (PSOL !== null) {
  122. VideoCardStatusOnLinux.update(
  123. { Status: req.body.linuxStatus },
  124. {
  125. where: {
  126. VideoCard_id: req.params.videoCardID,
  127. DistLinux_id: req.body.linuxVendor,
  128. },
  129. }
  130. );
  131. } else {
  132. VideoCardStatusOnLinux.create({
  133. VideoCard_id: req.params.videoCardID,
  134. DistLinux_id: req.body.linuxVendor,
  135. Status: req.body.linuxStatus,
  136. });
  137. }
  138. });
  139. }
  140. })
  141. .then(() => res.redirect("/dataBase/hards"));
  142. }
  143. module.exports = {
  144. editProc,
  145. editVideoCard,
  146. postEditProc,
  147. postEditVideoCard,
  148. };