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

Add total number lines changed since #202

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
23 changes: 22 additions & 1 deletion api/controllers/shabads.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ exports.search = async (req, res) => {

if (searchQuery) {
if (searchType === 0) {
// First letter start
// First letter start=> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=>{} not needed in this comment

// }
const queryObj = lib.searchOperators.firstLetterStartToQuery(
charCodeQuery,
charCodeQueryWildCard,
Expand Down Expand Up @@ -600,3 +601,23 @@ const getNavigation = async (req, res, type, first, last, source = '') => {
}
return {};
};

exports.updates = async (req, res) => {
let conn;
const { Date } = req.params;

try {
conn = await req.app.locals.pool.getConnection();

if (!Date) res.json({ error: 'please enter valid date' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use lib.error here with status code 400. Make the error message "Date not specified."

const query = `SELECT COUNT(*) FROM Verse WHERE Updated >= '${Date}'`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably use a parameterized query and/or do more thorough input sanitization on line 612

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some input sanitization that need to be done

  • Date in the future
  • Date not formatted properly.

both of those should return 422 with appropriate messages.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do i check if the date is formatted correctly? Do i have to use some regex thingy or something else?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const dbCount = await conn.query(query);

res.json({ updatedVerses: dbCount[0]['COUNT(*)'] });
} catch (err) {
lib.error(err, res, 500);
} finally {
if (conn) conn.end();
}
};
2 changes: 2 additions & 0 deletions api/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ route.get('/search/:query', limiter.rate250, shabads.search);

route.get('/shabads/:ShabadID', limiter.rate100, shabads.shabads);

route.get('/shabads/updates/:Date', limiter.rate100, shabads.updates);

route.get('/angs/:PageNo/:SourceID?', limiter.rate100, shabads.angs);

route.get('/hukamnamas/:year?/:month?/:day?', limiter.rate100, shabads.hukamnamas);
Expand Down