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

Add new parameter for detailed company information #77

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Add new parameter for detailed company information #77

wants to merge 5 commits into from

Conversation

vimalbera92
Copy link

Hi Hamzah,

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

Thanks,
Vimal

Copy link
Owner

@ArkeologeN ArkeologeN left a 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.

@@ -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) {
Copy link
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
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.

this.asAdmin = function(cb) {
this.createCall('GET', 'companies', {"is-company-admin": true}, cb)(this.config);
this.asAdmin = function(withDetail, cb) {
if(withDetail){
Copy link
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.

// 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
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