const whiteListUrls = await this.whiteListDomainsRepository.find({ where: {and: [{isActive: true}, {type: 'redirect'}]}, });Este whiteListUrls da una matriz como:
[ 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 } ]whiteListUrls devuelve whiteListDomainId . Quiero cambiar ese nombre de clave a una sola identificación . Además, no podemos sobrescribir whiteListUrls tal como se inicializó desde la consulta de db. Así que a continuación está el enfoque que probé. Pero el error de SonarQube dice "obj: devolver inmediatamente esta expresión en lugar de asignarla a la variable temporal"
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;¿Hay alguna forma mejor optimizada de hacerlo?
obj: devuelve inmediatamente esta expresión en lugar de asignarla a la variable temporal
Lo que significa ese error es que quiere que hagas esto en su lugar:
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; });