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 ?
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;
});