Update mutate delete for db collection
This commit is contained in:
parent
71a0cb59b5
commit
b78b71b260
1 changed files with 34 additions and 3 deletions
|
@ -607,15 +607,46 @@ class Builder
|
|||
return self::mutateCreate($utopia, $request, $response, $dbForProject, $collectionId);
|
||||
}
|
||||
|
||||
private static function mutateDelete(string $collectionId, Database $dbForProject): callable
|
||||
private static function mutateDelete(
|
||||
App $utopia,
|
||||
Request $request,
|
||||
Response $response,
|
||||
Database $dbForProject,
|
||||
string $collectionId
|
||||
): callable
|
||||
{
|
||||
return fn($type, $args, $context, $info) => new CoroutinePromise(
|
||||
function (callable $resolve, callable $reject) use ($collectionId, $type, $args, $dbForProject) {
|
||||
function (callable $resolve, callable $reject) use ($utopia, $request, $response, $dbForProject, $collectionId, $type, $args) {
|
||||
$swooleRq = $request->getSwoole();
|
||||
|
||||
$swooleRq->post = [
|
||||
'collectionId' => $collectionId,
|
||||
'documentId' => $args['id'],
|
||||
];
|
||||
// Drop json content type so post args are used directly
|
||||
if (\array_key_exists('content-type', $swooleRq->header)
|
||||
&& $swooleRq->header['content-type'] === 'application/json') {
|
||||
unset($swooleRq->header['content-type']);
|
||||
}
|
||||
|
||||
$url = '/v1/database/collections/:collectionId/documents/:documentId';
|
||||
$route = $utopia->getRoutes()['DELETE'][$url];
|
||||
|
||||
$request = new Request($swooleRq);
|
||||
$response = new Response($response->getSwoole());
|
||||
|
||||
$utopia->setResource('request', fn() => $request);
|
||||
$utopia->setResource('response', fn() => $response);
|
||||
|
||||
$response->setContentType(Response::CONTENT_TYPE_NULL);
|
||||
|
||||
try {
|
||||
$resolve($dbForProject->deleteDocument($collectionId, $args['id']));
|
||||
$utopia->setRoute($route)->execute($route, $request);
|
||||
} catch (\Throwable $e) {
|
||||
$reject($e);
|
||||
}
|
||||
|
||||
$resolve($response->getPayload());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue