Skip to content

Commit

Permalink
Deletes all existing building map entries if the id does not match th…
Browse files Browse the repository at this point in the history
…e current served map, before saving (#735)

* Deletes all existing building map entries if the id does not match the current served map, before saving

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Fix remapped variable

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

---------

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
  • Loading branch information
aaronchongth committed Aug 14, 2023
1 parent 5fcccd3 commit ac0ca6c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/api-server/api_server/models/building_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ def from_tortoise(tortoise: ttm.BuildingMap) -> "BuildingMap":
return BuildingMap(**tortoise.data)

async def save(self) -> None:
existing_maps = await ttm.BuildingMap.all()
for m in existing_maps:
if m.id_ != self.name:
await m.delete()
await ttm.BuildingMap.update_or_create({"data": self.dict()}, id_=self.name)

0 comments on commit ac0ca6c

Please sign in to comment.