Separated laravel app to its own folder (#540)
This commit is contained in:
65
api/app/Models/Integration/FormIntegration.php
Normal file
65
api/app/Models/Integration/FormIntegration.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Integration;
|
||||
|
||||
use App\Events\Models\FormIntegrationCreated;
|
||||
use App\Models\Forms\Form;
|
||||
use App\Models\OAuthProvider;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class FormIntegration extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
public const STATUS_ACTIVE = 'active';
|
||||
public const STATUS_INACTIVE = 'inactive';
|
||||
|
||||
protected $fillable = [
|
||||
'form_id',
|
||||
'status',
|
||||
'integration_id',
|
||||
'logic',
|
||||
'data',
|
||||
'oauth_id'
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'data' => 'object',
|
||||
'logic' => 'object'
|
||||
];
|
||||
}
|
||||
|
||||
protected $dispatchesEvents = [
|
||||
'created' => FormIntegrationCreated::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Relationships
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
return $this->belongsTo(Form::class);
|
||||
}
|
||||
|
||||
public function events()
|
||||
{
|
||||
return $this->hasMany(FormIntegrationsEvent::class, 'integration_id');
|
||||
}
|
||||
|
||||
public function provider()
|
||||
{
|
||||
return $this->belongsTo(OAuthProvider::class, 'oauth_id');
|
||||
}
|
||||
|
||||
public static function getAllIntegrations()
|
||||
{
|
||||
return json_decode(file_get_contents(resource_path('data/forms/integrations.json')), true);
|
||||
}
|
||||
|
||||
public static function getIntegration($key)
|
||||
{
|
||||
return self::getAllIntegrations()[$key] ?? null;
|
||||
}
|
||||
}
|
||||
42
api/app/Models/Integration/FormIntegrationsEvent.php
Normal file
42
api/app/Models/Integration/FormIntegrationsEvent.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Integration;
|
||||
|
||||
use App\Events\Models\FormIntegrationsEventCreated;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class FormIntegrationsEvent extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public const STATUS_SUCCESS = 'success';
|
||||
public const STATUS_ERROR = 'error';
|
||||
|
||||
protected $fillable = [
|
||||
'integration_id',
|
||||
'status',
|
||||
'data'
|
||||
];
|
||||
|
||||
protected function casts()
|
||||
{
|
||||
return [
|
||||
'data' => 'object'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* The event map for the model.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dispatchesEvents = [
|
||||
'created' => FormIntegrationsEventCreated::class,
|
||||
];
|
||||
|
||||
public function integration()
|
||||
{
|
||||
return $this->belongsTo(FormIntegration::class, 'integration_id');
|
||||
}
|
||||
}
|
||||
40
api/app/Models/Integration/FormZapierWebhook.php
Normal file
40
api/app/Models/Integration/FormZapierWebhook.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Integration;
|
||||
|
||||
use App\Models\Forms\Form;
|
||||
use App\Service\Forms\Webhooks\WebhookHandlerProvider;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class FormZapierWebhook extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'form_zapier_webhooks';
|
||||
|
||||
protected $fillable = [
|
||||
'form_id',
|
||||
'hook_url',
|
||||
];
|
||||
|
||||
/**
|
||||
* Relationships
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
return $this->belongsTo(Form::class);
|
||||
}
|
||||
|
||||
public function triggerHook(array $data)
|
||||
{
|
||||
WebhookHandlerProvider::getProvider(
|
||||
$this->form,
|
||||
$data,
|
||||
WebhookHandlerProvider::ZAPIER_PROVIDER,
|
||||
$this->hook_url
|
||||
)->handle();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user