mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
exchange user table seeder
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Exchange;
|
||||
use App\Models\AbstractModel;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
/**
|
||||
* Class Company
|
||||
* @package App\Models
|
||||
*
|
||||
* @property \App\Models\Country country_id
|
||||
* @property \App\Models\State state_id
|
||||
* @property \App\Models\District district_id
|
||||
* @property string postcode
|
||||
* @property string street_one
|
||||
* @property string street_two
|
||||
* @property integer billing_type
|
||||
*/
|
||||
class Company extends AbstractModel
|
||||
{
|
||||
protected $connection = 'exchange_db';
|
||||
|
||||
protected $table = 'companies';
|
||||
|
||||
/**
|
||||
* @return belongsToMany
|
||||
*/
|
||||
public function employees(): belongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class, (new Employee())->getTable(), 'company_id','user_id');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Exchange;
|
||||
|
||||
use App\Models\AbstractModel;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
/**
|
||||
* Class CompanyEmployee
|
||||
* @package App\Models
|
||||
*
|
||||
* @property \App\Models\Company company_id
|
||||
* @property \App\Models\User user_id
|
||||
*/
|
||||
class Employee extends AbstractModel
|
||||
{
|
||||
protected $connection = 'exchange_db';
|
||||
|
||||
protected $table = 'employees';
|
||||
|
||||
/**
|
||||
* @return HasMany
|
||||
*/
|
||||
public function company(): HasMany
|
||||
{
|
||||
return $this->HasMany(Company::class, 'company_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
**/
|
||||
public function user(): HasOne
|
||||
{
|
||||
return $this->hasOne(User::class, 'user_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Exchange;
|
||||
|
||||
use App\Models\AbstractModel;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class User extends AbstractModel {
|
||||
|
||||
protected $connection = 'exchange_db';
|
||||
|
||||
/**
|
||||
* @return belongsToMany
|
||||
*/
|
||||
public function company(): belongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Company::class, (new Employee())->getTable(), 'user_id', 'company_id');
|
||||
}
|
||||
}
|
||||
+19
-1
@@ -82,7 +82,25 @@ return [
|
||||
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
|
||||
]) : [],
|
||||
],
|
||||
|
||||
'exchange_db' => [
|
||||
'driver' => 'mysql',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'port' => env('DB_PORT', '3306'),
|
||||
'database' => env('DB_DATABASE_EXCHANGE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'unix_socket' => env('DB_SOCKET_IZYIM', ''),
|
||||
'charset' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
|
||||
]) : [],
|
||||
],
|
||||
'pgsql' => [
|
||||
'driver' => 'pgsql',
|
||||
'url' => env('DATABASE_URL'),
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\EmploymentObject;
|
||||
use App\Classes\Modules\Companies\Processors\AssignEmployeeProcessor;
|
||||
use App\Models\CompanyConnection;
|
||||
use App\Models\Exchange\Company as ExchangeCompany;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CompanyEmployeesTableSeeder extends Seeder
|
||||
{
|
||||
|
||||
/** @var AssignEmployeeProcessor */
|
||||
private $assignEmployeeProcessor;
|
||||
|
||||
/**
|
||||
* CompanyEmployeesTableSeeder constructor.
|
||||
* @param AssignEmployeeProcessor $assignEmployeeProcessor
|
||||
*/
|
||||
public function __construct(AssignEmployeeProcessor $assignEmployeeProcessor)
|
||||
{
|
||||
$this->assignEmployeeProcessor = $assignEmployeeProcessor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
DB::beginTransaction();
|
||||
foreach(ExchangeCompany::all() as $company) {
|
||||
|
||||
if($connection = CompanyConnection::where('invitee_reference', $company->reference)->first()){
|
||||
|
||||
$companyModule = $connection->invitee;
|
||||
|
||||
if($companyModule->employees()->exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$exchangeUser = $company->employees()->first();
|
||||
|
||||
$user = new User();
|
||||
$user->name = $exchangeUser->name;
|
||||
$user->email = $exchangeUser->email;
|
||||
$user->password = $exchangeUser->password;
|
||||
$user->type = $exchangeUser->type;
|
||||
$user->status = $exchangeUser->status;
|
||||
|
||||
$user->save();
|
||||
|
||||
$Object = new EmploymentObject($companyModule, $user);
|
||||
|
||||
$this->assignEmployeeProcessor->execute($Object);
|
||||
}
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user