I have a collection of users. Each user has a cards
array, which is composed of the id
s of the cards that the user chose.
user.cards = [10, 12, 24, 31]
I want to have the 10 cards that are the most chosen by users.
I have user.service.js
and card.service.js
, which I guess are DAOs. card.service.js
looks something like this (used plain Promises
for simplicity).
(function(app) {
app.CardService = ng.core.Injectable({}).Class({
constructor: function() {},
getCards: function() {
return Promise.resolve(app.cards)
},
getCard: function(cardId) {
return Promise.resolve(app.cards.get(cardId));
},
getTop10Cards: function() {
// How would I go about doing this method?
}
})
})(window.app || (window.app = {}));
Logically, I would need the list of all the users, collect their cardIds
and aggregate them to find the most used cards. But should CardService
use UserService
(as an injection)? Or is using a DAO in another DAO the wrong way to go about it? Should I have a separate collection that contains the links between each models (like a joint table)?