42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
require __DIR__ . '/_bootstrap.php';
|
|
|
|
/**
|
|
* @OA\Post(
|
|
* path="/home-delete.php",
|
|
* tags={"Homes"},
|
|
* summary="Delete property (cascade files and sharing)",
|
|
* security={{"bearerAuth":{}}},
|
|
* @OA\RequestBody(required=true, @OA\JsonContent(
|
|
* required={"idhome"},
|
|
* @OA\Property(property="idhome", 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);
|
|
$idhome = (int) (body()['idhome'] ?? 0);
|
|
|
|
if ($idhome <= 0) {
|
|
json_error(422, 'idhome is required');
|
|
}
|
|
if (!user_owns_home($pdo, $user, $idhome)) {
|
|
json_error(403, 'No access to this home');
|
|
}
|
|
|
|
$pdo->beginTransaction();
|
|
try {
|
|
$pdo->prepare('DELETE FROM doc_storage WHERE idhome = ?')->execute([$idhome]);
|
|
$pdo->prepare('DELETE FROM home_sharing WHERE idhome = ?')->execute([$idhome]);
|
|
$pdo->prepare('DELETE FROM home_owners WHERE home_id = ?')->execute([$idhome]);
|
|
$pdo->prepare('DELETE FROM home WHERE idhome = ? AND iduser = ?')->execute([$idhome, $user['id']]);
|
|
$pdo->commit();
|
|
} catch (Throwable $e) {
|
|
$pdo->rollBack();
|
|
json_error(500, 'Delete failed');
|
|
}
|
|
|
|
json_ok();
|