Show:

Constructor

JSONSerializer ()

Defined in src/serializer.js:3

Methods

normalizeArrayResponse
(
  • instances
)
Promise

Defined in src/serializer.js:8

Returns an array of Sequelize instances

Parameters:

  • instances Array

    Sequelize instances

Returns:

Promise:

<Object, Error>

Example:

return orm.findAll("user").then(users => {
  return serializer.normalizeArrayResponse(instances);
}).then(response => {
  /**
   * [{
   *   firstName: "foo",
   *   lastName; "bar"
   * }]
});
normalizeResponse
(
  • instance
  • method
)
Promise

Takes one or several Sequelize intances and returns them.

Parameters:

Returns:

Promise:

<Object, Error>

Example:

return orm.findOne("user", 1).then(user => {
  return serializer.normalizeResponse(user, "findOne");
}).then(response => {
  /**
   * {
   *   firstName: "foo",
   *   lastName; "bar"
   * }
})

return orm.findAll("user").then(users => {
  return serializer.normalizeResponse(users, "findAll");
}).then(response => {
  /**
   * [{
   *   firstName: "foo",
   *   lastName: "bar"
   * }]
});
normalizeSingularResponse
(
  • instance
)
Promise

Returns a single sequelize instance

Parameters:

  • instance Object

    Sequelize model instance

Returns:

Promise:

<Object, Error>

Example:

return orm.findOne("user", 1).then(user => {
  return serializer.normalizeSingularResponse(instance, "findOne");
}).then(response => {
  /**
   * {
   *   firstName: "foo",
   *   lastName; "bar"
   * }
});