Global Contants Implemented

This commit is contained in:
Luis Fernando Molina committed 2021-08-29 17:44:46 +02:00
1 parent 79adad9893
commit 390115d789
7 files changed
+33 -47

No files matched your search

+7 -14
View File
@@ -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 }
+2 -5
View File
@@ -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 }
+2 -5
View File
@@ -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 }
+2 -5
View File
@@ -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 }
+2 -5
View File
@@ -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 }
+13 -1
View File
@@ -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'
}
}
}
}
+5 -12
View File
@@ -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.')
}