Feature(s) impacted
SmartCollection
Observed behavior
The route to my Smartcollection works fine but is displaying an empty list with no fields. The “Fields” tab is neither clickable when trying to edit the layout.
Expected behavior
SmartCollections displaying the expected fields.
Failure Logs
No failure logs, I’ve probably missed something else…
console log of data sent by “get” route :
{
type: ‘pDComment’,
id: ‘110755c2-247d-447a-90da-92471d382f09’,
attributes: {
id: ‘110755c2-247d-447a-90da-92471d382f09’,
description:"Gouverner c'est prévoir". Apparemment, nous n'avons plus de gouvernants depuis quelques décennies...
,
published_at: 2022-07-24T09:50:00.000Z
}
}
…
Context
-
Project name: PolitizrForest
-
Team name: Operations
-
Environment name: Development
-
Agent type & version:
“body-parser”: “1.19.0”,
“chalk”: “~1.1.3”,
“cookie-parser”: “1.4.4”,
“cors”: “2.8.5”,
“debug”: “~4.0.1”,
“dotenv”: “~6.1.0”,
“express”: “~4.17.1”,
“express-jwt”: “6.1.2”,
“forest-cli”: “^3.0.6”,
“forest-express-sequelize”: “^8.0.0”,
“morgan”: “1.9.1”,
“mysql2”: “~2.2.5”,
“require-all”: “^3.0.0”,
“sequelize”: “~5.15.1” -
Recent changes made on your end if any:
I’m trying to get a single view (SQL’s “Union”) of 2 tables (p_d_d_comment + p_d_r_comment => p_d_comment).
I read the documentation to help me, but I’m not familiar with JS coding.
forest/p-d-comment.js :
const { collection } = require('forest-express-sequelize');
const models = require('../models');
// Union of pddcomment & pdrcomment collection
collection('pDComment', {
isSearchable: true,
fields: [{
field: 'id',
type: String,
}, {
field: 'description',
type: String,
}, {
field: 'published_at',
type: Date,
}],
});
routes/p-d-comment.js :
// Grouping of pddcomment & pdrcomment collection
const { RecordSerializer } = require('forest-express-sequelize');
const express = require('express');
const router = express.Router();
const { connections } = require('../models');
const sequelize = connections.default;
router.get('/pDComment', (req, res, next) => {
const limit = parseInt(req.query.page.size) || 20;
const offset = (parseInt(req.query.page.number) - 1) * limit;
const queryType = sequelize.QueryTypes.SELECT;
const queryData = `
SELECT d.uuid as id, d.description as description, d.published_at as published_at
FROM p_d_d_comment as d
UNION
SELECT r.uuid as id, r.description as description, r.published_at as published_at
FROM p_d_r_comment as r
ORDER BY published_at desc
LIMIT ${limit}
OFFSET ${offset}
`;
const queryCount = `
SELECT sum(tbl.tblCount) as count
FROM
(
SELECT count(*) as tblCount from p_d_d_comment
UNION ALL
SELECT count(*) as tblCount from p_d_r_comment
) tbl;
`;
Promise.all([
sequelize.query(queryData, { type: queryType }),
sequelize.query(queryCount, { type: queryType }),
])
.then(async ([pDCommentsList, pDCommentsCount]) => {
const pDCommentSerializer = new RecordSerializer({ name: 'pDComment' });
const pDComments = await pDCommentSerializer.serialize(pDCommentsList);
const count = pDCommentsCount[0].count;
res.send({ ...pDComments, meta:{ count: count }});
})
.catch((err) => next(err));
});
module.exports = router;