Add new parameter for detailed company information#77
Conversation
ArkeologeN
left a comment
There was a problem hiding this comment.
Please make the necessary changes.
|
|
||
| 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.
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.
@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.
| 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.
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.
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