Skip to content

Commit

Permalink
fix: records route with new propertie attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
cballevre committed Mar 4, 2024
1 parent 7762874 commit 83287a4
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions app/api/v1/sensors/[id]/records/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ export async function GET(request, { params }) {
where: {
sensor_id: sensorId,
},
orderBy: {
recorded_at: 'asc',
},
})

if (format === 'geojson') {
const geojson = getGeojsonFromRecord(records)
return NextResponse.json({ data: geojson }, { status: 200 })
return NextResponse.json({ ...geojson }, { status: 200 })
}

return NextResponse.json({ data: records }, { status: 200 })
Expand All @@ -44,17 +47,21 @@ function getGeojsonFromRecord(recordList) {
let geojson = {
type: 'FeatureCollection',
features: [
...recordList.map((record) => {
const { id, latitude, longitude, ...properties } = record
return {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [longitude.toString(), latitude.toString()],
},
properties,
}
}),
...recordList.map(
({ id, latitude, longitude, recorded_at, properties }) => {
return {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [longitude.toString(), latitude.toString()],
},
properties: {
recorded_at,
...properties,
},
}
},
),
{
type: 'Feature',
geometry: {
Expand Down

0 comments on commit 83287a4

Please sign in to comment.