In listRepresenter, we call the toJson method. Why don't we do this for Representer?
Argument could be made here that for creation routes, these entities don't have a toJson method, however, this can be simple fixed by returnijng a wrapped entity.
from
to
return wrap(await getById(id));
This comes in especially handy when you have a parent - children entity, that upon initialization has an empty collection. Without the wrap, and with em.create, it will return the parent with an object children, even though it's an array. Wrapping in every create and toJsoning in the representer fixes this.
In listRepresenter, we call the toJson method. Why don't we do this for Representer?
Argument could be made here that for creation routes, these entities don't have a toJson method, however, this can be simple fixed by returnijng a wrapped entity.
from
to
This comes in especially handy when you have a parent - children entity, that upon initialization has an empty collection. Without the wrap, and with em.create, it will return the parent with an object children, even though it's an array. Wrapping in every create and toJsoning in the representer fixes this.