Skip to content

Commit

Permalink
Added CORS preflight route for API requests [SLE-192]
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgfeller committed May 10, 2024
1 parent 25a8f92 commit 849dc8f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@

// API routes
$app->group('/api', function (RouteCollectorProxy $group) {
// Options route for CORS preflight requests required, otherwise exception Method not allowed is thrown.
$group->options('/{routes:.+}', function ($request, $response) {
return $response;
});

// Client creation API call
$group->post('/clients', \App\Application\Action\Client\Api\ApiClientCreateAction::class)
->setName('api-client-create-submit');
Expand Down
8 changes: 4 additions & 4 deletions src/Domain/Note/Repository/NoteFinderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ public function findMostRecentNotes(int $notesAmount): array
$query = $this->queryFactory->selectQuery()->from('note');

$concatUserName = $query->func()->concat(
// Not very sexy to put IFNULL function there but with "identifier", cake interprets the string literally
['IFNULL(user.first_name, "")' => 'identifier', ' ', 'IFNULL(user.last_name, "")' => 'identifier']
// Cake interprets the string literally with "literal", so IFNULL() and column are interpreted as raw sql
['IFNULL(user.first_name, "")' => 'literal', ' ', 'IFNULL(user.last_name, "")' => 'identifier']
);
$concatClientName = $query->func()->concat(
['IFNULL(client.first_name, "")' => 'identifier', ' ', 'IFNULL(client.last_name, "")' => 'identifier']
['IFNULL(client.first_name, "")' => 'literal', ' ', 'IFNULL(client.last_name, "")' => 'identifier']
);

$query->select(
Expand All @@ -138,7 +138,7 @@ public function findMostRecentNotes(int $notesAmount): array
->join(['table' => 'user', 'conditions' => 'note.user_id = user.id'])
->leftJoin('client', ['note.client_id = client.id'])
->andWhere(['note.deleted_at IS' => null, 'note.is_main' => 0])
->orderByDesc('note.updated_at')->limit($notesAmount);
->orderBy(['note.updated_at' => 'DESC', 'note.created_at' => 'DESC'])->limit($notesAmount);

$resultRows = $query->execute()->fetchAll('assoc') ?: [];

Expand Down

0 comments on commit 849dc8f

Please sign in to comment.