Skip to content

Commit

Permalink
fix: handle integer long or lat values from the garden Firestore REST…
Browse files Browse the repository at this point in the history
… API
  • Loading branch information
th0rgall committed May 16, 2024
1 parent 293415a commit 6880ff9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/lib/api/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export const getGarden = async (id: string) => {
}
};

// Presumably, doubles and integers are the only numbers allowed:
// https://firebase.google.com/docs/firestore/manage-data/data-types
type DoubleValue = {
doubleValue: number;
};
Expand Down Expand Up @@ -95,8 +97,14 @@ function mapRestToGarden(doc: RESTGardenDoc): Garden {
id: name.split('/').pop() as string,
description: description?.stringValue,
location: {
latitude: location.mapValue.fields.latitude?.doubleValue,
longitude: location.mapValue.fields.longitude?.doubleValue
// Integer values are rare, but we have one in the db at the time of writing
// It looks like a real location!
latitude:
location.mapValue.fields.latitude?.doubleValue ??
location.mapValue.fields.latitude?.integerValue,
longitude:
location.mapValue.fields.longitude?.doubleValue ??
location.mapValue.fields.longitude?.integerValue
},
listed: listed.booleanValue,
facilities: {
Expand Down

0 comments on commit 6880ff9

Please sign in to comment.