mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 00:50:54 -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;
|
$this->serializer = Request::get('serializer') ?: API_SERIALIZER_ARRAY;
|
||||||
|
|
||||||
if ($this->serializer === API_SERIALIZER_JSON) {
|
if ($this->serializer === API_SERIALIZER_JSON) {
|
||||||
$this->manager->setSerializer(new JsonApiSerializer());
|
$this->manager->setSerializer(new JsonApiSerializer());
|
||||||
} else {
|
} else {
|
||||||
$this->manager->setSerializer(new ArraySerializer());
|
$this->manager->setSerializer(new ArraySerializer());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils::isNinjaDev()) {
|
if (Utils::isNinjaDev()) {
|
||||||
\DB::enableQueryLog();
|
\DB::enableQueryLog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function handleAction($request)
|
protected function handleAction($request)
|
||||||
{
|
{
|
||||||
$entity = $request->entity();
|
$entity = $request->entity();
|
||||||
$action = $request->action;
|
$action = $request->action;
|
||||||
|
|
||||||
$repo = Utils::toCamelCase($this->entityType) . 'Repo';
|
$repo = Utils::toCamelCase($this->entityType) . 'Repo';
|
||||||
|
|
||||||
$this->$repo->$action($entity);
|
$this->$repo->$action($entity);
|
||||||
|
|
||||||
return $this->itemResponse($entity);
|
return $this->itemResponse($entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function listResponse($query)
|
protected function listResponse($query)
|
||||||
{
|
{
|
||||||
$transformerClass = EntityModel::getTransformerName($this->entityType);
|
$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 = $transformer->getDefaultIncludes();
|
||||||
$includes = $this->getRequestIncludes($includes);
|
$includes = $this->getRequestIncludes($includes);
|
||||||
|
|
||||||
$query->with($includes);
|
$query->with($includes);
|
||||||
|
|
||||||
if ($updatedAt = Input::get('updated_at')) {
|
if ($updatedAt = Input::get('updated_at')) {
|
||||||
$updatedAt = date('Y-m-d H:i:s', $updatedAt);
|
$updatedAt = date('Y-m-d H:i:s', $updatedAt);
|
||||||
$query->where(function($query) use ($includes, $updatedAt) {
|
$query->where(function($query) use ($includes, $updatedAt) {
|
||||||
@ -106,14 +106,14 @@ class BaseAPIController extends Controller
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($clientPublicId = Input::get('client_id')) {
|
if ($clientPublicId = Input::get('client_id')) {
|
||||||
$filter = function($query) use ($clientPublicId) {
|
$filter = function($query) use ($clientPublicId) {
|
||||||
$query->where('public_id', '=', $clientPublicId);
|
$query->where('public_id', '=', $clientPublicId);
|
||||||
};
|
};
|
||||||
$query->whereHas('client', $filter);
|
$query->whereHas('client', $filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! Utils::hasPermission('view_all')){
|
if ( ! Utils::hasPermission('view_all')){
|
||||||
if ($this->entityType == ENTITY_USER) {
|
if ($this->entityType == ENTITY_USER) {
|
||||||
$query->where('id', '=', Auth::user()->id);
|
$query->where('id', '=', Auth::user()->id);
|
||||||
@ -121,7 +121,7 @@ class BaseAPIController extends Controller
|
|||||||
$query->where('user_id', '=', Auth::user()->id);
|
$query->where('user_id', '=', Auth::user()->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->createCollection($query, $transformer, $this->entityType);
|
$data = $this->createCollection($query, $transformer, $this->entityType);
|
||||||
|
|
||||||
return $this->response($data);
|
return $this->response($data);
|
||||||
@ -130,10 +130,10 @@ class BaseAPIController extends Controller
|
|||||||
protected function itemResponse($item)
|
protected function itemResponse($item)
|
||||||
{
|
{
|
||||||
$transformerClass = EntityModel::getTransformerName($this->entityType);
|
$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);
|
$data = $this->createItem($item, $transformer, $this->entityType);
|
||||||
|
|
||||||
return $this->response($data);
|
return $this->response($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ class BaseAPIController extends Controller
|
|||||||
} else {
|
} else {
|
||||||
$resource = new Collection($query, $transformer, $entityType);
|
$resource = new Collection($query, $transformer, $entityType);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->manager->createData($resource)->toArray();
|
return $this->manager->createData($resource)->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ class BaseAPIController extends Controller
|
|||||||
Log::info(Request::method() . ' - ' . Request::url() . ": $count queries");
|
Log::info(Request::method() . ' - ' . Request::url() . ": $count queries");
|
||||||
Log::info(json_encode(\DB::getQueryLog()));
|
Log::info(json_encode(\DB::getQueryLog()));
|
||||||
}
|
}
|
||||||
|
|
||||||
$index = Request::get('index') ?: 'data';
|
$index = Request::get('index') ?: 'data';
|
||||||
|
|
||||||
if ($index == 'none') {
|
if ($index == 'none') {
|
||||||
@ -222,7 +222,18 @@ class BaseAPIController extends Controller
|
|||||||
$data[] = $include;
|
$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;
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,6 +184,10 @@ class InvoiceApiController extends BaseAPIController
|
|||||||
->with('client', 'invoice_items', 'invitations')
|
->with('client', 'invoice_items', 'invitations')
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
|
if (isset($data['download_invoice']) && boolval($data['download_invoice'])) {
|
||||||
|
return $this->fileReponse($invoice->getFileName(), $invoice->getPDFString());
|
||||||
|
}
|
||||||
|
|
||||||
return $this->itemResponse($invoice);
|
return $this->itemResponse($invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,14 +365,7 @@ class InvoiceApiController extends BaseAPIController
|
|||||||
public function download(InvoiceRequest $request)
|
public function download(InvoiceRequest $request)
|
||||||
{
|
{
|
||||||
$invoice = $request->entity();
|
$invoice = $request->entity();
|
||||||
$pdfString = $invoice->getPDFString();
|
|
||||||
|
|
||||||
header('Content-Type: application/pdf');
|
return $this->fileReponse($invoice->getFileName(), $invoice->getPDFString());
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ class PaymentTransformer extends EntityTransformer
|
|||||||
public function __construct($account = null, $serializer = null, $invoice = null)
|
public function __construct($account = null, $serializer = null, $invoice = null)
|
||||||
{
|
{
|
||||||
parent::__construct($account, $serializer);
|
parent::__construct($account, $serializer);
|
||||||
|
|
||||||
$this->invoice = $invoice;
|
$this->invoice = $invoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +57,7 @@ class PaymentTransformer extends EntityTransformer
|
|||||||
'is_deleted' => (bool) $payment->is_deleted,
|
'is_deleted' => (bool) $payment->is_deleted,
|
||||||
'payment_type_id' => (int) $payment->payment_type_id,
|
'payment_type_id' => (int) $payment->payment_type_id,
|
||||||
'invoice_id' => (int) ($this->invoice ? $this->invoice->public_id : $payment->invoice->public_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