Skip to content

Commit

Permalink
Add endpoint to get car details by make
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchernchong committed Jun 16, 2024
1 parent 24ca97d commit 30f44fb
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ app.get("/cars/:type", async (c) => {
const type = c.req.param("type");
const month = c.req.query("month");
return c.json(await getCarsByFuelType(type, month));
app.get("/make", async (c) => {
return c.json(await db.collection<Car>("cars").distinct("make"));
});

app.get("/make/:make", async (c) => {
const make = c.req.param("make");
const vehicleType = c.req.query("vehicleType");

return c.json(
await db
.collection<Car>("cars")
.find({
make: new RegExp(make, "i"),
vehicle_type: new RegExp(vehicleType, "i"),
})
.toArray(),
);
});

app.get("/coe", async (c) => {
Expand All @@ -39,10 +56,6 @@ app.get("/coe/latest", async (c) => {
return c.json(await getCOEResultByMonth(month));
});

app.get("/vehicle-make", async (c) => {
return c.json(await db.collection<Car>("cars").distinct("make"));
});

app.get("/months", async (c) => {
const grouped = c.req.query("grouped");
const months = await db.collection<Car>("cars").distinct("month");
Expand Down

0 comments on commit 30f44fb

Please sign in to comment.