Skip to content

Commit

Permalink
Merge pull request #2214 from bakaphp/KCT-414
Browse files Browse the repository at this point in the history
refactor: if key no exists
  • Loading branch information
FredPeal authored Oct 18, 2024
2 parents 416a73a + af2ac8b commit 2a5fffe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Domains/Event/Events/DataTransferObject/EventDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public function __construct(
#[WithCast(DateTimeInterfaceCast::class)]
#[WithTransformer(DateTimeInterfaceTransformer::class)]
public readonly DateTime $date,
public readonly string $start_time,
public readonly string $end_time,
public readonly ?string $start_time = null,
public readonly ?string $end_time = null,
) {
}

Expand Down
13 changes: 13 additions & 0 deletions src/Domains/Event/Events/Jobs/ImporterEventJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Kanvas\Event\Events\Jobs;

use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Kanvas\Companies\Models\Companies;
use Kanvas\Event\Events\Actions\CreateEventAction;
use Kanvas\Event\Events\DataTransferObject\Event;
Expand Down Expand Up @@ -43,6 +44,18 @@ public function handle()
$errors = [];
foreach ($this->importer as $request) {
try {
$request['slug'] = key_exists('slug', $request) ? $request['slug'] : Str::slug($request['name']);
if (! key_exists('type_id', $request)) {
$type = EventType::firstOrCreate([
'companies_id' => $this->branch->company->getId(),
'apps_id' => $this->app->getId(),
'users_id' => $this->user->getId(),
'name' => $request['event_type'],
]);
$request['type_id'] = $type->getId();
}

$request['category_id'] = key_exists('category_id', $request) ? $request['category_id'] : EventCategory::where('companies_id', $this->branch->company->getId())->first()->getId();
$data = Event::fromMultiple($this->app, $this->user, $this->branch->company, $request);
$event = (new CreateEventAction($data))->execute();

Expand Down

0 comments on commit 2a5fffe

Please sign in to comment.