collection('missingContractCategories', {
isSearchable: true,
actions: [],
fields: [
{
field: 'id',
type: 'String'
},{
field: 'placeReference',
type: 'String',
isFilterable: true
}, {
field: 'display_name',
type: 'String',
isFilterable: true,
}, {
field: 'mandatory',
type: 'Boolean',
isFilterable: true,
// isSortable: true,
// filter: async ({ condition, where }) => {
// const positive = condition.operator === 'equal' && !!condition.value || condition.operator === 'not_equal' && !condition.value
// console.log("🚀 ~ file: missing-contract-categories.js:35 ~ filter: ~ positive:", positive)
// return { mandatory: positive };
// }
}, {
field: 'state',
isFilterable: true,
// type: 'String',
type: 'Enum',
enums: ['active',
'canceled',
'pending_cancellation',
'pending',
'completed',
'archived'
],
isFilterable: true,
},
router.get('/missingContractCategories', permissionMiddlewareCreator.list(), (request, response, next) => {
const recordSerializer = new RecordSerializer({ name: 'missingContractCategories' });
// Get query parameters information
const pageSize = Number(request.query.page.size) || 20;
const page = Number(request.query.page.number) || 1;
const from = (page - 1) * pageSize;
const to = from + pageSize;
//let search = request.query.search;
let sort = request.query.sort;
let filters;
try {
filters = request.query?.filters && JSON.parse(request.query.filters);
console.log("🚀 ~ file: missing-contract-categories.js:25 ~ router.get ~ request.query?.filters:", request.query?.filters)
} catch (e) {
filters = undefined;
}
//console.log("🚀 ~ file: missing-contract-categories.js ~ line 33 ~ router.get ~ filters", filters)
axios.get(
`${API_URL}/forest_admin/missing_categories`, {
headers: {
'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
'X-CURRENT-USER-EMAIL': request.user.email
}
}).then(async res => {
const dataToSend = [];
res.data.map(item => {
const placeReference = item.sergic_id_full;
item.missing_categories.map(categorie => {
const cat = {
id: `${item.id}-${categorie.id}`,
placeReference: placeReference,
display_name: categorie.display_name,
mandatory: categorie.mandatory,
state: categorie.last_maintenance_contract ? categorie.last_maintenance_contract.state : '' ,
reference: categorie.last_maintenance_contract ? categorie.last_maintenance_contract.reference : '',
end_date: categorie.last_maintenance_contract ? categorie.last_maintenance_contract.end_date : null,
origin_date: categorie.last_maintenance_contract ? categorie.last_maintenance_contract .origin_date : null,
amount: categorie.last_maintenance_contract ? categorie.last_maintenance_contract.amount: '',
repartition_key_id: categorie.last_maintenance_contract ? categorie.last_maintenance_contract.repartition_key_id: '',
automatic_renewal: categorie.last_maintenance_contract ? categorie.last_maintenance_contract.automatic_renewal : '',
notice_in_month: categorie.last_maintenance_contract ? categorie.last_maintenance_contract.notice_in_month: ''
};
dataToSend.push(cat);
});
});
response.send({
...(await recordSerializer.serialize(dataToSend.slice(from, to))),
meta: { count: dataToSend.length }
});
}).catch(err => {
if (err.response?.data?.error?.message) {
response.status(400).send(err.response.data.error.message);
} else {
response.status(400).send('Erreur inattendue, veuillez contacter votre administrateur.');
}
});
});