Skip to content

Commit

Permalink
Fix databaseHelper.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Dec 3, 2024
1 parent 708d512 commit 68cc093
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions api/src/common/databaseHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ const initializeLocations = async () => {
const langLocationValue = new LocationValue({ language: lang, value: enLocationValue.value })
await langLocationValue.save()
const loc = await Location.findById(location.id)
loc?.values.push(new mongoose.Types.ObjectId(String(langLocationValue.id)))
await loc?.save()
if (loc) {
loc.values.push(new mongoose.Types.ObjectId(String(langLocationValue.id)))
await loc.save()
}
}
}
} else {
Expand Down Expand Up @@ -142,9 +144,11 @@ const initializeCountries = async () => {
if (!country.values.some((val) => val.language === lang)) {
const langLocationValue = new LocationValue({ language: lang, value: enLocationValue.value })
await langLocationValue.save()
const loc = await Country.findById(country.id)
loc?.values.push(new mongoose.Types.ObjectId(String(langLocationValue.id)))
await loc?.save()
const cnt = await Country.findById(country.id)
if (cnt) {
cnt.values.push(new mongoose.Types.ObjectId(String(langLocationValue.id)))
await cnt.save()
}
}
}
} else {
Expand Down Expand Up @@ -198,9 +202,11 @@ const initializeParkingSpots = async () => {
if (!parkingSpot.values.some((val) => val.language === lang)) {
const langLocationValue = new LocationValue({ language: lang, value: enLocationValue.value })
await langLocationValue.save()
const loc = await ParkingSpot.findById(parkingSpot.id)
loc?.values.push(new mongoose.Types.ObjectId(String(langLocationValue.id)))
await loc?.save()
const ps = await ParkingSpot.findById(parkingSpot.id)
if (ps) {
ps.values.push(new mongoose.Types.ObjectId(String(langLocationValue.id)))
await ps.save()
}
}
}
} else {
Expand Down

0 comments on commit 68cc093

Please sign in to comment.