-
Notifications
You must be signed in to change notification settings - Fork 30
Test for Get Api Updated #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Sukriti-sood
wants to merge
4
commits into
Girl-Code-It:develop
Choose a base branch
from
Sukriti-sood:feature
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,10 +32,7 @@ export default async function pagination(queryObject, opportunity) { | |
| limit = parseInt(limit); | ||
| page = parseInt(page); | ||
|
|
||
| // The startIndex is the first index to be rendered from the database | ||
| // skip is the total no of documents/items on each page as per the user | ||
| const startIndex = page - 1; | ||
| const skip = (page - 1) * limit; | ||
|
|
||
|
|
||
| // Object initialised to store the results for various queries | ||
| const result = {}; | ||
|
|
@@ -49,16 +46,17 @@ export default async function pagination(queryObject, opportunity) { | |
|
|
||
| // When limit is less than or equal to the number of Docs | ||
| if (numDocs >= limit) { | ||
| totalPages = Math.floor(numDocs / limit) + (numDocs % limit); | ||
|
|
||
| totalPages = Math.floor(numDocs / limit) + (numDocs % limit === 0 ? 0 : 1); | ||
|
|
||
| } | ||
|
|
||
| // this is the case when limit exceeds the documents , so we only have a single page | ||
| else { | ||
| totalPages = 1; | ||
| } | ||
|
|
||
| // Begin here shows the first index of next Page and helps in determining wether or not it is possible to go on the next page | ||
| let begin = page * limit; | ||
|
|
||
|
|
||
| // If any of the paramter becomes neagtive or Zero | ||
| if (page <= 0 || limit <= 0) { | ||
|
|
@@ -67,43 +65,39 @@ export default async function pagination(queryObject, opportunity) { | |
| } | ||
|
|
||
| // If user enters a Page number greater than the number of Documents present in the Database | ||
| if (startIndex >= numDocs) { | ||
| result.results = 'The maximum page value should be ' + numDocs; | ||
| return result; | ||
| } | ||
|
|
||
| // If the page entered exceeds the Max allowed value(totalPages) | ||
| if (page > totalPages) { | ||
| let maxAllowedPages = totalPages; | ||
| result.results = 'The maximum allowed pages are ' + maxAllowedPages; | ||
| return result; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| // StartIndex should be atleast 0 and for the min val of Page should be 1 | ||
| if (startIndex < 0) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you remove these checks?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Purpose this has been updated in my code. |
||
| if (page <=0) { | ||
|
|
||
| result.results = 'The minimum page value should be 1'; | ||
| return result; | ||
| } | ||
|
|
||
| // Page can't be entered more than the Number of documents present in DataBase | ||
| if (startIndex >= numDocs) { | ||
| result.results = 'The maximum page value should be ' + numDocs; | ||
| return result; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| // If we get valid data we also render the Next and Previous page to the User along with the Results | ||
| else { | ||
| // If there is valid next page in the Database , then we let the user know about it | ||
|
|
||
| if (begin < numDocs) { | ||
| if (page * limit < numDocs) { | ||
| result.next = { | ||
| page: page + 1, | ||
| limit: limit, | ||
| }; | ||
| } | ||
|
|
||
| // If there is valid Previous page in the Database , then we let the user know about it | ||
| if (startIndex > 0) { | ||
|
|
||
| if (page>1) { | ||
| result.previous = { | ||
| page: page - 1, | ||
| limit: limit, | ||
|
|
@@ -114,6 +108,11 @@ export default async function pagination(queryObject, opportunity) { | |
| let query = {}; | ||
| if (queryObject.type) query['opportunityType'] = queryObject.type; | ||
|
|
||
|
|
||
| if(queryObject.opportunityType!=null) | ||
| { | ||
| query={ opportunityType: queryObject.opportunityType,} | ||
| } | ||
| // Once a Valid Query(The one which is inside the Range) is entered, we render the Results | ||
| try { | ||
| result.results = await opportunity.find( | ||
|
|
@@ -122,7 +121,8 @@ export default async function pagination(queryObject, opportunity) { | |
| /* No constraints */ | ||
| }, | ||
| { | ||
| skip: skip, | ||
| skip: limit*(page-1), | ||
|
|
||
| limit: limit, | ||
| } | ||
| ); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.