Skip to content

Instantly share code, notes, and snippets.

@geoidesic
geoidesic / console.text
Created Nov 26, 2020
Problem with sync from pouchDB
View console.text
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 Aug 3, 2020
Handles validation for the JSONAPI relationships requests.
View DocumentRelationshipValidator.php
<?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 Aug 3, 2020
Will invoke a custom DocumentValidator class depending on the URL format.
View CrudJsonApiListener.php
<?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 Aug 3, 2020
Refactor attempt of the CrudJsonApiControllerTrait as a CRUD Action class extension (note the `print_r` which mysteriously doesn't yield the request body)
View RelationshipAction.php
<?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 Aug 3, 2020
Adds actions to your `crud-json-api` controller to handle POST and PATCH relationships requests.
View CrudJsonControllerTrait
<?php
namespace App\Traits;
use Cake\Utility\Inflector;
use Cake\Utility\Hash;
trait CrudJsonApiControllerTrait
{
/**
@geoidesic
geoidesic / routes.php
Created Aug 3, 2020
Routing for CrudJsonControllerTrait
View routes.php
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']);
}