Add hashed transformer for company tokens

This commit is contained in:
David Bomba 2020-07-13 12:54:56 +10:00
parent 2e165c11ca
commit 708422dd9b
4 changed files with 73 additions and 1 deletions

View File

@ -321,6 +321,8 @@ class BaseController extends Controller
'company.tasks',
'company.projects',
'company.designs',
'company.webhooks',
'company.tokens_hashed'
];
$mini_load = [

View File

@ -374,6 +374,11 @@ class Company extends BaseModel
return $this->hasMany(CompanyToken::class);
}
public function tokens_hashed()
{
return $this->hasMany(CompanyToken::class);
}
public function company_users()
{
//return $this->hasMany(CompanyUser::class)->withTimestamps();

View File

@ -0,0 +1,56 @@
<?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;
use App\Models\CompanyToken;
use App\Utils\Traits\MakesHash;
/**
* Class CompanyTokenHashedTransformer.
*/
class CompanyTokenHashedTransformer extends EntityTransformer
{
use MakesHash;
/**
* @var array
*/
protected $defaultIncludes = [
];
/**
* @var array
*/
protected $availableIncludes = [
];
/**
* @param CompanyToken $company_token
*
* @return array
*/
public function transform(CompanyToken $company_token)
{
return [
'id' => $this->encodePrimaryKey($company_token->id),
'user_id' => $this->encodePrimaryKey($company_token->user_id),
'token' => substr($company_token->token, 0 ,10)."xxxxxxxxxxx",
'name' => $company_token->name ?: '',
'is_system' =>(bool)$company_token->is_system,
'updated_at' => (int)$company_token->updated_at,
'archived_at' => (int)$company_token->deleted_at,
'created_at' => (int)$company_token->created_at,
'is_deleted' => (bool)$company_token->is_deleted,
];
}
}

View File

@ -33,6 +33,7 @@ use App\Models\TaxRate;
use App\Models\User;
use App\Models\Webhook;
use App\Transformers\CompanyLedgerTransformer;
use App\Transformers\CompanyTokenHashedTransformer;
use App\Transformers\CompanyTokenTransformer;
use App\Transformers\CreditTransformer;
use App\Transformers\PaymentTermTransformer;
@ -82,7 +83,8 @@ class CompanyTransformer extends EntityTransformer
'tasks',
'ledger',
'webhooks',
'tokens'
'tokens',
'tokens_hashed'
];
@ -147,6 +149,13 @@ class CompanyTransformer extends EntityTransformer
return $this->includeCollection($company->tokens, $transformer, CompanyToken::class);
}
public function includeTokensHashed(Company $company)
{
$transformer = new CompanyTokenHashedTransformer($this->serializer);
return $this->includeCollection($company->tokens, $transformer, CompanyToken::class);
}
public function includeWebhooks(Company $company)
{
$transformer = new WebhookTransformer($this->serializer);