JSONSerializer
Table of Contents
Constructor
JSONSerializer
()
Methods
Returns an array of Sequelize instances
Parameters:
-
instances
ArraySequelize instances
Returns:
Promise:
<Object, Error>
Example:
return orm.findAll("user").then(users => {
return serializer.normalizeArrayResponse(instances);
}).then(response => {
/**
* [{
* firstName: "foo",
* lastName; "bar"
* }]
});
Takes one or several Sequelize intances and returns them.
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"
* }]
});
Returns a single sequelize instance
Parameters:
-
instance
ObjectSequelize 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"
* }
});