editDBController.js 5.6 KB

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