Skip to content

Add new parameter for detailed company information#77

Open
vimalbera92 wants to merge 5 commits into
ArkeologeN:masterfrom
vimalbera92:master
Open

Add new parameter for detailed company information#77
vimalbera92 wants to merge 5 commits into
ArkeologeN:masterfrom
vimalbera92:master

Conversation

@vimalbera92

Copy link
Copy Markdown

Hi Hamzah,

Please review and merge it if you find it proper. Let me know if you have any comments.

Thanks,
Vimal

@ArkeologeN ArkeologeN left a comment

Copy link
Copy Markdown
Owner

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.

Comment thread lib/services/companies.js

this.asAdmin = function(cb) {
this.createCall('GET', 'companies', {"is-company-admin": true}, cb)(this.config);
this.asAdmin = function(withDetail, cb) {

Copy link
Copy Markdown
Owner

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.

Copy link
Copy Markdown
Owner

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.

Comment thread lib/services/companies.js
this.asAdmin = function(cb) {
this.createCall('GET', 'companies', {"is-company-admin": true}, cb)(this.config);
this.asAdmin = function(withDetail, cb) {
if(withDetail){

Copy link
Copy Markdown
Owner

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.

Comment thread lib/services/companies.js
// 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){

Copy link
Copy Markdown
Owner

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.

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.

2 participants