Skip to content

Commit

Permalink
Fix geojson return type
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadjaur committed Dec 18, 2024
1 parent d173b04 commit dbbf6c8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
19 changes: 13 additions & 6 deletions server/src/routes/geojsonRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,24 @@ router.get(
params.resourceId,
);

if (!object) {
return ctx.json(
{
error: `Resource ${params.resource}/${params.resourceId} not found`,
},
404,
);
}

const headers = new Headers();
object.writeHttpMetadata(headers);
headers.set('etag', object.httpEtag);
headers.set('Content-Type', 'application/geo+json');
ctx.header('etag', object.httpEtag);
ctx.header('Content-Type', 'application/geo+json');
const json = await object.json();

return new Response(json, {
headers,
});
return ctx.json(json);
} catch (error) {
return ctx.json({ error: error.message }, 400);
return ctx.json({ error: error.message }, 500);
}
}),
);
Expand Down
10 changes: 4 additions & 6 deletions server/src/services/geojsonStorage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ export class GeojsonStorageService {
resource: ResourceType,
geojson: string,
resourceId: string,
): Promise<R2Object> {
const object = await this._bucket.put(`${resource}/${resourceId}`, geojson);
return object;
): Promise<R2Object | null> {
return this._bucket.put(`${resource}/${resourceId}`, geojson);
}

public static async retrieve(
resource: ResourceType,
resourceId: string,
): Promise<R2ObjectBody> {
const object = await this._bucket.get(`${resource}/${resourceId}`);
return object;
): Promise<R2ObjectBody | null> {
return this._bucket.get(`${resource}/${resourceId}`);
}
}
1 change: 1 addition & 0 deletions server/src/services/trip/editTripService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const editTripService = async (
await scoreTripService(selectedTrip.id);

const serializedGeoJSON = tripData.geoJSON;

if (!serializedGeoJSON) {
return updatedTrip;
}
Expand Down

0 comments on commit dbbf6c8

Please sign in to comment.