From 390115d789b7ee37525d3ee2d38f20b343af8845 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Aug 2021 17:44:46 +0200 Subject: [PATCH] Global Contants Implemented --- Network/Queries/Events.js | 21 +++++++-------------- Network/Queries/PostReplies.js | 7 ++----- Network/Queries/ProfileFollowers.js | 7 ++----- Network/Queries/ProfileFollowing.js | 7 ++----- Network/Queries/ProfilePosts.js | 7 ++----- Network/SocialGraphNetwokNode.js | 14 +++++++++++++- Network/Utilities/QueriesValidations.js | 17 +++++------------ 7 files changed, 33 insertions(+), 47 deletions(-) diff --git a/Network/Queries/Events.js b/Network/Queries/Events.js index ee80312c7..87b85f484 100644 --- a/Network/Queries/Events.js +++ b/Network/Queries/Events.js @@ -10,13 +10,6 @@ exports.newEvents = function newEvents() { finalize: finalize } - const INITIAL_EVENT_INDEX_FIRST = 'First' - const INITIAL_EVENT_INDEX_LAST = 'Last' - const MIN_AMOUNT_REQUESTED = 1 - const MAX_AMOUNT_REQUESTED = 100 - const DIRECTION_FUTURE = 'Future' - const DIRECTION_PAST = 'Past' - return thisObject function finalize() { @@ -43,11 +36,11 @@ exports.newEvents = function newEvents() { throw ('Initial Index Undefined.') } - if (queryReceived.initialIndex === INITIAL_EVENT_INDEX_LAST) { + if (queryReceived.initialIndex === NT.globals.constants.queries.INITIAL_INDEX_LAST) { queryReceived.initialIndex = thisObject.profile.posts.length - 1 } - if (queryReceived.initialIndex === INITIAL_EVENT_INDEX_FIRST) { + if (queryReceived.initialIndex === NT.globals.constants.queries.INITIAL_INDEX_FIRST) { queryReceived.initialIndex = 0 } @@ -67,11 +60,11 @@ exports.newEvents = function newEvents() { throw ('Amount Requested Is Not a Number.') } - if (queryReceived.amountRequested < MIN_AMOUNT_REQUESTED) { + if (queryReceived.amountRequested < NT.globals.constants.queries.MIN_AMOUNT_REQUESTED) { throw ('Amount Requested Below Min.') } - if (queryReceived.amountRequested > MAX_AMOUNT_REQUESTED) { + if (queryReceived.amountRequested > NT.globals.constants.queries.MAX_AMOUNT_REQUESTED) { throw ('Amount Requested Above Max.') } /* @@ -81,7 +74,7 @@ exports.newEvents = function newEvents() { throw ('Direction Undefined.') } - if (queryReceived.direction !== DIRECTION_FUTURE && queryReceived.direction !== DIRECTION_PAST) { + if (queryReceived.direction !== NT.globals.constants.queries.DIRECTION_FUTURE && queryReceived.direction !== NT.globals.constants.queries.DIRECTION_PAST) { throw ('Direction Not Supported.') } @@ -92,7 +85,7 @@ exports.newEvents = function newEvents() { function execute() { let response = [] switch (thisObject.direction) { - case DIRECTION_FUTURE: { + case NT.globals.constants.queries.DIRECTION_FUTURE: { for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) { let event = NT.memory.arrays.EVENTS[i] if (event === undefined) { break } @@ -100,7 +93,7 @@ exports.newEvents = function newEvents() { } break } - case DIRECTION_PAST: { + case NT.globals.constants.queries.DIRECTION_PAST: { for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { let event = NT.memory.arrays.EVENTS[i] if (event === undefined) { break } diff --git a/Network/Queries/PostReplies.js b/Network/Queries/PostReplies.js index 6eb79e96c..41a4f06a9 100644 --- a/Network/Queries/PostReplies.js +++ b/Network/Queries/PostReplies.js @@ -15,9 +15,6 @@ exports.newPostReplies = function newPostReplies() { finalize: finalize } - const DIRECTION_FUTURE = 'Future' - const DIRECTION_PAST = 'Past' - return thisObject function finalize() { @@ -39,7 +36,7 @@ exports.newPostReplies = function newPostReplies() { let array = Array.from(thisObject.post.replies) switch (thisObject.direction) { - case DIRECTION_FUTURE: { + case NT.globals.constants.queries.DIRECTION_FUTURE: { for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) { let arrayItem = array[i] if (post === undefined) { break } @@ -47,7 +44,7 @@ exports.newPostReplies = function newPostReplies() { } break } - case DIRECTION_PAST: { + case NT.globals.constants.queries.DIRECTION_PAST: { for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { let arrayItem = array[i] if (post === undefined) { break } diff --git a/Network/Queries/ProfileFollowers.js b/Network/Queries/ProfileFollowers.js index 371bfde95..3fc0a3a9d 100644 --- a/Network/Queries/ProfileFollowers.js +++ b/Network/Queries/ProfileFollowers.js @@ -10,9 +10,6 @@ exports.newProfileFollowers = function newProfileFollowers() { finalize: finalize } - const DIRECTION_FUTURE = 'Future' - const DIRECTION_PAST = 'Past' - return thisObject function finalize() { @@ -32,7 +29,7 @@ exports.newProfileFollowers = function newProfileFollowers() { let array = Array.from(thisObject.profile.followers) switch (thisObject.direction) { - case DIRECTION_FUTURE: { + case NT.globals.constants.queries.DIRECTION_FUTURE: { for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) { let arrayItem = array[i] if (arrayItem === undefined) { break } @@ -40,7 +37,7 @@ exports.newProfileFollowers = function newProfileFollowers() { } break } - case DIRECTION_PAST: { + case NT.globals.constants.queries.DIRECTION_PAST: { for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { let arrayItem = array[i] if (arrayItem === undefined) { break } diff --git a/Network/Queries/ProfileFollowing.js b/Network/Queries/ProfileFollowing.js index 09c6d29d7..4fea1534d 100644 --- a/Network/Queries/ProfileFollowing.js +++ b/Network/Queries/ProfileFollowing.js @@ -10,9 +10,6 @@ exports.newProfileFollowing = function newProfileFollowing() { finalize: finalize } - const DIRECTION_FUTURE = 'Future' - const DIRECTION_PAST = 'Past' - return thisObject function finalize() { @@ -32,7 +29,7 @@ exports.newProfileFollowing = function newProfileFollowing() { let array = Array.from(thisObject.profile.following) switch (thisObject.direction) { - case DIRECTION_FUTURE: { + case NT.globals.constants.queries.DIRECTION_FUTURE: { for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) { let arrayItem = array[i] if (arrayItem === undefined) { break } @@ -40,7 +37,7 @@ exports.newProfileFollowing = function newProfileFollowing() { } break } - case DIRECTION_PAST: { + case NT.globals.constants.queries.DIRECTION_PAST: { for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { let arrayItem = array[i] if (arrayItem === undefined) { break } diff --git a/Network/Queries/ProfilePosts.js b/Network/Queries/ProfilePosts.js index 02e8fcfe0..bbeded5d4 100644 --- a/Network/Queries/ProfilePosts.js +++ b/Network/Queries/ProfilePosts.js @@ -14,9 +14,6 @@ exports.newProfilePosts = function newProfilePosts() { finalize: finalize } - const DIRECTION_FUTURE = 'Future' - const DIRECTION_PAST = 'Past' - return thisObject function finalize() { @@ -35,7 +32,7 @@ exports.newProfilePosts = function newProfilePosts() { let array = Array.from(thisObject.profile.posts) switch (thisObject.direction) { - case DIRECTION_FUTURE: { + case NT.globals.constants.queries.DIRECTION_FUTURE: { for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) { let arrayItem = array[i] if (arrayItem === undefined) { break } @@ -43,7 +40,7 @@ exports.newProfilePosts = function newProfilePosts() { } break } - case DIRECTION_PAST: { + case NT.globals.constants.queries.DIRECTION_PAST: { for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { let arrayItem = array[i] if (arrayItem === undefined) { break } diff --git a/Network/SocialGraphNetwokNode.js b/Network/SocialGraphNetwokNode.js index 7073ba1a9..3b3de0575 100644 --- a/Network/SocialGraphNetwokNode.js +++ b/Network/SocialGraphNetwokNode.js @@ -28,7 +28,19 @@ global.NT = { QUERY_EVENTS: require('./Queries/Events.js') }, utilities: { - queriesValidations: require('./Utilities/QueriesValidations.js').newProfileQueries() + queriesValidations: require('./Utilities/QueriesValidations.js').newProfileQueries() + }, + globals: { + constants: { + queries: { + INITIAL_INDEX_FIRST: 'First', + INITIAL_INDEX_LAST: 'Last', + MIN_AMOUNT_REQUESTED: 1, + MAX_AMOUNT_REQUESTED: 100, + DIRECTION_FUTURE: 'Future', + DIRECTION_PAST: 'Past' + } + } } } diff --git a/Network/Utilities/QueriesValidations.js b/Network/Utilities/QueriesValidations.js index ba0934ec9..618c1759b 100644 --- a/Network/Utilities/QueriesValidations.js +++ b/Network/Utilities/QueriesValidations.js @@ -6,13 +6,6 @@ exports.newProfileFollowers = function newProfileFollowers() { arrayValidations: arrayValidations } - const INITIAL_POST_INDEX_FIRST = 'First' - const INITIAL_POST_INDEX_LAST = 'Last' - const MIN_AMOUNT_REQUESTED = 1 - const MAX_AMOUNT_REQUESTED = 100 - const DIRECTION_FUTURE = 'Future' - const DIRECTION_PAST = 'Past' - return thisObject function profilesValidations(queryReceived, thisObject) { @@ -56,11 +49,11 @@ exports.newProfileFollowers = function newProfileFollowers() { throw ('Initial Index Undefined.') } - if (queryReceived.initialIndex === INITIAL_POST_INDEX_LAST) { + if (queryReceived.initialIndex === NT.globals.constants.queries.INITIAL_INDEX_LAST) { queryReceived.initialIndex = thisObject.profile.posts.length - 1 } - if (queryReceived.initialIndex === INITIAL_POST_INDEX_FIRST) { + if (queryReceived.initialIndex === NT.globals.constants.queries.INITIAL_INDEX_FIRST) { queryReceived.initialIndex = 0 } @@ -80,11 +73,11 @@ exports.newProfileFollowers = function newProfileFollowers() { throw ('Amount Requested Is Not a Number.') } - if (queryReceived.amountRequested < MIN_AMOUNT_REQUESTED) { + if (queryReceived.amountRequested < NT.globals.constants.queries.MIN_AMOUNT_REQUESTED) { throw ('Amount Requested Below Min.') } - if (queryReceived.amountRequested > MAX_AMOUNT_REQUESTED) { + if (queryReceived.amountRequested > NT.globals.constants.queries.MAX_AMOUNT_REQUESTED) { throw ('Amount Requested Above Max.') } /* @@ -94,7 +87,7 @@ exports.newProfileFollowers = function newProfileFollowers() { throw ('Direction Undefined.') } - if (queryReceived.direction !== DIRECTION_FUTURE && queryReceived.direction !== DIRECTION_PAST) { + if (queryReceived.direction !== NT.globals.constants.queries.DIRECTION_FUTURE && queryReceived.direction !== NT.globals.constants.queries.DIRECTION_PAST) { throw ('Direction Not Supported.') }