Skip to content

Commit

Permalink
Fix existing population entries not being overwritten
Browse files Browse the repository at this point in the history
  • Loading branch information
lemilonkh committed Mar 19, 2024
1 parent eb0ad02 commit b209029
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions app/src/app/api/v0/city/[city]/population/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export const POST = apiHandler(async (req, { session, params }) => {
year: body.cityPopulationYear,
},
});
if (!cityPopulation) {
if (cityPopulation) {
cityPopulation.population = body.cityPopulation;
await cityPopulation.save();
} else {
await db.models.Population.create({
cityId,
population: body.cityPopulation,
Expand All @@ -35,7 +38,10 @@ export const POST = apiHandler(async (req, { session, params }) => {
year: body.regionPopulationYear,
},
});
if (!regionPopulation) {
if (regionPopulation) {
regionPopulation.regionPopulation = body.regionPopulation;
await regionPopulation.save();
} else {
await db.models.Population.create({
cityId,
regionPopulation: body.regionPopulation,
Expand All @@ -49,7 +55,10 @@ export const POST = apiHandler(async (req, { session, params }) => {
year: body.countryPopulationYear,
},
});
if (!countryPopulation) {
if (countryPopulation) {
countryPopulation.countryPopulation = body.countryPopulation;
await countryPopulation.save();
} else {
countryPopulation = await db.models.Population.create({
cityId,
countryPopulation: body.countryPopulation,
Expand Down

0 comments on commit b209029

Please sign in to comment.