Skip to content

Commit

Permalink
Merge pull request #1377 from andrew-bierman/fix-geojson-route
Browse files Browse the repository at this point in the history
Fix geojson route returning invalid string and add minimum range in the trip name and description
  • Loading branch information
taronaleksanian authored Dec 18, 2024
2 parents f92630a + a7c5b6b commit a4a2e56
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { TripActivity } from './enums';

const tripActivityValues = Object.values(TripActivity) as [string, ...string[]];

export const addTripForm = z.object({
name: z.string(),
description: z.string().optional().nullable(),
export const tripForm = z.object({
name: z.string().min(2).max(40),
description: z.string().min(50).max(200).optional().nullable(),
activity: z.enum(tripActivityValues).optional(),
is_public: z.boolean().optional(),
});
Expand Down Expand Up @@ -58,7 +58,7 @@ export const addTripDetails = z.object({
trails: z.string().optional(),
});

export const addTrip = addTripDetails.merge(addTripForm);
export const addTrip = addTripDetails.merge(tripForm);
export type AddTripType = z.infer<typeof addTrip>;

export const editTrip = addTrip.merge(
Expand Down
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 a4a2e56

Please sign in to comment.