Hi team,
I’m facing a problem with a smart collection using the RecordSerializer.
I’m getting my data from an external API, I can print the result but the output from the serialize method is empty.
Here is my code with the url and credentials hidden (routes/merchants.js):
router.get('/merchants', async (request, response, next) => {
const res = await axios.post('https://api.xxxxx.io/client/signin', { login: "xxxxx", password: "xxxxx" })
const merchantsList = await axios.get('https://api.xxxxx.io/cashback/merchants', { headers: { 'api-token': 'xxxxx', 'jwt-token': res.data.jwtToken }});
const merchantsSerializer = new RecordSerializer({ name: 'merchants' });
const merchants = await merchantsSerializer.serialize(merchantsList);
response.send({ ...merchants });
Here is my collection (forest/merchants.js):
const { collection } = require('forest-express-sequelize');
collection('merchants', {
isSearchable: false,
fields: [{
field: 'merchantId',
type: 'Number',
}, {
field: 'isActive',
type: 'Boolean',
}, {
field: 'name',
type: 'String',
}, {
field: 'category',
type: 'String',
}, {
field: 'description',
type: 'String',
}, {
field: 'condition',
type: 'String',
}, {
field: 'image',
type: 'String',
}, {
field: 'websiteUrl',
type: 'String',
}, {
field: 'activationUrl',
type: 'String',
}, {
field: 'online',
type: 'Boolean',
}, {
field: 'addresses',
type: '[\'String\']',
}, {
field: 'externalMerchantSource',
type: 'String',
}, {
field: 'externalMerchantId',
type: 'String',
}, {
field: 'systemAdditionalField',
type: 'String',
}, {
field: 'clientComissionInPercent',
type: 'Number',
}, {
field: 'balanceAlertingAmount',
type: 'Number',
}, {
field: 'balanceAlertingEmails',
type: '[\'String\']',
}],
});
Finally, here is the result of the merchants value from the serialize method:
{ data: { type: 'merchants' } }
Is there a solution to fix this ? Am I missing something from the documentation ?