|
|
@@ -65,7 +65,7 @@ class AppointmentService
|
|
|
], $model->user_id);
|
|
|
}
|
|
|
|
|
|
- public function update(int $id, array $data): ?Appointment
|
|
|
+ public function update(int $id, array $data, ?int $approvingUserId = null): ?Appointment
|
|
|
{
|
|
|
$model = Appointment::find($id);
|
|
|
|
|
|
@@ -73,6 +73,15 @@ class AppointmentService
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ if (
|
|
|
+ isset($data['status'])
|
|
|
+ && $data['status'] === AppointmentStatusEnum::CONFIRMADO->value
|
|
|
+ && $model->status !== AppointmentStatusEnum::CONFIRMADO
|
|
|
+ ) {
|
|
|
+ $data['auto_approved'] = false;
|
|
|
+ $data['approved_by_user_id'] = $approvingUserId;
|
|
|
+ }
|
|
|
+
|
|
|
$model->update($data);
|
|
|
return $model->fresh(['user', 'partnerAgreement', 'partnerAgreementService']);
|
|
|
}
|
|
|
@@ -122,14 +131,16 @@ class AppointmentService
|
|
|
return $query->paginate($perPage);
|
|
|
}
|
|
|
|
|
|
- public function approve(int $id, string $date, string $time): ?Appointment
|
|
|
+ public function approve(int $id, string $date, string $time, ?int $approvedByUserId = null): ?Appointment
|
|
|
{
|
|
|
$model = Appointment::find($id);
|
|
|
if (!$model) return null;
|
|
|
$model->update([
|
|
|
- 'status' => AppointmentStatusEnum::CONFIRMADO,
|
|
|
- 'date' => $date,
|
|
|
- 'time' => $time,
|
|
|
+ 'status' => AppointmentStatusEnum::CONFIRMADO,
|
|
|
+ 'date' => $date,
|
|
|
+ 'time' => $time,
|
|
|
+ 'auto_approved' => false,
|
|
|
+ 'approved_by_user_id' => $approvedByUserId,
|
|
|
]);
|
|
|
$this->notificationService->createAutoForUser([
|
|
|
'title' => 'Agendamento confirmado',
|
|
|
@@ -161,9 +172,11 @@ class AppointmentService
|
|
|
$model = Appointment::whereHas('partnerAgreement', fn($q) => $q->where('user_id', $userId))->find($id);
|
|
|
if (!$model) return null;
|
|
|
$model->update([
|
|
|
- 'status' => AppointmentStatusEnum::CONFIRMADO,
|
|
|
- 'date' => $date,
|
|
|
- 'time' => $time,
|
|
|
+ 'status' => AppointmentStatusEnum::CONFIRMADO,
|
|
|
+ 'date' => $date,
|
|
|
+ 'time' => $time,
|
|
|
+ 'auto_approved' => false,
|
|
|
+ 'approved_by_user_id' => $userId,
|
|
|
]);
|
|
|
$this->notificationService->createAutoForUser([
|
|
|
'title' => 'Agendamento confirmado',
|