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

createTag and getTag API #75

Merged
merged 4 commits into from
Dec 12, 2020
Merged

Conversation

ridhishjain-zepto
Copy link
Collaborator

@ridhishjain-zepto ridhishjain-zepto commented Dec 12, 2020

Issue at work: #60

API implemented:

  • createTag
    POST /tag Admin only: create a tag
  • getTag
    GET /tag?search=keyword: search for a tag

Signed-off-by: ridhisjain <[email protected]>
Copy link
Collaborator

@cjchirag7 cjchirag7 left a comment

Choose a reason for hiding this comment

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

Just some minor changes.
Rest LGTM !

server/models/tags/createTag.js Outdated Show resolved Hide resolved
server/models/tags/createTag.js Outdated Show resolved Hide resolved
server/models/tags/getTag.js Outdated Show resolved Hide resolved
server/models/tags/getTag.js Outdated Show resolved Hide resolved
Copy link
Contributor

@NBNARADHYA NBNARADHYA left a comment

Choose a reason for hiding this comment

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

@ridhishjain I think getting tag by id is also necessary I guess. Like check if there is id in search string if so search it by id, otherwise check if search is available and search by search.

server/models/tags/getTag.js Outdated Show resolved Hide resolved
server/models/tags/getTag.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@cjchirag7 cjchirag7 left a comment

Choose a reason for hiding this comment

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

Cool !

@ridhishjain-zepto ridhishjain-zepto merged commit da127b7 into Cyber-Labs:master Dec 12, 2020
const keyword = query.keyword || ''
const searchId = query.id || ''
pool.query(
`SELECT * FROM tags WHERE id LIKE ? AND name LIKE ?`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I meant to say:

let query = ``;
const depArr = [];

if(searchId) {
 query += `SELECT * FROM tags WHERE id = ?`;
 depArr.push(searchId);
} else if(keyword) {
 query += `SELECT * FROM tags LIKE ?`;
 depArr.push(keyword);
}

pool.query(query, depArr, (err, res) => {
 ...
})

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, that's much better !

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

complexity will be same in both cases....

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nope ! this would be a bit faster , as it doesn't have AND , OR in SQL query..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants