Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
Obj: Immediately return this expression instead of assigning it to the temporary variable
  const whiteListUrls = await this.whiteListDomainsRepository.find({
    where: {and: [{isActive: true}, {type: 'redirect'}]},
  });

This whiteListUrls give a array like:

[
    WhiteListDomain {
    whiteListDomainId: '62b068307bed2ef2c57c4bbf',
    domain: 'go.pampers.com',
    isActive: true,
    type: 'redirect',
    createdDate: 2021-03-25T06:11:53.974Z,
    createdBy: 'thakkar.dt.1@pg.com',
    updatedBy: 'thakkar.dt.1@pg.com',
    updatedDate: 2021-03-25T06:13:53.545Z
    },
    WhiteListDomain {
    whiteListDomainId: '62b068f87bed2ef2c57c4bc0',
    domain: 'app.adjust.com',
    isActive: true,
    type: 'redirect',
    createdDate: 2021-03-25T06:11:53.974Z,
    createdBy: 'thakkar.dt.1@pg.com',
    updatedBy: 'thakkar.dt.1@pg.com',
    updatedDate: 2021-03-25T06:13:53.545Z
    }
]

The whiteListUrls returns whiteListDomainId I want to change that key name to ony id Also we cannot overrwite whiteListUrls as it initialized from the db query. So below is the approach i tried. But SonarQube error says " obj: Immediately return this expression instead of assigning it to the temporary variable"

  interface GetWhiteListesdUrls {
    id: string;
    domain: string;
    isActive: boolean;
    type: string;
    createdDate: string;
    createdBy: string;
    updatedDate: string;
    updatedBy: string;
  }

  const urls = whiteListUrls.map(element => {
    const obj: GetWhiteListesdUrls = {
      id: element.whiteListDomainId!,
      domain: element.domain,
      isActive: element.isActive!,
      type: element.type,
      createdDate: element.createdDate,
      createdBy: element.createdBy,
      updatedDate: element.updatedDate,
      updatedBy: element.updatedBy,
    };
    return obj;
  });
  return urls;

Is there any better optimized way to do it ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

obj: Immediately return this expression instead of assigning it to the temporary variable

What that error means is that it wants you do this instead:

  return whiteListUrls.map(element => {
    const obj: GetWhiteListesdUrls = {
      id: element.whiteListDomainId!,
      domain: element.domain,
      isActive: element.isActive!,
      type: element.type,
      createdDate: element.createdDate,
      createdBy: element.createdBy,
      updatedDate: element.updatedDate,
      updatedBy: element.updatedBy,
    };
    return obj;
  });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!