chore: mark completion of sessions and SWOT components in devbook.md; add @hello-pangea/dnd dependency for drag & drop functionality
This commit is contained in:
156
src/actions/swot.ts
Normal file
156
src/actions/swot.ts
Normal file
@@ -0,0 +1,156 @@
|
||||
'use server';
|
||||
|
||||
import { revalidatePath } from 'next/cache';
|
||||
import { auth } from '@/lib/auth';
|
||||
import * as sessionsService from '@/services/sessions';
|
||||
import type { SwotCategory } from '@prisma/client';
|
||||
|
||||
// ============================================
|
||||
// SWOT Items Actions
|
||||
// ============================================
|
||||
|
||||
export async function createSwotItem(
|
||||
sessionId: string,
|
||||
data: { content: string; category: SwotCategory }
|
||||
) {
|
||||
const session = await auth();
|
||||
if (!session?.user?.id) {
|
||||
return { success: false, error: 'Non autorisé' };
|
||||
}
|
||||
|
||||
try {
|
||||
const item = await sessionsService.createSwotItem(sessionId, data);
|
||||
revalidatePath(`/sessions/${sessionId}`);
|
||||
return { success: true, data: item };
|
||||
} catch (error) {
|
||||
console.error('Error creating SWOT item:', error);
|
||||
return { success: false, error: 'Erreur lors de la création' };
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateSwotItem(
|
||||
itemId: string,
|
||||
sessionId: string,
|
||||
data: { content?: string; category?: SwotCategory; order?: number }
|
||||
) {
|
||||
const session = await auth();
|
||||
if (!session?.user?.id) {
|
||||
return { success: false, error: 'Non autorisé' };
|
||||
}
|
||||
|
||||
try {
|
||||
const item = await sessionsService.updateSwotItem(itemId, data);
|
||||
revalidatePath(`/sessions/${sessionId}`);
|
||||
return { success: true, data: item };
|
||||
} catch (error) {
|
||||
console.error('Error updating SWOT item:', error);
|
||||
return { success: false, error: 'Erreur lors de la mise à jour' };
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteSwotItem(itemId: string, sessionId: string) {
|
||||
const session = await auth();
|
||||
if (!session?.user?.id) {
|
||||
return { success: false, error: 'Non autorisé' };
|
||||
}
|
||||
|
||||
try {
|
||||
await sessionsService.deleteSwotItem(itemId);
|
||||
revalidatePath(`/sessions/${sessionId}`);
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error('Error deleting SWOT item:', error);
|
||||
return { success: false, error: 'Erreur lors de la suppression' };
|
||||
}
|
||||
}
|
||||
|
||||
export async function moveSwotItem(
|
||||
itemId: string,
|
||||
sessionId: string,
|
||||
newCategory: SwotCategory,
|
||||
newOrder: number
|
||||
) {
|
||||
const session = await auth();
|
||||
if (!session?.user?.id) {
|
||||
return { success: false, error: 'Non autorisé' };
|
||||
}
|
||||
|
||||
try {
|
||||
const item = await sessionsService.moveSwotItem(itemId, newCategory, newOrder);
|
||||
revalidatePath(`/sessions/${sessionId}`);
|
||||
return { success: true, data: item };
|
||||
} catch (error) {
|
||||
console.error('Error moving SWOT item:', error);
|
||||
return { success: false, error: 'Erreur lors du déplacement' };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// Actions CRUD
|
||||
// ============================================
|
||||
|
||||
export async function createAction(
|
||||
sessionId: string,
|
||||
data: {
|
||||
title: string;
|
||||
description?: string;
|
||||
priority?: number;
|
||||
linkedItemIds: string[];
|
||||
}
|
||||
) {
|
||||
const session = await auth();
|
||||
if (!session?.user?.id) {
|
||||
return { success: false, error: 'Non autorisé' };
|
||||
}
|
||||
|
||||
try {
|
||||
const action = await sessionsService.createAction(sessionId, data);
|
||||
revalidatePath(`/sessions/${sessionId}`);
|
||||
return { success: true, data: action };
|
||||
} catch (error) {
|
||||
console.error('Error creating action:', error);
|
||||
return { success: false, error: 'Erreur lors de la création' };
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateAction(
|
||||
actionId: string,
|
||||
sessionId: string,
|
||||
data: {
|
||||
title?: string;
|
||||
description?: string;
|
||||
priority?: number;
|
||||
status?: string;
|
||||
}
|
||||
) {
|
||||
const session = await auth();
|
||||
if (!session?.user?.id) {
|
||||
return { success: false, error: 'Non autorisé' };
|
||||
}
|
||||
|
||||
try {
|
||||
const action = await sessionsService.updateAction(actionId, data);
|
||||
revalidatePath(`/sessions/${sessionId}`);
|
||||
return { success: true, data: action };
|
||||
} catch (error) {
|
||||
console.error('Error updating action:', error);
|
||||
return { success: false, error: 'Erreur lors de la mise à jour' };
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteAction(actionId: string, sessionId: string) {
|
||||
const session = await auth();
|
||||
if (!session?.user?.id) {
|
||||
return { success: false, error: 'Non autorisé' };
|
||||
}
|
||||
|
||||
try {
|
||||
await sessionsService.deleteAction(actionId);
|
||||
revalidatePath(`/sessions/${sessionId}`);
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error('Error deleting action:', error);
|
||||
return { success: false, error: 'Erreur lors de la suppression' };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user