Fixes for transformerS (#3388)

This commit is contained in:
David Bomba 2020-02-27 10:32:44 +11:00 committed by GitHub
parent 200b26d809
commit c15f17186d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 63 additions and 46 deletions

View File

@ -13,12 +13,10 @@ namespace App\Models;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Laracasts\Presenter\PresentableTrait;
class Account extends BaseModel
{
use SoftDeletes;
use PresentableTrait;
use MakesHash;

View File

@ -12,9 +12,12 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class CompanyToken extends Model
{
use SoftDeletes;
/**
* @var bool
*/

View File

@ -12,9 +12,12 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Document extends BaseModel
{
use SoftDeletes;
const DOCUMENT_PREVIEW_SIZE = 300; // pixels
/**

View File

@ -24,6 +24,7 @@ use Illuminate\Database\Eloquent\Model;
class GroupSetting extends StaticModel
{
use MakesHash;
use SoftDeletes;
public $timestamps = false;

View File

@ -60,6 +60,8 @@ class AccountTransformer extends EntityTransformer
'id' => (string)$this->encodePrimaryKey($account->id),
'default_url' => config('ninja.site_url'),
'plan' => $account->getPlan(),
'updated_at' => (int)$account->updated_at,
'archived_at' => (int)$account->deleted_at,
];
}

View File

@ -33,6 +33,7 @@ class ActivityTransformer extends EntityTransformer
'payment_id' => $activity->payment_id ? (string) $this->encodePrimaryKey($activity->payment_id) : '',
'credit_id' => $activity->credit_id ? (string) $this->encodePrimaryKey($activity->credit_id) : '',
'updated_at' => (int)$activity->updated_at,
'created_at' => (int)$activity->created_at,
'expense_id' => $activity->expense_id ? (string) $this->encodePrimaryKey($activity->expense_id) : '',
'is_system' => (bool) $activity->is_system,
'contact_id' => $activity->contact_id ? (string) $this->encodePrimaryKey($activity->contact_id) : '',

View File

@ -33,6 +33,7 @@ class ClientContactLoginTransformer extends EntityTransformer
'first_name' => $contact->first_name ?: '',
'last_name' => $contact->last_name ?: '',
'email' => $contact->email ?: '',
'created_at' => (int)$contact->created_at,
'updated_at' => (int)$contact->updated_at,
'archived_at' => (int)$contact->deleted_at,
'is_primary' => (bool) $contact->is_primary,

View File

@ -34,6 +34,7 @@ class ClientContactTransformer extends EntityTransformer
'first_name' => $contact->first_name ?: '',
'last_name' => $contact->last_name ?: '',
'email' => $contact->email ?: '',
'created_at' => (int)$contact->created_at,
'updated_at' => (int)$contact->updated_at,
'archived_at' => (int)$contact->deleted_at,
'is_primary' => (bool) $contact->is_primary,

View File

@ -36,6 +36,7 @@ class ClientGatewayTokenTransformer extends EntityTransformer
'gateway_type_id' => (string)$cgt->gateway_type_id ?: '',
'company_gateway_id' => (string)$this->encodePrimaryKey($cgt->company_gateway_id) ?: '',
'is_default' => (bool) $cgt->is_default,
'created_at' => (int)$cgt->created_at,
'updated_at' => (int)$cgt->updated_at,
'archived_at' => (int)$cgt->deleted_at,
];

View File

@ -115,6 +115,7 @@ class ClientTransformer extends EntityTransformer
'id_number' => $client->id_number ?: '',
'updated_at' => (int)$client->updated_at,
'archived_at' => (int)$client->deleted_at,
'created_at' => (int)$client->created_at,
'display_name' => $client->present()->name()
];
}

View File

@ -14,6 +14,7 @@ namespace App\Transformers;
use App\Models\CompanyGateway;
use App\Transformers\GatewayTransformer;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class CompanyGatewayTransformer.
@ -21,7 +22,7 @@ use App\Utils\Traits\MakesHash;
class CompanyGatewayTransformer extends EntityTransformer
{
use MakesHash;
use SoftDeletes;
/**
* @var array
*/
@ -55,6 +56,8 @@ class CompanyGatewayTransformer extends EntityTransformer
'fees_and_limits' => $company_gateway->fees_and_limits ?: '',
'updated_at' => (int)$company_gateway->updated_at,
'archived_at' => (int)$company_gateway->deleted_at,
'created_at' => (int)$company_gateway->created_at,
'is_deleted' => (bool)$company_gateway->is_deleted,
'custom_value1' => $company_gateway->custom_value1 ?: '',
'custom_value2' => $company_gateway->custom_value2 ?: '',
'custom_value3' => $company_gateway->custom_value3 ?: '',

View File

@ -44,6 +44,9 @@ class CompanyTokenTransformer extends EntityTransformer
return [
'token' => $company_token->token,
'name' => $company_token->name ?: '',
'updated_at' => (int)$company_token->updated_at,
'archived_at' => (int)$company_token->deleted_at,
'created_at' => (int)$company_token->created_at,
];
}
}

View File

@ -108,6 +108,7 @@ class CompanyTransformer extends EntityTransformer
'enabled_tax_rates' => (int)$company->enabled_tax_rates,
'updated_at' => (int)$company->updated_at,
'archived_at' => (int)$company->deleted_at,
'created_at' =>(int)$company->created_at,
];
}

View File

@ -59,6 +59,7 @@ class CompanyUserTransformer extends EntityTransformer
'is_locked' => (bool) $company_user->is_locked,
'updated_at' => (int)$company_user->updated_at,
'archived_at' => (int)$company_user->deleted_at,
'created_at' => (int)$company_user->created_at,
];
}

View File

@ -29,6 +29,7 @@ class CreditInvitationTransformer extends EntityTransformer {
'opened_date' => $invitation->opened_date ?:'',
'updated_at' => (int) $invitation->updated_at,
'archived_at' => (int) $invitation->deleted_at,
'created_at' => (int) $invitation->created_at,
];
}
}

View File

@ -84,6 +84,7 @@ class CreditTransformer extends EntityTransformer
'invoice_id' => (string) ($credit->invoice_id ?: 1),
'updated_at' => (int)$credit->updated_at,
'archived_at' => (int)$credit->deleted_at,
'created_at' => (int)$credit->created_at,
'number' => $credit->number ?: '',
'discount' => (float) $credit->discount,
'po_number' => $credit->po_number ?: '',

View File

@ -13,6 +13,7 @@ namespace App\Transformers;
use App\Models\Design;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class DesignTransformer.
@ -20,7 +21,7 @@ use App\Utils\Traits\MakesHash;
class DesignTransformer extends EntityTransformer
{
use MakesHash;
use SoftDeletes;
/**
* @var array
*/
@ -47,6 +48,9 @@ class DesignTransformer extends EntityTransformer
'is_custom' => (bool)$design->is_custom,
'is_active' => (bool)$design->is_active,
'design' => $design->design,
'updated_at' => (int)$design->updated_at,
'archived_at' => (int)$design->deleted_at,
'created_at' => (int)$design->created_at,
];
}

View File

@ -49,6 +49,7 @@ class DocumentTransformer extends EntityTransformer
'is_default' => (bool) $document->is_default,
'updated_at' => (int) $document->updated_at,
'archived_at' => (int) $document->deleted_at
'created_at' => (int) $document->created_at
];
}

View File

@ -13,6 +13,7 @@ namespace App\Transformers;
use App\Models\Expense;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* class ExpenseTransformer
@ -20,7 +21,7 @@ use App\Utils\Traits\MakesHash;
class ExpenseTransformer extends EntityTransformer
{
use MakesHash;
use SoftDeletes;
protected $defaultIncludes = [
];
@ -75,6 +76,7 @@ class ExpenseTransformer extends EntityTransformer
'custom_value4' => $expense->custom_value4 ?: '',
'updated_at' => (int)$expense->updated_at,
'archived_at' => (int)$expense->deleted_at,
'created_at' => (int)$expense->created_at,
];
}
}

View File

@ -51,6 +51,7 @@ class GatewayTransformer extends EntityTransformer
'is_secure' => (bool)$gateway->is_secure,
'fields' => (string)$gateway->fields ?: '',
'updated_at' => (int)$gateway->updated_at,
'created_at' => (int)$gateway->created_at,
];
}
}

View File

@ -42,6 +42,10 @@ class GroupSettingTransformer extends EntityTransformer
'id' => $this->encodePrimaryKey($group_setting->id),
'name' => (string)$group_setting->name ?: '',
'settings' => $group_setting->settings ?: new \stdClass,
'created_at' => (int)$group_setting->created_at,
'updated_at' => (int)$group_setting->updated_at,
'archived_at' => (int)$group_setting->deleted_at,
'is_deleted' => (bool) $group_setting->is_deleted,
];
}
}

View File

@ -28,6 +28,7 @@ class InvoiceInvitationTransformer extends EntityTransformer {
'opened_date' => $invitation->opened_date?:'',
'updated_at' => (int) $invitation->updated_at,
'archived_at' => (int) $invitation->deleted_at,
'created_at' => (int) $invitation->created_at,
];
}
}

View File

