Lae/app/Jobs/Module/WorkOrder/Reply.php

66 lines
1.8 KiB
PHP
Raw Normal View History

2022-08-19 15:27:57 +00:00
<?php
2022-11-16 02:29:50 +00:00
namespace App\Jobs\Module\WorkOrder;
2022-08-19 15:27:57 +00:00
2022-11-06 11:28:22 +00:00
use App\Models\WorkOrder\Reply as WorkOrderReply;
2022-08-19 15:27:57 +00:00
use Illuminate\Bus\Queueable;
2022-11-06 11:28:22 +00:00
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
2022-08-19 15:27:57 +00:00
use Illuminate\Queue\SerializesModels;
2022-09-08 16:12:02 +00:00
2022-08-19 15:27:57 +00:00
class Reply implements ShouldQueue
{
2022-09-08 16:12:02 +00:00
use InteractsWithQueue, Queueable, SerializesModels;
2022-08-19 15:27:57 +00:00
2022-12-31 11:28:21 +00:00
protected WorkOrderReply $reply;
protected string $type;
2022-08-19 15:27:57 +00:00
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(WorkOrderReply $reply, $type = 'post')
2022-08-19 15:27:57 +00:00
{
$this->reply = $reply;
$this->type = $type;
2022-08-19 15:27:57 +00:00
}
/**
* Execute the job.
*
* @return void
*/
2022-12-31 11:28:21 +00:00
public function handle(): void
2022-08-19 15:27:57 +00:00
{
$this->reply->load(['workOrder', 'user']);
$this->reply->workOrder->load(['module']);
2022-09-08 16:12:02 +00:00
$reply = $this->reply->toArray();
if ($this->type == 'post') {
$response = $this->reply->workOrder->module->http()->post('work-orders/' . $this->reply->workOrder->id . '/replies', $reply);
2022-08-19 15:27:57 +00:00
if ($response->successful()) {
$this->reply->update([
'is_pending' => false
]);
} else {
$this->reply->update([
'is_pending' => true
]);
}
2022-09-22 06:00:03 +00:00
} else if ($this->type == 'patch') {
$this->reply->workOrder->module->http()->patch('work-orders/' . $this->reply->workOrder->id . '/replies/' . $this->reply->id, $reply);
} else if ($this->type == 'delete') {
$response = $this->reply->workOrder->module->http()->delete('work-orders/' . $this->reply->workOrder->id . '/replies/' . $this->reply->id);
2022-09-22 06:00:03 +00:00
if ($response->successful()) {
$this->reply->delete();
}
2022-08-19 15:27:57 +00:00
}
}
}