-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #439 from Open-Earth-Foundation/fix/show-populatio…
…n-values Fix/show population values
- Loading branch information
Showing
3 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,21 @@ | ||
import UserService from "@/backend/UserService"; | ||
import { db } from "@/models"; | ||
import { apiHandler } from "@/util/api"; | ||
import { PopulationEntry, findClosestYearToInventory } from "@/util/helpers"; | ||
import { NextResponse } from "next/server"; | ||
|
||
export const GET = apiHandler(async (_req: Request, { session, params }) => { | ||
const city = await UserService.findUserCity(params.city, session); | ||
const population = await db.models.Population.findOne({ | ||
where: { cityId: city?.cityId, year: params.year }, | ||
const population = await db.models.Population.findAll({ | ||
where: { cityId: city?.cityId }, | ||
}); | ||
return NextResponse.json({ data: population }); | ||
}); | ||
const populations: PopulationEntry[] = population.map(({population, year})=>{ | ||
return { | ||
year, | ||
population: population! | ||
} | ||
}) | ||
|
||
const closestYearPopulationData = findClosestYearToInventory(populations, parseInt(params.year)) | ||
return NextResponse.json({ data: closestYearPopulationData }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters