diff --git a/components/calendar/dialog/Delete.vue b/components/calendar/dialog/Delete.vue new file mode 100644 index 0000000..d90fec9 --- /dev/null +++ b/components/calendar/dialog/Delete.vue @@ -0,0 +1,95 @@ + + + + + + Êtes-vous sûr de supprimer ce calendrier ? + + + Les évènements ne seront plus accessibles et vous ne pourrez plus récupérer les données ! + + + + + + + + + + + + + + + + diff --git a/components/calendar/form/DeleteEvent.vue b/components/calendar/form/DeleteEvent.vue index 35e9fce..70ed0ac 100644 --- a/components/calendar/form/DeleteEvent.vue +++ b/components/calendar/form/DeleteEvent.vue @@ -4,7 +4,7 @@ import { PhCircleNotch } from '@phosphor-icons/vue'; const { resetSkeleton, deleteEventFromSkeleton, cancelLatestRequest } = useCalendar() const { isDeleteEventModalOpen, eventSkeleton, lastActiveEvent } = storeToRefs(useCalendar()) -const isLoading = ref(false) +const isLoading = ref(false) const formErrors = reactive<{ message: string | null }>({ message: null @@ -17,7 +17,7 @@ watch(isDeleteEventModalOpen, (hasOpened, _o) => { } }) -async function handleAction() { +async function handleAction(): Promise { if (isLoading.value) return isLoading.value = true @@ -41,7 +41,7 @@ async function handleAction() { * * @param e The closing event (can be keydown or click) */ -function handleClosing(e: Event) { +function handleClosing(e: Event): void { if (isLoading.value) { e.preventDefault() } @@ -52,7 +52,7 @@ function handleClosing(e: Event) { * * Must cancel the abortController in the store, and stop the loading */ -function handleCancel() { +function handleCancel(): void { cancelLatestRequest() isLoading.value = false } diff --git a/components/ui/card/Card.vue b/components/ui/card/Card.vue index 18bebb2..bc0ac40 100644 --- a/components/ui/card/Card.vue +++ b/components/ui/card/Card.vue @@ -11,7 +11,7 @@ const props = defineProps<{ diff --git a/pages/i/world/[id].vue b/pages/i/world/[id].vue index 3e228fe..24c59cc 100644 --- a/pages/i/world/[id].vue +++ b/pages/i/world/[id].vue @@ -1,6 +1,6 @@ @@ -111,7 +124,7 @@ onUnmounted(() => { - alertModalOpened = true"> + isCreateEventModalOpen = true"> @@ -130,11 +143,15 @@ onUnmounted(() => { :link="`/i/calendar/${calendar.id}`" > - {{ calendar.name }} + {{ calendar.name }} Description future (ou alors des informations sur le nb d'évènements) + + + + @@ -148,6 +165,7 @@ onUnmounted(() => { - + + diff --git a/server/api/calendars/[id].delete.ts b/server/api/calendars/[id].delete.ts new file mode 100644 index 0000000..3027393 --- /dev/null +++ b/server/api/calendars/[id].delete.ts @@ -0,0 +1,41 @@ +import { z } from 'zod' +import { serverSupabaseClient } from "#supabase/server" +import type { Calendar } from "~/models/CalendarConfig" + +const paramsSchema = z.object({ + id: z.number({ coerce: true }).positive().int() +}) + +export default defineEventHandler(async (event) => { + const client = await serverSupabaseClient(event) + + const { data: params, error: paramsError} = await getValidatedRouterParams(event, paramsSchema.safeParse) + + if (paramsError) { + throw createError({ + cause: 'Utilisateur', + fatal: false, + message: "L'identifiant du calendrier est manquant ou mal renseigné.", + status: 401, + }) + } + + try { + const { data, error } = await client + .from('calendars') + .delete() + .eq('id', params.id) + .maybeSingle() + + if (error) throw error + + return data + } catch (err) { + throw createError({ + cause: 'Serveur', + status: 500, + fatal: false, + message: 'Une erreur inconnue est survenue.' + }) + } +}) diff --git a/supabase/migrations/202401_init.sql b/supabase/migrations/202401_init.sql index 746cf05..058a91c 100644 --- a/supabase/migrations/202401_init.sql +++ b/supabase/migrations/202401_init.sql @@ -175,19 +175,25 @@ create policy "Allow individual insert access for GMs" on public.worlds for inse create policy "Allow individual update access for GMs" on public.worlds for update using ( auth.uid() = gm_id ); -- Calendar policies -create policy "Allow individual read access for GMs" on public.calendars for select using ( +create policy "Allow GMs to see their calendars" on public.calendars for select using ( exists ( select 1 from worlds where worlds.id = calendars.world_id ) ); -create policy "Allow individual insert access for GMs" on public.calendars for insert with check ( +create policy "Allow GMs to add calendars to their worldd" on public.calendars for insert with check ( exists ( select 1 from worlds where worlds.id = calendars.world_id ) ); -create policy "Allow individual update access for GMs" on public.calendars for update with check ( +create policy "Allow GMs to edit their calendars" on public.calendars for update with check ( + exists ( + select 1 from worlds + where worlds.id = calendars.world_id + ) +); +create policy "Allow GMs to delete their calendars" on public.calendars for delete using ( exists ( select 1 from worlds where worlds.id = calendars.world_id
Description future (ou alors des informations sur le nb d'évènements)