Closed roy-coder closed 7 months ago
This PR exposes existing functionality under getSequelizeFindOptions.
getSequelizeFindOptions
With this, we will be able make further changes for hatchedKoa.parse.findAndCountAll to have something like:
hatchedKoa.parse.findAndCountAll
Input:
"include=user&filter[name]=laundry&fields[Todo]=id,name,dueDate&fields[User]=name&page[number]=3&page[size]=5"
Output:
{ "filter": { "=": ["#name", "laundry"] }, "fields": { "Todo": ["id", "name", "dueDate"], "User": ["name"] }, "page": { "number": 3, "size": 5 }, "sort": [], "include": ["user"], "errors": { "filter": [], "fields": [], "page": [], "sort": [], "include": [] } }
Then hatchedKoa.recordQuery.findAndCountAll will take our ORM-agnostic query, query Sequelize and return plain objects:
hatchedKoa.recordQuery.findAndCountAll
{ "count": 1, "rows": [ { "id": 1, "name": "laundry", "dueDate": "2024-01-01", "user": { "name": "John" } } ] }
And then hatchedKoa.serialize.findAndCountAll will covert it to proper JSONAPI response:
hatchedKoa.serialize.findAndCountAll
{ "jsonapi": { "version": "1.0" }, "meta": { "unpaginatedCount": 1 }, "data": [ ... ], "included": [ ... ] }
Anyone who wants to keep altering the Sequelize queries will have to switch from hatchedKoa.model.Todo to hatchedKoa.orm.models.Todo.
hatchedKoa.model.Todo
hatchedKoa.orm.models.Todo
Decided not to take this path.
This PR exposes existing functionality under
getSequelizeFindOptions
.With this, we will be able make further changes for
hatchedKoa.parse.findAndCountAll
to have something like:Input:
Output:
Then
hatchedKoa.recordQuery.findAndCountAll
will take our ORM-agnostic query, query Sequelize and return plain objects:Input:
Output:
And then
hatchedKoa.serialize.findAndCountAll
will covert it to proper JSONAPI response:Input:
Output:
Anyone who wants to keep altering the Sequelize queries will have to switch from
hatchedKoa.model.Todo
tohatchedKoa.orm.models.Todo
.