Skip to content

Commit

Permalink
feat(metadata): avoid merging null properties to metadata object
Browse files Browse the repository at this point in the history
  • Loading branch information
willian-viana committed Jun 11, 2024
1 parent 5302fb7 commit 7e4a50e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pages/api/metadata/[...params].js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,25 @@ export default async (req, res) => {
`${GFW_METADATA_API_URL}/dataset/gfw_integrated_alerts/v20240605/metadata`
);

const dataVersionMetadataObject = datasetVersionMetadata.data.data;

const response = {
...datasetMetadata.data.data,
metadata: {
...datasetMetadata.data.data.metadata,
...datasetVersionMetadata.data.data,
},
};

/*
* Merging the metadata from the second request
* avoiding overwrite the object properties with null value
*/
Object.keys(dataVersionMetadataObject).forEach((key) => {
if (dataVersionMetadataObject[key] !== null) {
response.metadata[key] = dataVersionMetadataObject[key];
}
});

return res.status(200).json(response);
} catch (error) {
if (error.response) {
Expand Down

0 comments on commit 7e4a50e

Please sign in to comment.