We help IT Professionals succeed at work.

Popping the Hood on this Function-  What is getPipelineColumns?

Bruce Gust
Bruce Gust asked
on
Here's the code that I'm working on:

async auth(email, password) {
   1) const isDev = (process.env.ENV == 'local' || process.env.ENV == 'dev');
	//console.log(email);
    2) let match = {
      email: email,
      active: true
    };

    try {
        3) let user = await this.loadUser(match);        
      // validate the password hash
      if (!isDev) {
        await this.checkPasswordHash(password, user.password);
      }

      return this.success(user);
    } catch (err) {
      console.log('Error: ', err);
      return this.error(err);
    }
  }

Open in new window


Here are my questions / explanations. Could you please either "proof" or answer my quandaries?

1 I've not seen this before: const isDev = (process.env.ENV == 'local' || process.env.ENV == 'dev');

I'm assuming it's something similar to a ternary IF statement, but what does it mean? And I'm just shooting from my hip as far as it being a ternary IF statement. Generally, when faced with this kind of thing, I'll refer to https://davidwalsh.name/php-ternary-examples, but this genuinely baffles me.

2 "match" is a variable that houses an array consisting of two key / value pairs: "email" and "active." "email" is one of the arguments being passed into the method, so that's going to be coming from the login page.

3 loadUser looks like this:

  loadUser(match={}) {
    return new Promise( async (resolve, reject) => {
      this.model.aggregate([
        {$match: match},
        {$limit: 1},
        {$lookup: {
          from: '',
          localField: '',
          foreignField: '',
          as: ''
        }},
        {$unwind: '$account'}
      ]).then(async (data) => {
        if (data.length === 0) {
          return reject( 'The provided email address and password combination is invalid. Please try again.' );
        } else if (!data[0].account.active) {
          return reject( 'The parent account is no longer active. Please contact your account administrator.' );
          }           
          4) let pipelineColumns = await this.getPipelineColumns(data[0].account._id);          
          if (pipelineColumns == null || pipelineColumns.length == 0) {
              // Seed built-in user specific pipelineColumn
              pipelineColumns = await this.seedBuiltInPipelineColumns(data[0].account._id);              
          }
          data[0].account.pipelineColumns = pipelineColumns;
          data[0].avatar = typeof data[0].avatar != 'undefined' ? data[0].avatar.length == 0 ? 'https://ui-avatars.com/api/?name=' + data[0].firstName + '%20' + data[0].lastName + '&background=33b5e5&size=200&color=000000' : data[0].avatar : data[0].avatar;
          resolve(data[0]);
      }).catch((err) => {
        console.log('Error: ', err);
        reject( 'An unexpected error was encountered. Please try again.' );
      });
    });
    }

Open in new window


4 (line #19) pipelineColumns is a collection in the database. My question here is "await this.getPipelineColumns..." I'm obviously not looking for the right thing because I started thinking that "getPipelineColumns" was a method, but it's not - at least not that I could find.

So, I shifted gears thinking that it was, perhaps, a Mongodb method, but I couldn't find any documentation to support that idea.

What is it?

Thanks!
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019
Commented:
const isDev = (process.env.ENV == 'local' || process.env.ENV == 'dev');

Open in new window

I'm assuming it's something similar to a ternary IF statement
Nope just a plain old Boolean expression

const isDev = A || B;

Open in new window

If either A OR B is true then isDev will be true. Only if both A AND B are false will isDev be false
A = process.env.ENV == 'local'; // True if process.env.ENV IS set to the string 'local'
B = process.env.ENV == 'dev';  // True if process.env.ENV IS set to the string 'dev'

Open in new window

If process.env.ENV == 'live' then isDev will be false

"match" is a variable that houses an array
At the risk of being pedantic - No - it is set  to an Object - there is a difference.

await this.getPipelineColumns(data[0].account._id);   

Open in new window

this.getPipe... indicates it is a method on the object that loadUser is in. Either in that class or one of its parent classes. 'this' being the key indicator here.
Bruce GustPHP Developer

Author

Commented:
My typical hierarchy looks like this:

Google / Stackoverflow
Experts Exchange
Nate (my boss - exceptional engineer)

Thing is, I like to save Nate for those scenarios that resonate as desperate only because I want to ensure I've done my due diligence so I don't appear either lazy or inept.

That said, I appreciate your time and expertise, Julian!

I did have to go to Nate for the "getPipelineColumns" because, although I had used Agent Ransack to look for that method, I still was able to miss the fact that it's part of the class that "User" extends...

class User extends Service {

Even after you referenced that it was in that class or one of its parent classes, I never saw it in service.js.

But we got it now!

All good!

Thanks!
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
You are welcome.
Bruce GustPHP Developer

Author

Commented:
Excellent!
Bruce GustPHP Developer

Author

Commented:
BTW: Excellent usage of the word, "pedantic." I had to look it up up and hear it's correct pronunciation. I may try to use that in sentence today just to see what the reaction will be.