const { RESTDataSource } = require('apollo-datasource-rest');
class PropertytwoAPI extends RESTDataSource {
constructor() {
super();
this.baseURL = ""
}
async getAllData() {
const response = await this.get("Data");
return !Array.isArray(response)
? response.documents.map((item, index) => this.propertyReducer(item))
: []
}
propertyReducer(item, index){
return {
id : [index] - 0,
fields : {
Rent_Frequency : {
stringValue : item.fields.Rent_Frequency.stringValue,
},
geopoints : {
geoPointValue : {
latitude : item.fields.geopoints.geoPointValue.latitude,
longitude : item.fields.geopoints.geoPointValue.longitude,
}
},
Images : {
arrayValue : {
values : item.fields.Images.arrayValue.values.map(i => ({
stringValue : i.stringValue
})),
}
},
Property_Size : {
stringValue : item.fields.Property_Size.stringValue,
},
Property_purpose : {
stringValue : item.fields.Property_purpose.stringValue,
},
Property_Description : {
stringValue : item.fields.Property_Description.stringValue,
},
Price : {
stringValue : item.fields.Price.stringValue,
},
Property_Size_Unit : {
stringValue : item.fields.Property_Size_Unit.stringValue,
},
Locality : {
stringValue : item.fields.Locality.stringValue,
},
Property_Type : {
stringValue : item.fields.Property_Type.stringValue,
},
Listing_Agent : {
stringValue : item.fields.Listing_Agent.stringValue,
},
Listing_Agent_Phone : {
stringValue : item.fields.Listing_Agent_Phone.stringValue,
},
Property_Title : {
stringValue : item.fields.Property_Title.stringValue,
},
Bathroom : {
stringValue : item.fields.Bathroom.stringValue,
},
Listing_Agent_Email : {
stringValue : item.fields.Listing_Agent_Email.stringValue,
},
Bedrooms : {
stringValue : item.fields.Bedrooms.stringValue,
},
City : {
stringValue : item.fields.City.stringValue,
},
Property_Status : {
stringValue : item.fields.Property_Status.stringValue,
},
Sub_Locality : {
stringValue : item.fields.Sub_Locality.stringValue,
},
}
}
}
}
module.exports = PropertytwoAPI;