From 0d470281056601993c7067c0b055226ef8815a42 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 3 Aug 2017 10:44:19 -0700 Subject: [PATCH] removed use of 'deferred' from promises --- controllers/publishController.js | 6 ++---- controllers/serveController.js | 3 +-- controllers/showController.js | 9 +++------ controllers/statsController.js | 3 +-- helpers/functions/getAllFreePublicClaims.js | 3 +-- public/assets/js/validationFunctions.js | 6 ++---- 6 files changed, 10 insertions(+), 20 deletions(-) diff --git a/controllers/publishController.js b/controllers/publishController.js index 13e67c72..f2c61e9c 100644 --- a/controllers/publishController.js +++ b/controllers/publishController.js @@ -20,7 +20,7 @@ function upsert (Model, values, condition) { } function checkNameAvailability (name) { - const deferred = new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { // find any records where the name is used db.File .findAll({ where: { name } }) @@ -50,12 +50,11 @@ function checkNameAvailability (name) { reject(error); }); }); - return deferred; }; module.exports = { publish (publishParams, fileName, fileType) { - const deferred = new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { // 1. make sure the name is available checkNameAvailability(publishParams.name) .then(result => { @@ -108,7 +107,6 @@ module.exports = { reject(error); }); }); - return deferred; }, checkNameAvailability (name) { return checkNameAvailability(name); diff --git a/controllers/serveController.js b/controllers/serveController.js index 3e032d5b..ae737b38 100644 --- a/controllers/serveController.js +++ b/controllers/serveController.js @@ -114,7 +114,7 @@ module.exports = { return getAssetByClaimId(fullClaimId, name); }, serveClaimByName (claimName) { - const deferred = new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { // 1. get the top free, public claims getAllFreePublicClaims(claimName) .then(freePublicClaimList => { @@ -152,6 +152,5 @@ module.exports = { reject(error); }); }); - return deferred; }, }; diff --git a/controllers/showController.js b/controllers/showController.js index 922fcdf7..6ecefc05 100644 --- a/controllers/showController.js +++ b/controllers/showController.js @@ -7,7 +7,7 @@ const serveHelpers = require('../helpers/serveHelpers.js'); module.exports = { showClaimByName (claimName) { - const deferred = new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { // 1. get the top free, public claims getAllFreePublicClaims(claimName) .then(freePublicClaimList => { @@ -51,11 +51,10 @@ module.exports = { reject(error); }); }); - return deferred; }, showClaimByClaimId (name, claimId) { logger.debug(`Getting claim name: ${name} by claimid: ${claimId}`); - const deferred = new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { // 1. check locally for the claim const uri = `${name}#${claimId}`; db.File @@ -107,10 +106,9 @@ module.exports = { }) .catch(error => reject(error)); }); - return deferred; }, showClaimByShortUrl (name, shortUrl) { - const deferred = new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { let uri; let claimId; // 1. validate the claim id & retrieve the full claim id if needed @@ -154,7 +152,6 @@ module.exports = { }) .catch(error => reject(error)); }); - return deferred; }, showAllClaims (claimName) { return getAllFreePublicClaims(claimName); diff --git a/controllers/statsController.js b/controllers/statsController.js index ee50f970..941fd401 100644 --- a/controllers/statsController.js +++ b/controllers/statsController.js @@ -70,7 +70,7 @@ module.exports = { }, getStatsSummary (startDate) { logger.debug('retrieving request records'); - const deferred = new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { // get the raw Requests data db.Request .findAll({ @@ -140,7 +140,6 @@ module.exports = { reject(error); }); }); - return deferred; }, getTrendingClaims (startDate) { logger.debug('retrieving trending requests'); diff --git a/helpers/functions/getAllFreePublicClaims.js b/helpers/functions/getAllFreePublicClaims.js index 120379fa..3c237bd7 100644 --- a/helpers/functions/getAllFreePublicClaims.js +++ b/helpers/functions/getAllFreePublicClaims.js @@ -29,7 +29,7 @@ function orderClaims (claimsListArray) { } module.exports = (claimName) => { - const deferred = new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { // make a call to the daemon to get the claims list lbryApi .getClaimsList(claimName) @@ -58,5 +58,4 @@ module.exports = (claimName) => { reject(error); }); }); - return deferred; }; diff --git a/public/assets/js/validationFunctions.js b/public/assets/js/validationFunctions.js index c16bc4bb..cd9ecb47 100644 --- a/public/assets/js/validationFunctions.js +++ b/public/assets/js/validationFunctions.js @@ -29,7 +29,7 @@ function validateFile(file) { } // validation function that checks to make sure the claim name is not already claimed function isNameAvailable (name) { - var deferred = new Promise(function(resolve, reject) { + return new Promise(function(resolve, reject) { // make sure the claim name is still available var xhttp; xhttp = new XMLHttpRequest(); @@ -50,7 +50,6 @@ function isNameAvailable (name) { }; xhttp.send(); }); - return deferred; } // validation function that checks to make sure the claim name is valid function validateClaimName (name) { @@ -92,7 +91,7 @@ function checkClaimName(name){ } // validation function which checks all aspects of the publish submission function validateSubmission(stagedFiles, name){ - var deferred = new Promise(function (resolve, reject) { + return new Promise(function (resolve, reject) { // make sure only 1 file was selected if (!stagedFiles) { reject(new FileError("Please select a file")); @@ -119,5 +118,4 @@ function validateSubmission(stagedFiles, name){ reject(error); }); }); - return deferred; } \ No newline at end of file