Last active
May 3, 2018 16:37
-
-
Save viniceosm/b9efa860eaa6e899f0fcd8edd02c9c43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Recjs(usuarios, itens, interacao) { | |
Object.assign(this, { usuarios, itens, interacao }); | |
} | |
Recjs.prototype.getAllUsuarios = function() { | |
return this.usuarios; | |
} | |
Recjs.prototype.recomendarPara = function(usuario) { | |
var filtradoApartirAmigos = filtrarPorAmigos(usuario); //interacao filtrada | |
filtradoApartirAmigos = filtradoApartirAmigos.sort(function (a, b) { | |
return a.item.value - b.item.value; | |
}); | |
filtradoApartirAmigos = filtradoApartirAmigos.map(function (o) { | |
return populate(o); | |
}); | |
return filtradoApartirAmigos; | |
// populate do mongoose | |
function populate(o) { | |
var nO = o; | |
var referencesKey = Object.keys(o).filter(function (key) { | |
return typeof o[key] == 'object'; | |
}); | |
referencesKey.map(function (key) { | |
var tabelaDaReference = eval(o[key].reference); | |
nO[key] = findById(tabelaDaReference, o[key].value); | |
}); | |
return nO; | |
} | |
function findById(arr, id) { | |
return arr.filter(function (o) { | |
return (o.id == id); | |
})[0]; | |
} | |
function filtrarPorAmigos(usuario) { | |
return this.interacao.filter(function (o) { | |
return usuario.amigos.includes(o.usuario.value); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
resultado