diff --git a/scripts/database/management/management.JS b/scripts/database/management/management.JS index e03c7c1..25e2d8a 100644 --- a/scripts/database/management/management.JS +++ b/scripts/database/management/management.JS @@ -28,6 +28,30 @@ class DBManagement { this[`collection`] = COLLECTION; this.state.then(() => {this.model = this[`connection`].model(`URL`, this[`schema`]);}) } + + /* + Find based on corresponding details. + + @param {object} CRITERIA the search criteria + @param {number} SIZE the size of the search + @return {object} the search results + */ + async search(CRITERIA = {}, SIZE) { + await this.state; + let RESULT = []; + + if ((CRITERIA && CRITERIA instanceof Object) ? !Object.keys(CRITERIA).length : true) { + RESULT = await this.model.find(); + } else if (CRITERIA instanceof Object) { + RESULT = await this.model.find(CRITERIA); + } + + if (RESULT.length && (SIZE) ? (SIZE > 0 && SIZE < RESULT.length) : false) { + RESULT = RESULT.slice(0,n); + } + + return RESULT; + }; } module.exports = DBManagement; \ No newline at end of file diff --git a/scripts/database/management/management_user.JS b/scripts/database/management/management_user.JS index c357201..2c39c51 100644 --- a/scripts/database/management/management_user.JS +++ b/scripts/database/management/management_user.JS @@ -27,7 +27,7 @@ class UsersManagement extends DBManagement { @return {object} the found user */ const checkMatch = async () => { - let RESULTS = await this.match({"name": USERNAME}, 1); + let RESULTS = await this.search({"name": USERNAME}, 1); return ((RESULTS.length) ? RESULTS[0] : false) } @@ -52,28 +52,4 @@ class UsersManagement extends DBManagement { return (CURRENT); }; }; - - /* - Find a user based on their corresponding details. - - @param {object} CRITERIA the search criteria - @param {number} SIZE the size of the search - @return {object} the search results - */ - async match(CRITERIA = {}, SIZE) { - await this.state; - let RESULT = []; - - if ((CRITERIA && CRITERIA instanceof Object) ? !Object.keys(CRITERIA).length : true) { - RESULT = await this.model.find(); - } else if (CRITERIA instanceof Object) { - RESULT = await this.model.find(CRITERIA); - } - - if (RESULT.length && (SIZE) ? (SIZE > 0 && SIZE < RESULT.length) : false) { - RESULT = RESULT.slice(0,n); - } - - return RESULT; - }; } \ No newline at end of file