Here’s a bunch of smart fields.
fields: [{
field: 'titre',
type: 'String',
get: maintenanceContract => models.providers.findOne({
where: { id: maintenanceContract.providerIdKey }
}).then(provider => axios.get(`${API_URL}/forest_admin/sage_providers`, {
headers: {
'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
'X-CURRENT-USER-EMAIL': process.env.SERVICE_EMAIL
},
params: {
provider_name: '',
siret: '',
matricule: provider ? provider.matricule : ''
}
}).then(res => {
return `${res.data[0].raison_sociale} - ${maintenanceContract.reference}`;
}))
}, {
field: 'Fournisseur',
type: 'String',
get: maintenanceContract => models.providers.findOne({
where: { id: maintenanceContract.providerIdKey }
}).then(provider => axios.get(`${API_URL}/forest_admin/sage_providers`, {
headers: {
'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
'X-CURRENT-USER-EMAIL': process.env.SERVICE_EMAIL
},
params: {
provider_name: '',
siret: '',
matricule: provider ? provider.matricule : ''
}
}).then(res => {
return `${res.data[0].raison_sociale} - ${res.data[0].site_ville}`;
}))
}, {
field: 'raison sociale',
type: 'String',
get: maintenanceContract => models.providers.findOne({
where: { id: maintenanceContract.providerIdKey }
}).then(provider => axios.get(`${API_URL}/forest_admin/sage_providers`, {
headers: {
'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
'X-CURRENT-USER-EMAIL': process.env.SERVICE_EMAIL
},
params: {
provider_name: '',
siret: '',
matricule: provider ? provider.matricule : ''
}
}).then(res => res.data[0].raison_sociale))
}, {
field: 'SIRET',
type: 'String',
get: maintenanceContract => models.providers.findOne({
where: { id: maintenanceContract.providerIdKey }
}).then(provider => axios.get(`${API_URL}/forest_admin/sage_providers`, {
headers: {
'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
'X-CURRENT-USER-EMAIL': process.env.SERVICE_EMAIL
},
params: {
provider_name: '',
siret: '',
matricule: provider ? provider.matricule : ''
}
}).then(res => res.data[0].siret))
}, {
field: 'adresse',
type: 'String',
get: maintenanceContract => models.providers.findOne({
where: { id: maintenanceContract.providerIdKey }
}).then(provider => axios.get(`${API_URL}/forest_admin/sage_providers`, {
headers: {
'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
'X-CURRENT-USER-EMAIL': process.env.SERVICE_EMAIL
},
params: {
provider_name: '',
siret: '',
matricule: provider ? provider.matricule : ''
}
}).then(res => res.data[0].site_adresse))
},
As you can see, there’s an API call for each field. I would like instead call my API once and distribute the gathered information to my smart fields.
At the same time. I want to keep it simple and avoid files dependencies and tedious imbricated asynchronous calls. Is there any Forest Admin standard, compliant, way to do it ?