@ -1,36 +0,0 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Transformers;
class InvoiceItemTransformer extends EntityTransformer
{
public function transform($item)
{
return [
'id' => (int) $item->id,
'product_key' => $item->product_key,
'updated_at' => (int)$item->updated_at,
'archived_at' => (int)$item->deleted_at,
'notes' => $item->notes ?: '',
'cost' => (float) $item->cost ?: '',
'quantity' => (float) ($item->quantity ?: 0.0),
'tax_name1' => $item->tax_name1 ? $item->tax_name1 : '',
'tax_rate1' => (float) ($item->tax_rate1 ?: 0.0),
'tax_name2' => $item->tax_name2 ? $item->tax_name2 : '',
'tax_rate2' => (float) ($item->tax_rate2 ?: 0.0),
'line_item_type_id' => (string) $item->line_item_type_id ?: '',
'custom_value1' => $item->custom_value1 ?: '',
'custom_value2' => $item->custom_value2 ?: '',
'discount' => (float) $item->discount ?: '',
];
}
}

View File

@ -91,8 +91,10 @@ class InvoiceTransformer extends EntityTransformer
'vendor_id' => (string) $this->encodePrimaryKey($invoice->vendor_id),
'status_id' => (string) ($invoice->status_id ?: 1),
'design_id' => (string) ($invoice->design_id ?: 1),
'created_at' => (int)$invoice->created_at,
'updated_at' => (int)$invoice->updated_at,
'archived_at' => (int)$invoice->deleted_at,
'is_deleted' => (bool) $invoice->is_deleted,
'number' => $invoice->number ?: '',
'discount' => (float) $invoice->discount,
'po_number' => $invoice->po_number ?: '',
@ -103,7 +105,6 @@ class InvoiceTransformer extends EntityTransformer
'terms' => $invoice->terms ?: '',
'public_notes' => $invoice->public_notes ?: '',
'private_notes' => $invoice->private_notes ?: '',
'is_deleted' => (bool) $invoice->is_deleted,
'uses_inclusive_taxes' => (bool) $invoice->uses_inclusive_taxes,
'tax_name1' => $invoice->tax_name1 ? $invoice->tax_name1 : '',
'tax_rate1' => (float) $invoice->tax_rate1,

View File

@ -72,6 +72,7 @@ class PaymentTransformer extends EntityTransformer
'transaction_reference' => $payment->transaction_reference ?: '',
'date' => $payment->date ?: '',
'is_manual' => (bool) $payment->is_manual,
'created_at' => (int)$payment->created_at,
'updated_at' => (int)$payment->updated_at,
'archived_at' => (int)$payment->deleted_at,
'is_deleted' => (bool) $payment->is_deleted,

View File

@ -73,6 +73,7 @@ class ProductTransformer extends EntityTransformer
'tax_rate2' => (float) $product->tax_rate2 ?: 0,
'tax_name3' => $product->tax_name3 ?: '',
'tax_rate3' => (float) $product->tax_rate3 ?: 0,
'created_at' => (int)$product->created_at,
'updated_at' => (int)$product->updated_at,
'archived_at' => (int)$product->deleted_at,
'custom_value1' => $product->custom_value1 ?: '',

View File

@ -36,6 +36,7 @@ class ProjectTransformer extends EntityTransformer
'id' => (string) $this->encodePrimaryKey($project->id),
'name' => $project->name ?: '',
'client_id' => (string) $this->encodePrimaryKey($project->client_id),
'created_at' => (int)$project->created_at,
'updated_at' => (int)$project->updated_at,
'archived_at' => (int)$project->deleted_at,
'is_deleted' => (bool) $project->is_deleted,

View File

@ -31,6 +31,7 @@ class QuoteInvitationTransformer extends EntityTransformer
'opened_date' => $invitation->opened_date ?: '',
'updated_at' => (int) $invitation->updated_at,
'archived_at' => (int) $invitation->deleted_at,
'created_at' => (int) $invitation->created_at,
];
}
}

View File

@ -84,6 +84,7 @@ class QuoteTransformer extends EntityTransformer
'invoice_id' => (string) ($quote->invoice_id ?: 1),
'updated_at' => (int)$quote->updated_at,
'archived_at' => (int)$quote->deleted_at,
'created_at' => (int)$quote->created_at,
'number' => $quote->number ?: '',
'discount' => (float) $quote->discount,
'po_number' => $quote->po_number ?: '',

View File

@ -87,6 +87,7 @@ class RecurringInvoiceTransformer extends EntityTransformer
'balance' => (float) $invoice->balance ?: '',
'client_id' => (string) $invoice->client_id,
'status_id' => (string) ($invoice->status_id ?: 1),
'created_at' => (int)$invoice->created_at,
'updated_at' => (int)$invoice->updated_at,
'archived_at' => (int)$invoice->deleted_at,
'discount' => (float) $invoice->discount ?: '',

