I encountered an issue while trying to implement a JSON API in an ES6 model. The error message I received was: TypeError: Cannot read property 'first_name' of undefined.
Here is the JSON API:
class UserModel {
constructor(data) {
this.id = data.id;
this.first_name = data.attributes.first_name;
this.last_name = data.attributes.last_name;
this.username = data.attributes.username;
this.email = data.attributes.email;
this.created_at = data.attributes.created_at;
this.link = data.links.self;
}
get getId() {
return this.id;
}
set setId(value) {
this.id = value;
}
get getFirstName() {
return this.first_name;
}
set setFirstName(value) {
this.first_name = value;
}
get getLastName() {
return this.last_name;
}
set setLastName(value) {
this.last_name = value;
}
get getUsername() {
return this.username;
}
set setUsername(value) {
this.username = value;
}
get getEmail() {
return this.email;
}
set setEmail(value) {
this.email = value;
}
get getCreatedAt() {
return this.created_at;
}
set setCreatedAt(value) {
this.created_at = value;
}
get getLink() {
return this.link
}
set setLink(value) {
this.link = value
}
}
Can anyone provide assistance on how to resolve this issue?