Skip to content

Commit

Permalink
Update geoInformation when not exists on SteamaCo site sync (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmohns authored Jul 23, 2024
1 parent 30ac0eb commit d8c4588
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ public function sync()
'mpm_mini_grid_id' => $miniGrid->id,
'hash' => $site['hash'],
]);
$this->updateGeographicalInformation($miniGrid->id, $site);
$this->createOrUpdateGeographicalInformation($miniGrid->id, $site);
});

$syncCheck['data']->filter(function ($value) {
return $value['syncStatus'] === SyncStatus::MODIFIED;
})->each(function ($site) {
$miniGrid = is_null($site['relatedMiniGrid']) ?
$this->creteRelatedMiniGrid($site) : $this->updateRelatedMiniGrid($site, $site['relatedMiniGrid']);
$this->updateGeographicalInformation($miniGrid->id, $site);
$this->createOrUpdateGeographicalInformation($miniGrid->id, $site);
$site['registeredStmSite']->update([
'site_id' => $site['id'],
'mpm_mini_grid_id' => $miniGrid->id,
Expand Down Expand Up @@ -176,7 +176,7 @@ public function updateRelatedMiniGrid($site, $miniGrid)
return $miniGrid->fresh();
}

public function updateGeographicalInformation($miniGridId, $site)
public function createOrUpdateGeographicalInformation($miniGridId, $site)
{
$geographicalInformation = $this->geographicalInformation->newQuery()->whereHasMorph(
'owner',
Expand All @@ -187,9 +187,18 @@ static function ($q) use ($miniGridId) {
)->first();
$points = $site['latitude'] === null ?
config('steama.geoLocation') : $site['latitude'].','.$site['longitude'];
$geographicalInformation->update([
'points' => $points,
]);

if ($geographicalInformation) {
$geographicalInformation->update([
'points' => $points,
]);
} else {
$this->geographicalInformation->create([
'owner_type' => 'mini-grid',
'owner_id' => $miniGridId,
'points' => $points,
]);
}
}

public function checkLocationAvailability()
Expand Down

0 comments on commit d8c4588

Please sign in to comment.