-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: possibility to delete an ESP directly from the dashboard * feat: create the migration files Closes: #184
- Loading branch information
Showing
6 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- Deploy climat-guardian:delete_esp_permission to pg | ||
|
||
BEGIN; | ||
|
||
grant delete on api.esp to web_user; -- any user can delete ESP | ||
grant delete on api.data to web_user; -- any user can delete ESP's data | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- Revert climat-guardian:delete_esp_permission from pg | ||
|
||
BEGIN; | ||
|
||
revoke delete on api.esp to web_user; -- any user can't anymore delete ESP | ||
revoke delete on api.data to web_user; -- any user can't anymore delete ESP's data | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- Verify climat-guardian:delete_esp_permission on pg | ||
|
||
BEGIN; | ||
|
||
\z api.esp -- check if user can delete or not an ESP | ||
\z api.data -- check if user can delete or not an ESP's data | ||
|
||
ROLLBACK; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Trash2 } from "lucide-react"; | ||
import { getToken } from "@/lib/context"; | ||
|
||
export default function DeleteEsp({ id }: { id: string }) { | ||
const deleteEsp = async (id: string) => { | ||
// Get the id in the URL of the page | ||
const urlData = `/postgrest/data?esp_id=eq.${id}`; | ||
|
||
const url = `/postgrest/esp?id=eq.${id}`; | ||
|
||
try { | ||
const responseData = await fetch(urlData, { | ||
method: "DELETE", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${getToken()}`, | ||
}, | ||
}); | ||
|
||
const response = await fetch(url, { | ||
method: "DELETE", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${getToken()}`, | ||
}, | ||
}); | ||
|
||
window.location.href = `/dashboard`; | ||
|
||
if (!responseData.ok && !response.ok) { | ||
console.error(`une erreur lors de la suppression de l'ESP`); | ||
console.error(await responseData.json()); | ||
console.error(await response.json()); | ||
} | ||
} catch (error) { | ||
console.error("Error: ", error); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="flex cursor-pointer gap-2"> | ||
<Trash2 onClick={() => deleteEsp(id)} /> | ||
</div> | ||
); | ||
} |