View File

@ -87,6 +87,7 @@ class RecurringQuoteTransformer extends EntityTransformer
'balance' => (float) $quote->balance ?: '',
'client_id' => (string) $quote->client_id,
'status_id' => (string) ($quote->status_id ?: 1),
'created_at' => (int)$quote->created_at,
'updated_at' => (int)$quote->updated_at,
'archived_at' => (int)$quote->deleted_at,
'discount' => (float) $quote->discount ?: '',

View File

@ -36,6 +36,7 @@ class TaskTransformer extends EntityTransformer
'id' => (string) $this->encodePrimaryKey($task->id),
'description' => $task->description ?: '',
'duration' => 0,
'created_at' => (int)$task->created_at,
'updated_at' => (int)$task->updated_at,
'archived_at' => (int)$task->deleted_at,
'invoice_id' => $this->encodePrimaryKey($task->invoice_id),

View File

@ -20,6 +20,7 @@ class TaxRateTransformer extends EntityTransformer
'rate' => (float) $tax_rate->rate,
'updated_at' => (int)$tax_rate->updated_at,
'archived_at' => (int)$tax_rate->deleted_at,
'created_at' => (int)$tax_rate->created_at,
];
}
}

View File

@ -52,6 +52,7 @@ class UserTransformer extends EntityTransformer
'last_name' => $user->last_name ?: '',
'email' => $user->email ?: '',
'last_login' => Carbon::parse($user->last_login)->timestamp,
'created_at' => (int)$user->created_at,
'updated_at' => (int)$user->updated_at,
'archived_at' => (int)$user->deleted_at,
'created_at' => (int)$user->created_at,

View File

@ -34,6 +34,7 @@ class VendorContactTransformer extends EntityTransformer
'first_name' => $vendor->first_name ?: '',
'last_name' => $vendor->last_name ?: '',
'email' => $vendor->email ?: '',
'created_at' => (int)$vendor->created_at,
'updated_at' => (int)$vendor->updated_at,
'archived_at' => (int)$vendor->deleted_at,
'is_primary' => (bool) $vendor->is_primary,

View File

@ -94,6 +94,7 @@ class VendorTransformer extends EntityTransformer
'id_number' => $vendor->id_number ?: '',
'updated_at' => (int)$vendor->updated_at,
'archived_at' => (int)$vendor->deleted_at,
'created_at' => (int)$vendor->created_at,
];
}
}

View File

@ -26,7 +26,7 @@ trait Uploadable
if ($path) {
$settings = $entity->settings;
$settings->company_logo = $company->domain() . $path;
$settings->company_logo = $path;
$entity->settings = $settings;
$entity->save();
}

View File

@ -135,7 +135,6 @@ class CreateUsersTable extends Migration
$table->string('referral_code')->nullable();
$table->timestamps(6);
$table->softDeletes('deleted_at', 6);
});
Schema::create('companies', function (Blueprint $table) {
@ -232,6 +231,7 @@ class CreateUsersTable extends Migration
$table->string('custom_value2')->nullable();
$table->string('custom_value3')->nullable();
$table->string('custom_value4')->nullable();
$table->softDeletes('deleted_at', 6);
$table->unsignedInteger('documentable_id');
$table->string('documentable_type');
@ -292,7 +292,9 @@ class CreateUsersTable extends Migration
$table->unsignedInteger('user_id');
$table->string('token')->nullable();
$table->string('name')->nullable();
$table->timestamps(6);
$table->softDeletes('deleted_at', 6);
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade')->onUpdate('cascade');
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade')->onUpdate('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
@ -405,6 +407,7 @@ class CreateUsersTable extends Migration
$table->boolean('show_billing_address')->default(true)->nullable();
$table->boolean('show_shipping_address')->default(true)->nullable();
$table->boolean('update_details')->default(false)->nullable();
$table->boolean('is_deleted')->default(false);
$table->mediumText('config');
$table->text('fees_and_limits');
$table->string('custom_value1')->nullable();
@ -1153,6 +1156,8 @@ class CreateUsersTable extends Migration
$table->unsignedInteger('user_id')->nullable();
$table->string('name')->nullable();
$table->mediumText('settings')->nullable();
$table->softDeletes('deleted_at', 6);
$table->timestamps(6);
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade')->onUpdate('cascade');
});
@ -1371,7 +1376,7 @@ class CreateUsersTable extends Migration
$table->boolean('is_active')->default(true);
$table->mediumText('design')->nullable();
$table->timestamps(6);
$table->softDeletes('deleted_at', 6);
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade')->onUpdate('cascade');
});