Skip to content

Commit

Permalink
feat: documents table type hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanoshadjipetrou committed Jun 4, 2024
1 parent 5f738e1 commit a5fce5b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/config/mapping/documents/list.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"dataPath": "value",
"type": "documentType.parent.name",
"subType": "documentType.name",
"title": "title",
"url": "url",
"geography": "geography.name",
"urlParams": "?$apply=filter(<filterString>)/groupby((geography/name,documentType/index,documentType/parent/name,title,url))&$orderby=documentType/index asc,title asc"
"urlParams": "?$apply=filter(<filterString>)/groupby((geography/name,documentType/index,documentType/parent/name,documentType/name,title,url))&$orderby=documentType/index asc,title asc"
}
37 changes: 25 additions & 12 deletions src/controllers/documents.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,33 @@ export class DocumentsController {
);

return {
data: _.map(groupedByLocation, (value, key) => {
const groupedByType = _.groupBy(value, DocumentsListMapping.type);
data: _.map(groupedByLocation, (locationObj, location) => {
const groupedByType = _.groupBy(
locationObj,
DocumentsListMapping.type,
);

return {
name: key,
documents: Object.keys(value).length,
_children: _.map(groupedByType, (value1, key) => ({
name: key,
documents: Object.keys(value1).length,
_children: _.map(value1, value2 => ({
name: _.get(value2, DocumentsListMapping.title, ''),
documents: _.get(value2, DocumentsListMapping.url, ''),
})),
})),
name: location,
documents: Object.keys(locationObj).length,
_children: _.map(groupedByType, (typeObj, type) => {
const groupedBySubType = _.groupBy(
typeObj,
DocumentsListMapping.subType,
);
return {
name: type,
documents: Object.keys(typeObj).length,
_children: _.map(groupedBySubType, (subTypeObj, subType) => ({
name: subType,
documents: Object.keys(subTypeObj).length,
_children: _.map(subTypeObj, doc => ({
name: _.get(doc, DocumentsListMapping.title, ''),
documents: _.get(doc, DocumentsListMapping.url, ''),
})),
})),
};
}),
};
}),
};
Expand Down

0 comments on commit a5fce5b

Please sign in to comment.