@ima/plugin-http-client
Version:
Generic http client for the IMA application framework.
30 lines (29 loc) • 1.06 kB
JavaScript
import { AbstractProcessor } from '../../AbstractProcessor';
/**
* The EntityProcessor transforms the response from the API into entities.
*/ export class EntityProcessor extends AbstractProcessor {
postRequest(params) {
const { response, additionalParams } = params;
if (response) {
const { body } = response;
const entityClass = additionalParams?.resource?.entityClass;
if (body && entityClass) {
let newBody;
if (body instanceof Array) {
newBody = body.map((entityData)=>Reflect.construct(entityClass, [
entityData
]));
} else {
newBody = Reflect.construct(entityClass, [
body
]);
}
params.response = Object.assign({}, response, {
body: newBody
});
}
}
return params;
}
}
//# sourceMappingURL=EntityProcessor.js.map