Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. ErrorsController.js
  2. //TODO UNCOMMENT AFTER UPDATE TO MONGO 4.x.x
  3. // const updateErrorPropertiesOnConfigurationChange = function() {
  4.  
  5.  
  6. // //Get Ignored/Priority message arrays
  7. // const ignoredMessages = getIgnoredMessages(true);
  8. // const priorityMessages = getPriorityMessages(true);
  9.  
  10. // //Queries
  11. // const ignoredQuery = getUpdateQuery(true, ignoredMessages);
  12. // const nonIgnoredQuery = getUpdateQuery(false, ignoredMessages);
  13. // const priorityQuery = getUpdateQuery(true, priorityMessages);
  14. // const nonPriorityQuery = getUpdateQuery(false, priorityMessages);
  15.  
  16. // //Logging messages
  17. // //Define a session variable for later use
  18. // let session = null;
  19. // //Adding these options to a query will ensure that the query you are executing is for the given session
  20. // let options = null;
  21.  
  22. // //Start a session
  23. // ErrorSchema.db.startSession()
  24. // .then(_session => {
  25. // //Set session and options to the outer scope variables so that we can use them while chaining promises
  26. // session = _session;
  27. // options = { session, new: true };
  28. // //Start transaction
  29. // session.startTransaction();
  30. // //Check for ignoredMessages
  31. // if(ignoredMessages && ignoredMessages.length > 0) {
  32.  
  33. // //Update the messages which are ignored to isIgnored true
  34. // const ignoredErrors = ErrorSchema.updateMany(
  35. // ignoredQuery,
  36. // { $set: { isIgnored: true } },
  37. // options
  38. // );
  39.  
  40. // //Update the messages which are not ignored to isIgnored false
  41. // const nonIngoredErrors = ErrorSchema.updateMany(
  42. // nonIgnoredQuery,
  43. // { $set: { isIgnored: false } },
  44. // options
  45. // );
  46.  
  47. // return Promise.all([ignoredErrors, nonIngoredErrors])
  48. // }
  49.  
  50. // else return [];
  51.  
  52. // })
  53. // .then(values => {
  54. // if(values.length > 0) {
  55.  
  56. // //Check if any of the fields that match the criteria are falsely updated/not updated
  57. // //Should equal 0, that means that there are no problematic fields
  58.  
  59. // //Ignored
  60. // const checkIgnoredQuery = {...ignoredQuery};
  61. // checkIgnoredQuery.isIgnored = false;
  62.  
  63. // //NonIgnored
  64. // const checkNonIgnoredQuery = {...nonIgnoredQuery};
  65. // checkNonIgnoredQuery.isIgnored = true;
  66.  
  67. // //Get results for session
  68. // const checkIgnored = ErrorSchema.count(ignoredQuery).session(session);
  69. // const checkNonIgnored = ErrorSchema.count(nonIgnoredQuery).session(session);
  70.  
  71. // return Promise.all([checkIgnored, checkNonIgnored]);
  72. // }
  73.  
  74. // //Send everything is okay
  75. // else return [0, 0];
  76. // })
  77. // .then(values => {
  78. // if(values.length > 0 && values[0] === 0 && values[1] === 0) {
  79. // return;
  80. // }
  81. // else throw new Error('Ignored Errors update is faulty.');
  82. // })
  83. // .then(() => {
  84. // session.commitTrasnaction();
  85. // //can perform extra checks
  86. // // session.end()??? in the docs says not needed. Maybe mongoose does that on its own.
  87. // })
  88. // .catch(err => {
  89. // res.status(500).json({
  90. // success: false,
  91. // error: err
  92. // });
  93. // });
  94.  
  95. // };
  96.  
  97. // const getUpdateQuery = function (status, messageArray) {
  98. // const query = {};
  99.  
  100. // //For Testing
  101. // query.timeStamp = {};
  102. // query.timeStamp.$gte = 1570147200000;
  103. // //
  104.  
  105. // if(status === true) {
  106. // query.message = {}
  107. // query.message.$in = messageArray;
  108. // }
  109. // else if(status === false) {
  110. // query.message = {}
  111. // query.message.$nin = messageArray;
  112. // }
  113. // else return null;
  114. // };
  115.  
  116. module.exports = {
  117. //TODO UNCOMMENT AFTER UPDATE TO MONGO 4.x.x
  118. // updateErrorPropertiesOnConfigurationChange,
  119. };
  120.  
  121. configurationController.js
  122. //TODO UNCOMMENT AFTER UPDATE TO MONGO 4.x.x
  123. // updateErrorPropertiesOnConfigurationChange();
  124.  
  125. //TODO UNCOMMENT AFTER UPDATE TO MONGO 4.x.x
  126. // const { validateCreateConfigurationModel } = require('../validation/validationHelper');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement