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

Sciper checking #206

Merged
merged 13 commits into from
Dec 14, 2022
Merged

Sciper checking #206

merged 13 commits into from
Dec 14, 2022

Conversation

mamine2207
Copy link
Contributor

No description provided.

@mamine2207 mamine2207 requested a review from a team as a code owner November 9, 2022 06:40
@mamine2207 mamine2207 marked this pull request as draft November 9, 2022 06:40
@coveralls
Copy link

coveralls commented Nov 9, 2022

Pull Request Test Coverage Report for Build 3452171632

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.05%) to 56.825%

Files with Coverage Reduction New Missed Lines %
services/dkg/pedersen/handler.go 3 87.23%
Totals Coverage Status
Change from base Build 3412119124: -0.05%
Covered Lines: 3272
Relevant Lines: 5758

💛 - Coveralls

@mamine2207 mamine2207 changed the title Improvements of the fake and Sciper checking Sciper checking Nov 14, 2022
@mamine2207 mamine2207 marked this pull request as ready for review November 14, 2022 14:57
Copy link
Contributor

@pierluca pierluca left a comment

Choose a reason for hiding this comment

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

Nice little PR. I've added a few suggestions for improvement.

Comment on lines 219 to 235
// The sciper has to contain 6 numbers
if (sciper < 999999 && sciper > 100000) {
// call https://search-api.epfl.ch/api/ldap?q=228271 if the answer
// empty then sciper invalid
axios.get(`https://search-api.epfl.ch/api/ldap?q=${sciper}`).then((response) => {
if (response.data.length === 0) {
res.status(400).send('Unknown sciper');
} else {
usersDB.put(sciper, role).catch((error) => {
res.status(500).send('Failed to add role');
console.log(error);
});
}
});
} else {
res.status(400).send('sciper length incorrect');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

In general, you can reduce indentation by using guard clauses and making the code more readable.
Just a suggestion:

Suggested change
// The sciper has to contain 6 numbers
if (sciper < 999999 && sciper > 100000) {
// call https://search-api.epfl.ch/api/ldap?q=228271 if the answer
// empty then sciper invalid
axios.get(`https://search-api.epfl.ch/api/ldap?q=${sciper}`).then((response) => {
if (response.data.length === 0) {
res.status(400).send('Unknown sciper');
} else {
usersDB.put(sciper, role).catch((error) => {
res.status(500).send('Failed to add role');
console.log(error);
});
}
});
} else {
res.status(400).send('sciper length incorrect');
}
// The sciper has to contain 6 numbers
if (sciper > 999999 || sciper < 100000) {
res.status(400).send('sciper length incorrect');
return;
}
// call https://search-api.epfl.ch/api/ldap?q=228271
// if the answer is empty then the sciper is invalid
axios.get(`https://search-api.epfl.ch/api/ldap?q=${sciper}`).then((response) => {
if (response.data.length === 0) {
res.status(400).send('Unknown sciper');
} else {
usersDB.put(sciper, role).catch((error) => {
res.status(500).send('Failed to add role');
console.log(error);
});
}
});

if (sciper < 999999 && sciper > 100000) {
// call https://search-api.epfl.ch/api/ldap?q=228271 if the answer
// empty then sciper invalid
axios.get(`https://search-api.epfl.ch/api/ldap?q=${sciper}`).then((response) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

what if the get fails ? it seems you don't catch that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I missed this one, I just added a catch in a new commit

Comment on lines 223 to 232
axios.get(`https://search-api.epfl.ch/api/ldap?q=${sciper}`).then((response) => {
if (response.data.length === 0) {
res.status(400).send('Unknown sciper');
} else {
usersDB.put(sciper, role).catch((error) => {
res.status(500).send('Failed to add role');
console.log(error);
});
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

For you information, you can also concatenate promises, by returning a promise from within the body of a then.

This is sometimes more readable, and you can group all the errors in one catch.

Suggested change
axios.get(`https://search-api.epfl.ch/api/ldap?q=${sciper}`).then((response) => {
if (response.data.length === 0) {
res.status(400).send('Unknown sciper');
} else {
usersDB.put(sciper, role).catch((error) => {
res.status(500).send('Failed to add role');
console.log(error);
});
}
});
axios.get(`https://search-api.epfl.ch/api/ldap?q=${sciper}`)
.then((response) => {
if (response.data.length === 0) {
res.status(400).send('Unknown sciper');
return;
}
return usersDB.put(sciper, role);
})
.catch((error) => {
res.status(500).send('Failed to add role');
console.log(error);
});;

@mamine2207 mamine2207 requested a review from pierluca November 14, 2022 19:51
console.log(error);
});

res.status(200).send('Role added');
Copy link
Contributor

Choose a reason for hiding this comment

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

this will also execute in the case of the catch above, don't you want to put in a then (before the catch) ?

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 7, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@mamine2207 mamine2207 requested a review from pierluca December 13, 2022 22:36
@mamine2207 mamine2207 merged commit 6a53a65 into main Dec 14, 2022
@mamine2207 mamine2207 deleted the amine branch December 14, 2022 08:33
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