From c425d48207dba412fe6a98cf81f73282e83f574d Mon Sep 17 00:00:00 2001 From: jbphet Date: Wed, 4 Dec 2019 15:26:38 -0700 Subject: [PATCH] fixed repo list portion of the query for deleting saved strings, see #208 --- js/routeHandlers.js | 2 +- js/stringSubmissionQueue.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/js/routeHandlers.js b/js/routeHandlers.js index 41e542d6..4ea3cc83 100644 --- a/js/routeHandlers.js +++ b/js/routeHandlers.js @@ -336,7 +336,7 @@ module.exports.renderTranslationPage = async function( req, res ) { } ); // create a parameterized query string for retrieving the user's previously saved strings - const savedStringsQuery = 'SELECT * from saved_translations where user_id = $1 AND locale = $2 AND (' + repositories + ')'; + const savedStringsQuery = 'SELECT * FROM saved_translations WHERE user_id = $1 AND locale = $2 AND (' + repositories + ')'; // connect to the database and query for saved strings corresponding to this user and sim let rows = null; diff --git a/js/stringSubmissionQueue.js b/js/stringSubmissionQueue.js index 0842cd60..8e19a503 100644 --- a/js/stringSubmissionQueue.js +++ b/js/stringSubmissionQueue.js @@ -170,6 +170,9 @@ module.exports.stringSubmissionQueue = async ( req, res ) => { /** * delete the strings that are stored in short-term storage + * {string} userID + * {string} locale + * {string[]} simOrLibNames * @private */ async function deleteStringsFromDB( userID, locale, simOrLibNames ) { @@ -178,7 +181,14 @@ async function deleteStringsFromDB( userID, locale, simOrLibNames ) { 'removing strings from short term storage for userID = ' + userID + ', sim/libs = ' + simOrLibNames + ', locale = ' + locale ); - const simOrLibNamesString = simOrLibNames.join( ' OR ' ); + // create a string with all the repo names that can be used in the SQL query + let simOrLibNamesString = ''; + simOrLibNames.forEach( ( simOrLibName, index ) => { + simOrLibNamesString += 'repository = ' + '\'' + simOrLibName + '\''; + if ( index < simOrLibNames.length - 1 ) { + simOrLibNamesString += ' OR '; + } + } ); const deleteQuery = 'DELETE FROM saved_translations WHERE user_id = $1 AND locale = $2 AND (' + simOrLibNamesString + ')'; const pool = new Pool();