My task involves mapping a field from a sub object in the response JSON to the parent object
The response I receive looks like this:
{
"id": 1,
"name": "file-1",
"survey": {
"identifier": 1,
"displayedValue": survey-1
}
}
I am attempting to map the above JSON to this Object:
import { Entity } from './entity';
export class File extends Entity {
name: string;
survey: Entity['identifier'];
status: string;
}
This is the Entity class being used:
export class Entity {
displayedValue: string;
identifier: string;
}
Here is the snippet of code showing how I attempted to map it:
this.fileService.getFileById(this.fileId).subscribe(data => {
this.file = data;
});
The file service method implementation:
public getFileById(fileId: string): Observable<File> {
const getFileByIdURL = environment.backendBaseURL + 'files/' + fileId;
return this.http.get<File>(getFileByIdURL);
}
The goal is for the file.survey to contain the survey identifier