Standardized component API output

This commit is contained in:
snipe 2017-10-07 06:56:18 -07:00
parent b3186ba5ea
commit 5d18937e94
3 changed files with 23 additions and 4 deletions

View file

@ -58,12 +58,22 @@ class ComponentsTransformer
} }
public function transformCheckedoutComponents(Collection $components_users, $total) public function transformCheckedoutComponents(Collection $components_assets, $total)
{ {
$array = array(); $array = array();
foreach ($components_users as $user) { foreach ($components_assets as $asset) {
$array[] = (new UsersTransformer)->transformUser($user); $array[] = [
'assigned_pivot_id' => $asset->pivot->id,
'id' => (int) $asset->id,
'name' => e($asset->model->present()->name) .' '.e($asset->present()->name),
'qty' => $asset->pivot->assigned_qty,
'type' => 'asset',
'created_at' => Helper::getFormattedDateObject($asset->pivot->created_at, 'datetime'),
'available_actions' => ['checkin' => true]
];
} }
return (new DatatablesTransformer)->transformDatatables($array, $total); return (new DatatablesTransformer)->transformDatatables($array, $total);
} }
} }

View file

@ -64,7 +64,7 @@ class Component extends SnipeModel
public function assets() public function assets()
{ {
return $this->belongsToMany('\App\Models\Asset', 'components_assets')->withPivot('assigned_qty', 'created_at', 'user_id'); return $this->belongsToMany('\App\Models\Asset', 'components_assets')->withPivot('id', 'assigned_qty', 'created_at', 'user_id');
} }
public function admin() public function admin()

View file

@ -120,5 +120,14 @@ class ComponentPresenter extends Presenter
return (string) link_to_route('consumables.show', e($this->name), $this->id); return (string) link_to_route('consumables.show', e($this->name), $this->id);
} }
/**
* Url to view this item.
* @return string
*/
public function viewUrl()
{
return route('accessories.show', $this->id);
}
} }