-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prettify metadata when fetching assets and devices from API #228
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should have starts from the 2-dev
branch because it had the new module architecture
(request.input.args.collection === "assets" || | ||
request.input.args.collection === "devices") && | ||
request.input.args.options?.prettify | ||
) { | ||
for (const document of documents) { | ||
if (document._source?.metadata) { | ||
document._source.metadata = | ||
this.assetCategoryService.formatMetadataForGet( | ||
document._source.metadata | ||
); | ||
} | ||
} | ||
} | ||
return documents; | ||
}, | ||
"generic:document:beforeUpdate": async (documents, request: Request) => { | ||
if ( | ||
(request.input.args.collection === "assets" || | ||
request.input.args.collection === "devices") && | ||
request.input.args.options?.prettify | ||
) { | ||
for (const document of documents) { | ||
if (document._source?.metadata) { | ||
document._source.metadata = | ||
this.assetCategoryService.formatMetadataForES( | ||
document._source.metadata | ||
); | ||
} | ||
} | ||
} | ||
return documents; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part could be DRY'ied
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do something like
pipeFunction(myFunction)
if (
(request.input.args.collection === "assets" ||
request.input.args.collection === "devices") &&
request.input.args.options?.prettify
) {
for (const document of documents) {
if (document._source?.metadata) {
document._source.metadata =
myFunction(
document._source.metadata
);
}
}
}
...
this.pipes = {
....
"generic:document:afterGet": async (documents, request: Request) => {
return pipeFunction( this.assetCategoryService.formatMetadataForGet);}
"generic:document:beforeUpdate": async (documents, request: Request) => {
return pipeFunction(this.assetCategoryService.formatMetadataForES);}
};
It's more concise, but, in my opinion, (even with better naming) less readable.
Yes, but when I start to work, the new architecture was not merged :-( |
I checked and it was not that hard, I did it ;-) |
No description provided.