37 lines
1.0 KiB
PHP
37 lines
1.0 KiB
PHP
<?php
|
|
require __DIR__ . '/_bootstrap.php';
|
|
|
|
/**
|
|
* @OA\Post(
|
|
* path="/home-owner-detach.php",
|
|
* tags={"Owners"},
|
|
* summary="Detach owner from home",
|
|
* security={{"bearerAuth":{}}},
|
|
* @OA\RequestBody(required=true, @OA\JsonContent(
|
|
* required={"idhome","owner_id"},
|
|
* @OA\Property(property="idhome", type="integer"),
|
|
* @OA\Property(property="owner_id", type="integer")
|
|
* )),
|
|
* @OA\Response(response=200, ref="#/components/responses/Success"),
|
|
* @OA\Response(response=403, ref="#/components/responses/Forbidden")
|
|
* )
|
|
*/
|
|
require_method('POST');
|
|
$user = require_auth($pdo);
|
|
$in = body();
|
|
|
|
$idhome = (int) ($in['idhome'] ?? 0);
|
|
$ownerId = (int) ($in['owner_id'] ?? 0);
|
|
|
|
if ($idhome <= 0 || $ownerId <= 0) {
|
|
json_error(422, 'idhome and owner_id are required');
|
|
}
|
|
if (!user_owns_home($pdo, $user, $idhome)) {
|
|
json_error(403, 'No access to this home');
|
|
}
|
|
|
|
$pdo->prepare('DELETE FROM home_owners WHERE home_id = ? AND owner_id = ?')
|
|
->execute([$idhome, $ownerId]);
|
|
|
|
json_ok();
|