Skip to content
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

Fixed Pagination Issue for GetSaveScan API #413

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions v1.0/backend/src/controller/marksController.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,13 @@ exports.getSaveScan = async (req, res, next) => {
match.subject = new RegExp(`^${subject}$`, 'i')
}

if (req.body.page) {
req.body.limit = 10;
req.body.page = 1;
} else {
req.body.limit = 0;
req.body.page = 1;
}
req.body.page=req.body.page || 1
req.body.limit=req.body.limit || 10
// Calculate the total number of records
const totalRecord=(await Marks.find(match)).length;


// Calculate the total number of pages
const totalPages = Math.ceil(totalRecord / req.body.limit);
const savedScan = await Marks.find(match, { _id: 0, __v: 0 })
.limit(parseInt(req.body.limit) * 1)
.skip((parseInt(parseInt(req.body.page)) - 1) * parseInt(parseInt(req.body.limit)))
Expand All @@ -149,11 +147,11 @@ exports.getSaveScan = async (req, res, next) => {
const executionTime2 = endTime - startTime;

logger.info(`Execution time for Get Saved Scan API : ${executionTime2}ms`);
res.status(200).json({ data: savedScan })
res.status(200).json({ data: savedScan , totalRecords:totalRecord, totalPages:totalPages})
} catch (e) {
logger.warn(e)
res.status(400).json({ "error": true, e })
} finally {
next()
}
}
}