mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-22 19:51:35 -04:00
API changes for Zapier
This commit is contained in:
parent
fc0a7cfbf0
commit
e36d23fcdc
@ -61,40 +61,40 @@ class BaseAPIController extends Controller
|
||||
}
|
||||
|
||||
$this->serializer = Request::get('serializer') ?: API_SERIALIZER_ARRAY;
|
||||
|
||||
|
||||
if ($this->serializer === API_SERIALIZER_JSON) {
|
||||
$this->manager->setSerializer(new JsonApiSerializer());
|
||||
} else {
|
||||
$this->manager->setSerializer(new ArraySerializer());
|
||||
}
|
||||
|
||||
|
||||
if (Utils::isNinjaDev()) {
|
||||
\DB::enableQueryLog();
|
||||
}
|
||||
}
|
||||
|
||||
protected function handleAction($request)
|
||||
{
|
||||
{
|
||||
$entity = $request->entity();
|
||||
$action = $request->action;
|
||||
|
||||
|
||||
$repo = Utils::toCamelCase($this->entityType) . 'Repo';
|
||||
|
||||
|
||||
$this->$repo->$action($entity);
|
||||
|
||||
|
||||
return $this->itemResponse($entity);
|
||||
}
|
||||
|
||||
protected function listResponse($query)
|
||||
{
|
||||
$transformerClass = EntityModel::getTransformerName($this->entityType);
|
||||
$transformer = new $transformerClass(Auth::user()->account, Input::get('serializer'));
|
||||
$transformer = new $transformerClass(Auth::user()->account, Input::get('serializer'));
|
||||
|
||||
$includes = $transformer->getDefaultIncludes();
|
||||
$includes = $this->getRequestIncludes($includes);
|
||||
|
||||
$query->with($includes);
|
||||
|
||||
|
||||
if ($updatedAt = Input::get('updated_at')) {
|
||||
$updatedAt = date('Y-m-d H:i:s', $updatedAt);
|
||||
$query->where(function($query) use ($includes, $updatedAt) {
|
||||
@ -106,14 +106,14 @@ class BaseAPIController extends Controller
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if ($clientPublicId = Input::get('client_id')) {
|
||||
$filter = function($query) use ($clientPublicId) {
|
||||
$query->where('public_id', '=', $clientPublicId);
|
||||
};
|
||||
$query->whereHas('client', $filter);
|
||||
}
|
||||
|
||||
|
||||
if ( ! Utils::hasPermission('view_all')){
|
||||
if ($this->entityType == ENTITY_USER) {
|
||||
$query->where('id', '=', Auth::user()->id);
|
||||
@ -121,7 +121,7 @@ class BaseAPIController extends Controller
|
||||
$query->where('user_id', '=', Auth::user()->id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$data = $this->createCollection($query, $transformer, $this->entityType);
|
||||
|
||||
return $this->response($data);
|
||||
@ -130,10 +130,10 @@ class BaseAPIController extends Controller
|
||||
protected function itemResponse($item)
|
||||
{
|
||||
$transformerClass = EntityModel::getTransformerName($this->entityType);
|
||||
$transformer = new $transformerClass(Auth::user()->account, Input::get('serializer'));
|
||||
$transformer = new $transformerClass(Auth::user()->account, Input::get('serializer'));
|
||||
|
||||
$data = $this->createItem($item, $transformer, $this->entityType);
|
||||
|
||||
|
||||
return $this->response($data);
|
||||
}
|
||||
|
||||
@ -160,7 +160,7 @@ class BaseAPIController extends Controller
|
||||
} else {
|
||||
$resource = new Collection($query, $transformer, $entityType);
|
||||
}
|
||||
|
||||
|
||||
return $this->manager->createData($resource)->toArray();
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ class BaseAPIController extends Controller
|
||||
Log::info(Request::method() . ' - ' . Request::url() . ": $count queries");
|
||||
Log::info(json_encode(\DB::getQueryLog()));
|
||||
}
|
||||
|
||||
|
||||
$index = Request::get('index') ?: 'data';
|
||||
|
||||
if ($index == 'none') {
|
||||
@ -222,7 +222,18 @@ class BaseAPIController extends Controller
|
||||
$data[] = $include;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function fileReponse($name, $data)
|
||||
{
|
||||
header('Content-Type: application/pdf');
|
||||
header('Content-Length: ' . strlen($data));
|
||||
header('Content-disposition: attachment; filename="' . $name . '"');
|
||||
header('Cache-Control: public, must-revalidate, max-age=0');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
@ -184,6 +184,10 @@ class InvoiceApiController extends BaseAPIController
|
||||
->with('client', 'invoice_items', 'invitations')
|
||||
->first();
|
||||
|
||||
if (isset($data['download_invoice']) && boolval($data['download_invoice'])) {
|
||||
return $this->fileReponse($invoice->getFileName(), $invoice->getPDFString());
|
||||
}
|
||||
|
||||
return $this->itemResponse($invoice);
|
||||
}
|
||||
|
||||
@ -361,14 +365,7 @@ class InvoiceApiController extends BaseAPIController
|
||||
public function download(InvoiceRequest $request)
|
||||
{
|
||||
$invoice = $request->entity();
|
||||
$pdfString = $invoice->getPDFString();
|
||||
|
||||
header('Content-Type: application/pdf');
|
||||
header('Content-Length: ' . strlen($pdfString));
|
||||
header('Content-disposition: attachment; filename="' . $invoice->getFileName() . '"');
|
||||
header('Cache-Control: public, must-revalidate, max-age=0');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
return $pdfString;
|
||||
return $this->fileReponse($invoice->getFileName(), $invoice->getPDFString());
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ class PaymentTransformer extends EntityTransformer
|
||||
public function __construct($account = null, $serializer = null, $invoice = null)
|
||||
{
|
||||
parent::__construct($account, $serializer);
|
||||
|
||||
|
||||
$this->invoice = $invoice;
|
||||
}
|
||||
|
||||
@ -57,6 +57,7 @@ class PaymentTransformer extends EntityTransformer
|
||||
'is_deleted' => (bool) $payment->is_deleted,
|
||||
'payment_type_id' => (int) $payment->payment_type_id,
|
||||
'invoice_id' => (int) ($this->invoice ? $this->invoice->public_id : $payment->invoice->public_id),
|
||||
'invoice_number' => $this->invoice ? $this->invoice->invoice_number : $payment->invoice->invoice_number,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user