aboutsummaryrefslogtreecommitdiffstats
path: root/app/models.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/models.js')
-rw-r--r--app/models.js44
1 files changed, 20 insertions, 24 deletions
diff --git a/app/models.js b/app/models.js
index d052f1c..1f39192 100644
--- a/app/models.js
+++ b/app/models.js
@@ -175,7 +175,7 @@ export class District {
const name = "nimi_fi" in feature.properties ? feature.properties.nimi_fi : "";
const geometry = feature.geometry;
- if (name === undefined || !(geometry instanceof Polygon)) {
+ if (name === null || name === undefined || !(geometry instanceof Polygon)) {
throw new Error("Invalid district feature data");
}
@@ -235,11 +235,10 @@ export class TrainTracks {
* @returns {TrainTracks}
*/
static fromFeature(feature) {
- const geometry = feature.geometry;
- if (!(geometry instanceof LineString)) {
- throw new Error("Invalid train tracks feature data");
+ if (!(feature.geometry instanceof LineString)) {
+ throw new Error("Invalid train tracks feature data {feature}");
}
- return new TrainTracks(geometry);
+ return new TrainTracks(feature.geometry);
}
/**
@@ -268,12 +267,11 @@ export class TrainStation {
* @returns {TrainStation|null}
*/
static fromFeature(feature) {
- const geometry = feature.geometry;
- if (!(geometry instanceof Polygon)) {
- console.warn(`Train station feature ${JSON.stringify(feature)} is not a Polygon`);
- return null;
+ if (!(feature.geometry instanceof Polygon)) {
+ throw new Error("Invalid train stations feature data {feature}");
}
- return new TrainStation(geometry);
+
+ return new TrainStation(feature.geometry);
}
/**
@@ -291,9 +289,9 @@ export class House {
* @param {string} id
* @param {string} address
* @param {string} district
- * @param {Point} coordinates - Use Point geometry instead of GeoPoint
- * @param {string} [postalCode]
+ * @param {Point} coordinates
* @param {number} price
+ * @param {string} [postalCode]
* @param {string} buildingType
* @param {number} [constructionYear]
* @param {number} [rooms]
@@ -303,9 +301,9 @@ export class House {
* @param {string} [condition]
* @param {string} [description]
* @param {PriceUpdate[]} [priceHistory]
- * @param {Date} firstSeen
- * @param {Date} lastSeen
- * @param {Date} lastUpdated
+ * @param {Date|null} firstSeen
+ * @param {Date|null} lastSeen
+ * @param {Date|null} lastUpdated
* @param {Date|null} [disappeared]
* @param {Scores} scores
* @param {string[]} images
@@ -316,9 +314,9 @@ export class House {
address,
district,
coordinates,
- postalCode = "",
price,
- buildingType,
+ postalCode = "",
+ buildingType = "",
constructionYear = 0,
rooms = 0,
livingArea = 0,
@@ -327,9 +325,9 @@ export class House {
condition = "",
description = "",
priceHistory = [],
- firstSeen,
- lastSeen,
- lastUpdated,
+ firstSeen = null,
+ lastSeen = null,
+ lastUpdated = null,
disappeared = null,
scores = new Scores(0),
images = [],
@@ -339,8 +337,8 @@ export class House {
this.address = address;
this.district = district;
this.coordinates = coordinates;
- this.postalCode = postalCode;
this.price = price;
+ this.postalCode = postalCode;
this.buildingType = buildingType;
this.constructionYear = constructionYear;
this.rooms = rooms;
@@ -390,8 +388,8 @@ export class House {
rawLocation.address || "",
rawLocation.district || "",
coordinates,
- rawLocation.zipCode || "",
parsePrice(rawData.price),
+ rawLocation.zipCode || "",
House.getBuildingType(data.type),
rawData.buildYear || 0,
rawData.rooms || 0,
@@ -546,8 +544,6 @@ export class DataProvider {
}
const data = /** @type {ApiResponse} */ (await response.json());
-
- // Extract the doc objects from each row and filter out any null/undefined
const housesData = data.rows.map((row) => row.doc).filter((doc) => doc?.raw?.location);
console.log(`Loaded ${housesData.length} houses from API`);