Skip to content

Commit

Permalink
Fix larastan warning (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmohns authored Dec 11, 2024
1 parent d74e0f5 commit 851df77
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/backend/app/Http/Controllers/Reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,10 @@ private function generateReportForCity(
$sheet = $this->spreadsheet->getActiveSheet();
$sheet->setTitle('graphs'.$startDate.'-'.$endDate);

$transactions = $this->transaction::with(['meter.meterParameter.tariff', 'meter.meterParameter.connectionType'])
$transactions = $this->transaction::with(['device.device.tariff', 'device.device.connectionType'])
->selectRaw('id,message,SUM(amount) as amount,GROUP_CONCAT(DISTINCT id SEPARATOR \',\') AS transaction_ids')
->whereHas(
'meter.meterParameter.address',
'device.device.address',
function ($q) use ($cityId) {
$q->where('city_id', $cityId);
}
Expand Down
4 changes: 2 additions & 2 deletions src/backend/app/Misc/LoanDataContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function loanCost() {
private function getCustomerDueRates($owner): Collection {
$loans = AssetPerson::query()->where('person_id', $owner->id)->pluck('id');

return AssetRate::with('assetPerson.assetType')
return AssetRate::with('assetPerson.device')
->whereIn('asset_person_id', $loans)
->where('remaining', '>', 0)
->whereDate('due_date', '<', date('Y-m-d'))
Expand All @@ -111,7 +111,7 @@ private function getCustomerDueRates($owner): Collection {
private function getMeterOwner(string $serialNumber): ?Person {
try {
/** @var Meter $meter */
$meter = Meter::with('meterParameter.owner')
$meter = Meter::with('device.person')
->where('serial_number', $serialNumber)
->firstOrFail();
} catch (ModelNotFoundException $ex) {
Expand Down
2 changes: 1 addition & 1 deletion src/backend/app/Services/AgentAssignedApplianceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function create(array $applianceData): AgentAssignedAppliances {
}

public function getById(int $id): AgentAssignedAppliances {
return $this->agentAssignedAppliance->newQuery()->with('applianceType')->find($id);
return $this->agentAssignedAppliance->newQuery()->with('appliance')->find($id);
}

public function update($model, array $data): AgentAssignedAppliances {
Expand Down
6 changes: 3 additions & 3 deletions src/backend/app/Services/AgentSoldApplianceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function create($applianceData): AgentSoldAppliance {
}

public function getById(int $agentId, ?int $customerId = null): AgentSoldAppliance {
return $this->assetPerson->newQuery()->with(['person', 'assetType', 'rates'])
return $this->assetPerson->newQuery()->with(['person', 'device', 'rates'])
->whereHasMorph(
'creator',
[Agent::class],
Expand Down Expand Up @@ -59,7 +59,7 @@ public function getAll(

$query = $this->agentSoldAppliance->newQuery()->with([
'assignedAppliance',
'assignedAppliance.applianceType',
'assignedAppliance.appliance.assetType',
'person',
]);

Expand Down Expand Up @@ -87,7 +87,7 @@ function ($q) use ($agentId) {
}

public function list($agentId) {
return $this->assetPerson->newQuery()->with(['person', 'assetType', 'rates'])
return $this->assetPerson->newQuery()->with(['person', 'device', 'rates'])
->whereHasMorph(
'creator',
[Agent::class],
Expand Down
2 changes: 1 addition & 1 deletion src/backend/app/Services/ClusterMeterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function __construct(private Cluster $cluster, private Meter $meter) {}

public function getCountById($clusterId): int {
return $this->meter->newQuery()->whereHas(
'meterParameter',
'device',
function ($q) use ($clusterId) {
$q->whereHas(
'address',
Expand Down
6 changes: 3 additions & 3 deletions src/backend/app/Services/MeterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ public function search($term, $paginate): LengthAwarePaginator {
public function getMeterWithAllRelations(int $meterId) {
return $this->meter->newQuery()->with([
'tariff',
'device.geo',
'device.device.geo',
'meterType',
])->find($meterId);
}

public function getUsedMetersGeoWithAccessRatePayments(): Collection|array {
return $this->meter->newQuery()->with(['device.geo', 'accessRatePayment'])->where('in_use', 1)->get();
return $this->meter->newQuery()->with(['device.device.geo', 'accessRatePayment'])->where('in_use', 1)->get();
}

public function getUsedMetersGeoWithAccessRatePaymentsInCities($cities): Collection|array {
return $this->meter->newQuery()->with(['device.geo', 'accessRatePayment'])
return $this->meter->newQuery()->with(['device.device.geo', 'accessRatePayment'])
->whereHas(
'device',
fn ($q) => $q->whereHas(
Expand Down
6 changes: 2 additions & 4 deletions src/backend/app/Services/PersonMeterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@

namespace App\Services;

use App\Models\Meter\Meter;
use App\Models\Person\Person;

class PersonMeterService {
public function __construct(
private Person $person,
private Meter $meter,
) {}

public function getPersonMeters(int $personId) {
return $this->person->newQuery()->with(['meters.tariff', 'meters.meter'])->find($personId);
return $this->person->newQuery()->with(['devices.device.tariff', 'meters.meter'])->find($personId);
}

public function getPersonMetersGeographicalInformation(int $personId) {
return $this->person->newQuery()->with(['meters.meter', 'meters.geo'])->find($personId);
return $this->person->newQuery()->with(['devices.device.meter', 'meters.geo'])->find($personId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected function getVariableValue($variable) {
$person = $this->data->meter->meterParameter->owner()->first();
} else {
try {
$person = Person::query()->with(['meters.meter' => function ($q) {
$person = Person::query()->with(['devices.device' => function ($q) {
return $q->where('serial_number', $this->data['meter'])->first();
}])->firstOrFail();
} catch (\Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion src/backend/app/Traits/RestExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected function isValidationException($e): bool {
*
* @return JsonResponse
*/
protected function jsonResponse(?array $payload = null, $status_code) {
protected function jsonResponse(?array $payload = null, $status_code = 400) {
$payload = $payload ?: [];

return response()->json(
Expand Down

0 comments on commit 851df77

Please sign in to comment.