-
Notifications
You must be signed in to change notification settings - Fork 76
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 new parameter for detailed company information #77
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make the necessary changes.
lib/services/companies.js
Outdated
@@ -56,8 +56,12 @@ | |||
this.createCall('GET', 'companies::(' + query + '):(' + fields.join(',') + ')', {strict: true},cb)(this.config); | |||
}; | |||
|
|||
this.asAdmin = function(cb) { | |||
this.createCall('GET', 'companies', {"is-company-admin": true}, cb)(this.config); | |||
this.asAdmin = function(withDetail, cb) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will break the API because the existing signature for function was function(cb)
but now you added function(withDetai, cb)
, therefore, existing users of the package would suffer.
Please change it into:
this.asAdmin = function asAdmin(withDetail, cb) {
if (arguments.length === 1) {
cb = withDetail;
withDetail = false;
}
}
Please also write test case to verify the assertion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vimalbera92 we cannot change the function definition because the project is already in live usage and the next release would be breaking. So, I suggest checking for argument length to prevent an issue for existing users.
lib/services/companies.js
Outdated
this.asAdmin = function(cb) { | ||
this.createCall('GET', 'companies', {"is-company-admin": true}, cb)(this.config); | ||
this.asAdmin = function(withDetail, cb) { | ||
if(withDetail){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can change it into 1 liner statement:
if (!!withDetail) {
return this.createCall('GET', "companies:(" + fields.join(",") + ")", {"is-company-admin": true, strict: true}, cb)(this.config);
}
return this.createCall('GET', 'companies', {"is-company-admin": true}, cb)(this.config);
You may not need the else
statement as the first executing block returns from function.
// if withDetail parameter is passed in function call, then detail of company will be fetched for which user is administrator. | ||
// so that extra call won't be needed. | ||
this.asAdmin = function(withDetail, cb) { | ||
if(withDetail){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are changing a signature of a function which is already in used.
In order to make it smooth, please put a check something like this:
if (arguments.length === 1) {
cb = withDetail;
withDetail = false;
}
Otherwise, it will break for existing projects.
Hi Hamzah,
Please review and merge it if you find it proper. Let me know if you have any comments.
Thanks,
Vimal