Skip to content

Instantly share code, notes, and snippets.

@geoidesic
geoidesic / console.text
Created November 26, 2020 11:42
Problem with sync from pouchDB
vue.runtime.esm.js?5593:619 [Vue warn]: Error in v-on handler: "TypeError: target.once is not a function"
found in
---> <QBtn>
<PouchDBExample>
<QPageContainer>
<QLayout>
<StorybookLayout> at src/layouts/Storybook.vue
<App> at src/App.vue
@geoidesic
geoidesic / DocumentRelationshipValidator.php
Created August 3, 2020 10:20
Handles validation for the JSONAPI relationships requests.
<?php
declare(strict_types=1);
namespace App\Listener\JsonApi;
use Cake\ORM\Entity;
use Cake\Utility\Hash;
use Cake\Utility\Inflector;
use Cake\Validation\Validation;
use Crud\Error\Exception\CrudException;
@geoidesic
geoidesic / CrudJsonApiListener.php
Created August 3, 2020 10:19
Will invoke a custom DocumentValidator class depending on the URL format.
<?php
declare(strict_types=1);
namespace App\Listener;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\RepositoryInterface;
use Cake\Datasource\ResultSetDecorator;
use Cake\Datasource\ResultSetInterface;
@geoidesic
geoidesic / RelationshipAction.php
Created August 3, 2020 09:11
Refactor attempt of the CrudJsonApiControllerTrait as a CRUD Action class extension (note the `print_r` which mysteriously doesn't yield the request body)
<?php
declare(strict_types=1);
namespace App\Crud\Action;
use Cake\Http\Response;
use Crud\Error\Exception\ValidationException;
use Crud\Event\Subject;
use Crud\Traits\FindMethodTrait;
use Crud\Traits\RedirectTrait;
@geoidesic
geoidesic / CrudJsonControllerTrait
Created August 3, 2020 09:03
Adds actions to your `crud-json-api` controller to handle POST and PATCH relationships requests.
<?php
namespace App\Traits;
use Cake\Utility\Inflector;
use Cake\Utility\Hash;
trait CrudJsonApiControllerTrait
{
/**
@geoidesic
geoidesic / routes.php
Created August 3, 2020 09:02
Routing for CrudJsonControllerTrait
Router::prefix('api', function (RouteBuilder $routes) {
$routes->connect('/{controller}/{id}/relationships/{foreignTableName}', ['_method' => 'DELETE', 'action' => 'deleterelationships']);
$routes->connect('/{controller}/{id}/relationships/{foreignTableName}', ['_method' => 'PATCH', 'action' => 'updaterelationships']);
$routes->connect('/{controller}/{id}/relationships/{foreignTableName}', ['_method' => 'POST', 'action' => 'postrelationships']);
}