Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ErrorsController.js
- //TODO UNCOMMENT AFTER UPDATE TO MONGO 4.x.x
- // const updateErrorPropertiesOnConfigurationChange = function() {
- // //Get Ignored/Priority message arrays
- // const ignoredMessages = getIgnoredMessages(true);
- // const priorityMessages = getPriorityMessages(true);
- // //Queries
- // const ignoredQuery = getUpdateQuery(true, ignoredMessages);
- // const nonIgnoredQuery = getUpdateQuery(false, ignoredMessages);
- // const priorityQuery = getUpdateQuery(true, priorityMessages);
- // const nonPriorityQuery = getUpdateQuery(false, priorityMessages);
- // //Logging messages
- // //Define a session variable for later use
- // let session = null;
- // //Adding these options to a query will ensure that the query you are executing is for the given session
- // let options = null;
- // //Start a session
- // ErrorSchema.db.startSession()
- // .then(_session => {
- // //Set session and options to the outer scope variables so that we can use them while chaining promises
- // session = _session;
- // options = { session, new: true };
- // //Start transaction
- // session.startTransaction();
- // //Check for ignoredMessages
- // if(ignoredMessages && ignoredMessages.length > 0) {
- // //Update the messages which are ignored to isIgnored true
- // const ignoredErrors = ErrorSchema.updateMany(
- // ignoredQuery,
- // { $set: { isIgnored: true } },
- // options
- // );
- // //Update the messages which are not ignored to isIgnored false
- // const nonIngoredErrors = ErrorSchema.updateMany(
- // nonIgnoredQuery,
- // { $set: { isIgnored: false } },
- // options
- // );
- // return Promise.all([ignoredErrors, nonIngoredErrors])
- // }
- // else return [];
- // })
- // .then(values => {
- // if(values.length > 0) {
- // //Check if any of the fields that match the criteria are falsely updated/not updated
- // //Should equal 0, that means that there are no problematic fields
- // //Ignored
- // const checkIgnoredQuery = {...ignoredQuery};
- // checkIgnoredQuery.isIgnored = false;
- // //NonIgnored
- // const checkNonIgnoredQuery = {...nonIgnoredQuery};
- // checkNonIgnoredQuery.isIgnored = true;
- // //Get results for session
- // const checkIgnored = ErrorSchema.count(ignoredQuery).session(session);
- // const checkNonIgnored = ErrorSchema.count(nonIgnoredQuery).session(session);
- // return Promise.all([checkIgnored, checkNonIgnored]);
- // }
- // //Send everything is okay
- // else return [0, 0];
- // })
- // .then(values => {
- // if(values.length > 0 && values[0] === 0 && values[1] === 0) {
- // return;
- // }
- // else throw new Error('Ignored Errors update is faulty.');
- // })
- // .then(() => {
- // session.commitTrasnaction();
- // //can perform extra checks
- // // session.end()??? in the docs says not needed. Maybe mongoose does that on its own.
- // })
- // .catch(err => {
- // res.status(500).json({
- // success: false,
- // error: err
- // });
- // });
- // };
- // const getUpdateQuery = function (status, messageArray) {
- // const query = {};
- // //For Testing
- // query.timeStamp = {};
- // query.timeStamp.$gte = 1570147200000;
- // //
- // if(status === true) {
- // query.message = {}
- // query.message.$in = messageArray;
- // }
- // else if(status === false) {
- // query.message = {}
- // query.message.$nin = messageArray;
- // }
- // else return null;
- // };
- module.exports = {
- //TODO UNCOMMENT AFTER UPDATE TO MONGO 4.x.x
- // updateErrorPropertiesOnConfigurationChange,
- };
- configurationController.js
- //TODO UNCOMMENT AFTER UPDATE TO MONGO 4.x.x
- // updateErrorPropertiesOnConfigurationChange();
- //TODO UNCOMMENT AFTER UPDATE TO MONGO 4.x.x
- // const { validateCreateConfigurationModel } = require('../validation/validationHelper');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement