Skip to content

Commit f269948

Browse files
authored
FEAT: Added missing option endpoints (#1171)
1 parent ba5c1a0 commit f269948

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/inc/apiv2/common/AbstractModelAPI.class.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,9 @@ public function getToOneRelationshipLink(Request $request, Response $response, a
878878
/*
879879
* API endpoint to patch a to one relationship link
880880
*/
881-
//This works as intended but it can give weird behaviour. ex. it allows you to put an MD5 hash to a SHA1 hashlist
881+
// TODO This works as intended but it can give weird behaviour. ex. it allows you to put an MD5 hash to a SHA1 hashlist
882882
//by patching the foreingkey. Simple fix could be to make foreignkey immutable for cases like this.
883+
//Or just like with the patch many, create an overrideable function to add more logic in child
883884
public function patchToOneRelationshipLink(Request $request, Response $response, array $args): Response
884885
{
885886
$this->preCommon($request);
@@ -1208,25 +1209,26 @@ static public function register($app): void
12081209
$foo = $me::getDBAClass();
12091210
$baseUri = $me::getBaseUri();
12101211
$baseUriOne = $baseUri . '/{id:[0-9]+}';
1212+
$baseUriCount = $baseUri . "/count";
12111213

12121214
$baseUriRelationships = $baseUri . '/{id:[0-9]+}/relationships';
1215+
$uris = [$baseUri, $baseUriOne, $baseUriCount, $baseUriRelationships];
12131216

12141217
$classMapper = $app->getContainer()->get('classMapper');
12151218
$classMapper->add($me::getDBAclass(), $me);
12161219

12171220
/* Allow CORS preflight requests */
1218-
$app->options($baseUri, function (Request $request, Response $response): Response {
1219-
return $response;
1220-
});
1221-
$app->options($baseUriOne, function (Request $request, Response $response): Response {
1222-
return $response;
1223-
});
1221+
foreach ($uris as $uri) {
1222+
$app->options($uri, function (Request $request, Response $response): Response {
1223+
return $response;
1224+
});
1225+
}
12241226

12251227
$available_methods = $me::getAvailableMethods();
12261228

12271229
if (in_array("GET", $available_methods)) {
12281230
$app->get($baseUri, $me . ':get')->setname($me . ':get');
1229-
$app->get($baseUri . "/count", $me . ':count')->setname($me . ':count');
1231+
$app->get($baseUriCount, $me . ':count')->setname($me . ':count');
12301232
}
12311233

12321234
foreach ($me::getToOneRelationships() as $name => $relationship) {

0 commit comments

Comments
 (0)