base-domain
Version:
simple module to help build Domain-Driven Design
64 lines (41 loc) • 1.43 kB
text/coffeescript
'use strict'
Includer = require './includer'
###*
include submodels
EntityCollectionIncluder
Includer
base-domain
###
class EntityCollectionIncluder extends Includer
constructor: ->
super
{ } =
include: ->
Promise.all([
super
])
includeItems: ->
return if .loaded()
items = []
for id in .ids
item = .get(, id)
items.push item if item?
if items.length is .length
.setItems(items)
return
repo =
return if not repo?
if repo.constructor.isSync
items = repo.getByIds(.ids, include: )
if items.length isnt .ids.length
console.warn('EntityCollectionIncluder#include(): some ids were not loaded.')
.setItems(items)
else
return unless .async
return repo.getByIds(.ids, include: ).then (items) =>
if items.length isnt .ids.length
console.warn('EntityCollectionIncluder#include(): some ids were not loaded.')
.setItems(items)
.catch (e) ->
module.exports = EntityCollectionIncluder