Refactor admin actions and improve code formatting: Standardize import statements, enhance error handling messages, and apply consistent formatting across event, user, and preference management functions for better readability and maintainability.
Some checks failed
Deploy with Docker Compose / deploy (push) Has been cancelled
Some checks failed
Deploy with Docker Compose / deploy (push) Has been cancelled
This commit is contained in:
@@ -1,73 +1,79 @@
|
||||
'use server'
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { auth } from '@/lib/auth'
|
||||
import { eventService } from '@/services/events/event.service'
|
||||
import { Role, EventType } from '@/prisma/generated/prisma/client'
|
||||
import { ValidationError, NotFoundError } from '@/services/errors'
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { eventService } from "@/services/events/event.service";
|
||||
import { Role, EventType } from "@/prisma/generated/prisma/client";
|
||||
import { ValidationError, NotFoundError } from "@/services/errors";
|
||||
|
||||
function checkAdminAccess() {
|
||||
return async () => {
|
||||
const session = await auth()
|
||||
const session = await auth();
|
||||
if (!session?.user || session.user.role !== Role.ADMIN) {
|
||||
throw new Error('Accès refusé')
|
||||
throw new Error("Accès refusé");
|
||||
}
|
||||
return session
|
||||
}
|
||||
return session;
|
||||
};
|
||||
}
|
||||
|
||||
export async function createEvent(data: {
|
||||
date: string
|
||||
name: string
|
||||
description?: string | null
|
||||
type: string
|
||||
room?: string | null
|
||||
time?: string | null
|
||||
maxPlaces?: number | null
|
||||
date: string;
|
||||
name: string;
|
||||
description?: string | null;
|
||||
type: string;
|
||||
room?: string | null;
|
||||
time?: string | null;
|
||||
maxPlaces?: number | null;
|
||||
}) {
|
||||
try {
|
||||
await checkAdminAccess()()
|
||||
await checkAdminAccess()();
|
||||
|
||||
const event = await eventService.validateAndCreateEvent({
|
||||
date: data.date,
|
||||
name: data.name,
|
||||
description: data.description ?? '',
|
||||
description: data.description ?? "",
|
||||
type: data.type as EventType,
|
||||
room: data.room ?? undefined,
|
||||
time: data.time ?? undefined,
|
||||
maxPlaces: data.maxPlaces ?? undefined,
|
||||
})
|
||||
});
|
||||
|
||||
revalidatePath('/admin')
|
||||
revalidatePath('/events')
|
||||
revalidatePath('/')
|
||||
revalidatePath("/admin");
|
||||
revalidatePath("/events");
|
||||
revalidatePath("/");
|
||||
|
||||
return { success: true, data: event }
|
||||
return { success: true, data: event };
|
||||
} catch (error) {
|
||||
console.error('Error creating event:', error)
|
||||
console.error("Error creating event:", error);
|
||||
|
||||
if (error instanceof ValidationError) {
|
||||
return { success: false, error: error.message }
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
if (error instanceof Error && error.message === 'Accès refusé') {
|
||||
return { success: false, error: 'Accès refusé' }
|
||||
if (error instanceof Error && error.message === "Accès refusé") {
|
||||
return { success: false, error: "Accès refusé" };
|
||||
}
|
||||
|
||||
return { success: false, error: 'Erreur lors de la création de l\'événement' }
|
||||
return {
|
||||
success: false,
|
||||
error: "Erreur lors de la création de l'événement",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateEvent(eventId: string, data: {
|
||||
date?: string
|
||||
name?: string
|
||||
description?: string | null
|
||||
type?: string
|
||||
room?: string | null
|
||||
time?: string | null
|
||||
maxPlaces?: number | null
|
||||
}) {
|
||||
export async function updateEvent(
|
||||
eventId: string,
|
||||
data: {
|
||||
date?: string;
|
||||
name?: string;
|
||||
description?: string | null;
|
||||
type?: string;
|
||||
room?: string | null;
|
||||
time?: string | null;
|
||||
maxPlaces?: number | null;
|
||||
}
|
||||
) {
|
||||
try {
|
||||
await checkAdminAccess()()
|
||||
await checkAdminAccess()();
|
||||
|
||||
const event = await eventService.validateAndUpdateEvent(eventId, {
|
||||
date: data.date,
|
||||
@@ -77,55 +83,60 @@ export async function updateEvent(eventId: string, data: {
|
||||
room: data.room ?? undefined,
|
||||
time: data.time ?? undefined,
|
||||
maxPlaces: data.maxPlaces ?? undefined,
|
||||
})
|
||||
});
|
||||
|
||||
revalidatePath('/admin')
|
||||
revalidatePath('/events')
|
||||
revalidatePath('/')
|
||||
revalidatePath("/admin");
|
||||
revalidatePath("/events");
|
||||
revalidatePath("/");
|
||||
|
||||
return { success: true, data: event }
|
||||
return { success: true, data: event };
|
||||
} catch (error) {
|
||||
console.error('Error updating event:', error)
|
||||
console.error("Error updating event:", error);
|
||||
|
||||
if (error instanceof ValidationError) {
|
||||
return { success: false, error: error.message }
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
if (error instanceof NotFoundError) {
|
||||
return { success: false, error: error.message }
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
if (error instanceof Error && error.message === 'Accès refusé') {
|
||||
return { success: false, error: 'Accès refusé' }
|
||||
if (error instanceof Error && error.message === "Accès refusé") {
|
||||
return { success: false, error: "Accès refusé" };
|
||||
}
|
||||
|
||||
return { success: false, error: 'Erreur lors de la mise à jour de l\'événement' }
|
||||
return {
|
||||
success: false,
|
||||
error: "Erreur lors de la mise à jour de l'événement",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteEvent(eventId: string) {
|
||||
try {
|
||||
await checkAdminAccess()()
|
||||
await checkAdminAccess()();
|
||||
|
||||
const existingEvent = await eventService.getEventById(eventId)
|
||||
const existingEvent = await eventService.getEventById(eventId);
|
||||
|
||||
if (!existingEvent) {
|
||||
return { success: false, error: 'Événement non trouvé' }
|
||||
return { success: false, error: "Événement non trouvé" };
|
||||
}
|
||||
|
||||
await eventService.deleteEvent(eventId)
|
||||
await eventService.deleteEvent(eventId);
|
||||
|
||||
revalidatePath('/admin')
|
||||
revalidatePath('/events')
|
||||
revalidatePath('/')
|
||||
revalidatePath("/admin");
|
||||
revalidatePath("/events");
|
||||
revalidatePath("/");
|
||||
|
||||
return { success: true }
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error('Error deleting event:', error)
|
||||
console.error("Error deleting event:", error);
|
||||
|
||||
if (error instanceof Error && error.message === 'Accès refusé') {
|
||||
return { success: false, error: 'Accès refusé' }
|
||||
if (error instanceof Error && error.message === "Accès refusé") {
|
||||
return { success: false, error: "Accès refusé" };
|
||||
}
|
||||
|
||||
return { success: false, error: 'Erreur lors de la suppression de l\'événement' }
|
||||
return {
|
||||
success: false,
|
||||
error: "Erreur lors de la suppression de l'événement",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,48 +1,50 @@
|
||||
'use server'
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { auth } from '@/lib/auth'
|
||||
import { sitePreferencesService } from '@/services/preferences/site-preferences.service'
|
||||
import { Role } from '@/prisma/generated/prisma/client'
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { sitePreferencesService } from "@/services/preferences/site-preferences.service";
|
||||
import { Role } from "@/prisma/generated/prisma/client";
|
||||
|
||||
function checkAdminAccess() {
|
||||
return async () => {
|
||||
const session = await auth()
|
||||
const session = await auth();
|
||||
if (!session?.user || session.user.role !== Role.ADMIN) {
|
||||
throw new Error('Accès refusé')
|
||||
throw new Error("Accès refusé");
|
||||
}
|
||||
return session
|
||||
}
|
||||
return session;
|
||||
};
|
||||
}
|
||||
|
||||
export async function updateSitePreferences(data: {
|
||||
homeBackground?: string | null
|
||||
eventsBackground?: string | null
|
||||
leaderboardBackground?: string | null
|
||||
homeBackground?: string | null;
|
||||
eventsBackground?: string | null;
|
||||
leaderboardBackground?: string | null;
|
||||
}) {
|
||||
try {
|
||||
await checkAdminAccess()()
|
||||
await checkAdminAccess()();
|
||||
|
||||
const preferences = await sitePreferencesService.updateSitePreferences({
|
||||
homeBackground: data.homeBackground,
|
||||
eventsBackground: data.eventsBackground,
|
||||
leaderboardBackground: data.leaderboardBackground,
|
||||
})
|
||||
});
|
||||
|
||||
revalidatePath('/admin')
|
||||
revalidatePath('/')
|
||||
revalidatePath('/events')
|
||||
revalidatePath('/leaderboard')
|
||||
revalidatePath("/admin");
|
||||
revalidatePath("/");
|
||||
revalidatePath("/events");
|
||||
revalidatePath("/leaderboard");
|
||||
|
||||
return { success: true, data: preferences }
|
||||
return { success: true, data: preferences };
|
||||
} catch (error) {
|
||||
console.error('Error updating admin preferences:', error)
|
||||
console.error("Error updating admin preferences:", error);
|
||||
|
||||
if (error instanceof Error && error.message === 'Accès refusé') {
|
||||
return { success: false, error: 'Accès refusé' }
|
||||
if (error instanceof Error && error.message === "Accès refusé") {
|
||||
return { success: false, error: "Accès refusé" };
|
||||
}
|
||||
|
||||
return { success: false, error: 'Erreur lors de la mise à jour des préférences' }
|
||||
return {
|
||||
success: false,
|
||||
error: "Erreur lors de la mise à jour des préférences",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,47 +1,55 @@
|
||||
'use server'
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { auth } from '@/lib/auth'
|
||||
import { userService } from '@/services/users/user.service'
|
||||
import { userStatsService } from '@/services/users/user-stats.service'
|
||||
import { Role } from '@/prisma/generated/prisma/client'
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { userService } from "@/services/users/user.service";
|
||||
import { userStatsService } from "@/services/users/user-stats.service";
|
||||
import { Role } from "@/prisma/generated/prisma/client";
|
||||
import {
|
||||
ValidationError,
|
||||
NotFoundError,
|
||||
ConflictError,
|
||||
} from '@/services/errors'
|
||||
} from "@/services/errors";
|
||||
|
||||
function checkAdminAccess() {
|
||||
return async () => {
|
||||
const session = await auth()
|
||||
const session = await auth();
|
||||
if (!session?.user || session.user.role !== Role.ADMIN) {
|
||||
throw new Error('Accès refusé')
|
||||
throw new Error("Accès refusé");
|
||||
}
|
||||
return session
|
||||
}
|
||||
return session;
|
||||
};
|
||||
}
|
||||
|
||||
export async function updateUser(userId: string, data: {
|
||||
username?: string
|
||||
avatar?: string | null
|
||||
hpDelta?: number
|
||||
xpDelta?: number
|
||||
score?: number
|
||||
level?: number
|
||||
role?: string
|
||||
}) {
|
||||
export async function updateUser(
|
||||
userId: string,
|
||||
data: {
|
||||
username?: string;
|
||||
avatar?: string | null;
|
||||
hpDelta?: number;
|
||||
xpDelta?: number;
|
||||
score?: number;
|
||||
level?: number;
|
||||
role?: string;
|
||||
}
|
||||
) {
|
||||
try {
|
||||
await checkAdminAccess()()
|
||||
await checkAdminAccess()();
|
||||
|
||||
// Valider username si fourni
|
||||
if (data.username !== undefined) {
|
||||
try {
|
||||
await userService.validateAndUpdateUserProfile(userId, { username: data.username })
|
||||
await userService.validateAndUpdateUserProfile(userId, {
|
||||
username: data.username,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof ValidationError || error instanceof ConflictError) {
|
||||
return { success: false, error: error.message }
|
||||
if (
|
||||
error instanceof ValidationError ||
|
||||
error instanceof ConflictError
|
||||
) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
throw error
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,47 +78,52 @@ export async function updateUser(userId: string, data: {
|
||||
maxXp: true,
|
||||
avatar: true,
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
revalidatePath('/admin')
|
||||
revalidatePath('/leaderboard')
|
||||
revalidatePath("/admin");
|
||||
revalidatePath("/leaderboard");
|
||||
|
||||
return { success: true, data: updatedUser }
|
||||
return { success: true, data: updatedUser };
|
||||
} catch (error) {
|
||||
console.error('Error updating user:', error)
|
||||
console.error("Error updating user:", error);
|
||||
|
||||
if (error instanceof Error && error.message === 'Accès refusé') {
|
||||
return { success: false, error: 'Accès refusé' }
|
||||
if (error instanceof Error && error.message === "Accès refusé") {
|
||||
return { success: false, error: "Accès refusé" };
|
||||
}
|
||||
|
||||
return { success: false, error: 'Erreur lors de la mise à jour de l\'utilisateur' }
|
||||
return {
|
||||
success: false,
|
||||
error: "Erreur lors de la mise à jour de l'utilisateur",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteUser(userId: string) {
|
||||
try {
|
||||
const session = await checkAdminAccess()()
|
||||
const session = await checkAdminAccess()();
|
||||
|
||||
await userService.validateAndDeleteUser(userId, session.user.id)
|
||||
await userService.validateAndDeleteUser(userId, session.user.id);
|
||||
|
||||
revalidatePath('/admin')
|
||||
revalidatePath('/leaderboard')
|
||||
revalidatePath("/admin");
|
||||
revalidatePath("/leaderboard");
|
||||
|
||||
return { success: true }
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error('Error deleting user:', error)
|
||||
console.error("Error deleting user:", error);
|
||||
|
||||
if (error instanceof ValidationError) {
|
||||
return { success: false, error: error.message }
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
if (error instanceof NotFoundError) {
|
||||
return { success: false, error: error.message }
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
if (error instanceof Error && error.message === 'Accès refusé') {
|
||||
return { success: false, error: 'Accès refusé' }
|
||||
if (error instanceof Error && error.message === "Accès refusé") {
|
||||
return { success: false, error: "Accès refusé" };
|
||||
}
|
||||
|
||||
return { success: false, error: 'Erreur lors de la suppression de l\'utilisateur' }
|
||||
return {
|
||||
success: false,
|
||||
error: "Erreur lors de la suppression de l'utilisateur",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,28 @@
|
||||
'use server'
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { auth } from '@/lib/auth'
|
||||
import { challengeService } from '@/services/challenges/challenge.service'
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { challengeService } from "@/services/challenges/challenge.service";
|
||||
import {
|
||||
ValidationError,
|
||||
NotFoundError,
|
||||
ConflictError,
|
||||
} from '@/services/errors'
|
||||
} from "@/services/errors";
|
||||
|
||||
export async function createChallenge(data: {
|
||||
challengedId: string
|
||||
title: string
|
||||
description: string
|
||||
pointsReward?: number
|
||||
challengedId: string;
|
||||
title: string;
|
||||
description: string;
|
||||
pointsReward?: number;
|
||||
}) {
|
||||
try {
|
||||
const session = await auth()
|
||||
const session = await auth();
|
||||
|
||||
if (!session?.user?.id) {
|
||||
return { success: false, error: 'Vous devez être connecté pour créer un défi' }
|
||||
return {
|
||||
success: false,
|
||||
error: "Vous devez être connecté pour créer un défi",
|
||||
};
|
||||
}
|
||||
|
||||
const challenge = await challengeService.createChallenge({
|
||||
@@ -28,85 +31,99 @@ export async function createChallenge(data: {
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
pointsReward: data.pointsReward || 100,
|
||||
})
|
||||
});
|
||||
|
||||
revalidatePath('/challenges')
|
||||
revalidatePath('/profile')
|
||||
revalidatePath("/challenges");
|
||||
revalidatePath("/profile");
|
||||
|
||||
return { success: true, message: 'Défi créé avec succès', data: challenge }
|
||||
return { success: true, message: "Défi créé avec succès", data: challenge };
|
||||
} catch (error) {
|
||||
console.error('Create challenge error:', error)
|
||||
console.error("Create challenge error:", error);
|
||||
|
||||
if (error instanceof ValidationError || error instanceof ConflictError) {
|
||||
return { success: false, error: error.message }
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
if (error instanceof NotFoundError) {
|
||||
return { success: false, error: error.message }
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
||||
return { success: false, error: 'Une erreur est survenue lors de la création du défi' }
|
||||
return {
|
||||
success: false,
|
||||
error: "Une erreur est survenue lors de la création du défi",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export async function acceptChallenge(challengeId: string) {
|
||||
try {
|
||||
const session = await auth()
|
||||
const session = await auth();
|
||||
|
||||
if (!session?.user?.id) {
|
||||
return { success: false, error: 'Vous devez être connecté pour accepter un défi' }
|
||||
return {
|
||||
success: false,
|
||||
error: "Vous devez être connecté pour accepter un défi",
|
||||
};
|
||||
}
|
||||
|
||||
const challenge = await challengeService.acceptChallenge(
|
||||
challengeId,
|
||||
session.user.id
|
||||
)
|
||||
);
|
||||
|
||||
revalidatePath('/challenges')
|
||||
revalidatePath('/profile')
|
||||
revalidatePath("/challenges");
|
||||
revalidatePath("/profile");
|
||||
|
||||
return { success: true, message: 'Défi accepté', data: challenge }
|
||||
return { success: true, message: "Défi accepté", data: challenge };
|
||||
} catch (error) {
|
||||
console.error('Accept challenge error:', error)
|
||||
console.error("Accept challenge error:", error);
|
||||
|
||||
if (error instanceof ValidationError) {
|
||||
return { success: false, error: error.message }
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
if (error instanceof NotFoundError) {
|
||||
return { success: false, error: error.message }
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
||||
return { success: false, error: 'Une erreur est survenue lors de l\'acceptation du défi' }
|
||||
return {
|
||||
success: false,
|
||||
error: "Une erreur est survenue lors de l'acceptation du défi",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export async function cancelChallenge(challengeId: string) {
|
||||
try {
|
||||
const session = await auth()
|
||||
const session = await auth();
|
||||
|
||||
if (!session?.user?.id) {
|
||||
return { success: false, error: 'Vous devez être connecté pour annuler un défi' }
|
||||
return {
|
||||
success: false,
|
||||
error: "Vous devez être connecté pour annuler un défi",
|
||||
};
|
||||
}
|
||||
|
||||
const challenge = await challengeService.cancelChallenge(
|
||||
challengeId,
|
||||
session.user.id
|
||||
)
|
||||
);
|
||||
|
||||
revalidatePath('/challenges')
|
||||
revalidatePath('/profile')
|
||||
revalidatePath("/challenges");
|
||||
revalidatePath("/profile");
|
||||
|
||||
return { success: true, message: 'Défi annulé', data: challenge }
|
||||
return { success: true, message: "Défi annulé", data: challenge };
|
||||
} catch (error) {
|
||||
console.error('Cancel challenge error:', error)
|
||||
console.error("Cancel challenge error:", error);
|
||||
|
||||
if (error instanceof ValidationError) {
|
||||
return { success: false, error: error.message }
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
if (error instanceof NotFoundError) {
|
||||
return { success: false, error: error.message }
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
||||
return { success: false, error: 'Une erreur est survenue lors de l\'annulation du défi' }
|
||||
return {
|
||||
success: false,
|
||||
error: "Une erreur est survenue lors de l'annulation du défi",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,45 +1,47 @@
|
||||
'use server'
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { auth } from '@/lib/auth'
|
||||
import { eventFeedbackService } from '@/services/events/event-feedback.service'
|
||||
import {
|
||||
ValidationError,
|
||||
NotFoundError,
|
||||
} from '@/services/errors'
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { eventFeedbackService } from "@/services/events/event-feedback.service";
|
||||
import { ValidationError, NotFoundError } from "@/services/errors";
|
||||
|
||||
export async function createFeedback(eventId: string, data: {
|
||||
rating: number
|
||||
comment?: string | null
|
||||
}) {
|
||||
export async function createFeedback(
|
||||
eventId: string,
|
||||
data: {
|
||||
rating: number;
|
||||
comment?: string | null;
|
||||
}
|
||||
) {
|
||||
try {
|
||||
const session = await auth()
|
||||
const session = await auth();
|
||||
|
||||
if (!session?.user?.id) {
|
||||
return { success: false, error: 'Non authentifié' }
|
||||
return { success: false, error: "Non authentifié" };
|
||||
}
|
||||
|
||||
const feedback = await eventFeedbackService.validateAndCreateFeedback(
|
||||
session.user.id,
|
||||
eventId,
|
||||
{ rating: data.rating, comment: data.comment }
|
||||
)
|
||||
);
|
||||
|
||||
revalidatePath(`/feedback/${eventId}`)
|
||||
revalidatePath('/events')
|
||||
revalidatePath(`/feedback/${eventId}`);
|
||||
revalidatePath("/events");
|
||||
|
||||
return { success: true, data: feedback }
|
||||
return { success: true, data: feedback };
|
||||
} catch (error) {
|
||||
console.error('Error saving feedback:', error)
|
||||
console.error("Error saving feedback:", error);
|
||||
|
||||
if (error instanceof ValidationError) {
|
||||
return { success: false, error: error.message }
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
if (error instanceof NotFoundError) {
|
||||
return { success: false, error: error.message }
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
||||
return { success: false, error: 'Erreur lors de l\'enregistrement du feedback' }
|
||||
return {
|
||||
success: false,
|
||||
error: "Erreur lors de l'enregistrement du feedback",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,65 +1,77 @@
|
||||
'use server'
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { auth } from '@/lib/auth'
|
||||
import { eventRegistrationService } from '@/services/events/event-registration.service'
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { eventRegistrationService } from "@/services/events/event-registration.service";
|
||||
import {
|
||||
ValidationError,
|
||||
NotFoundError,
|
||||
ConflictError,
|
||||
} from '@/services/errors'
|
||||
} from "@/services/errors";
|
||||
|
||||
export async function registerForEvent(eventId: string) {
|
||||
try {
|
||||
const session = await auth()
|
||||
const session = await auth();
|
||||
|
||||
if (!session?.user?.id) {
|
||||
return { success: false, error: 'Vous devez être connecté pour vous inscrire' }
|
||||
return {
|
||||
success: false,
|
||||
error: "Vous devez être connecté pour vous inscrire",
|
||||
};
|
||||
}
|
||||
|
||||
const registration = await eventRegistrationService.validateAndRegisterUser(
|
||||
session.user.id,
|
||||
eventId
|
||||
)
|
||||
);
|
||||
|
||||
revalidatePath('/events')
|
||||
revalidatePath('/')
|
||||
revalidatePath("/events");
|
||||
revalidatePath("/");
|
||||
|
||||
return { success: true, message: 'Inscription réussie', data: registration }
|
||||
return {
|
||||
success: true,
|
||||
message: "Inscription réussie",
|
||||
data: registration,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Registration error:', error)
|
||||
console.error("Registration error:", error);
|
||||
|
||||
if (error instanceof ValidationError || error instanceof ConflictError) {
|
||||
return { success: false, error: error.message }
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
if (error instanceof NotFoundError) {
|
||||
return { success: false, error: error.message }
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
||||
return { success: false, error: 'Une erreur est survenue lors de l\'inscription' }
|
||||
return {
|
||||
success: false,
|
||||
error: "Une erreur est survenue lors de l'inscription",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export async function unregisterFromEvent(eventId: string) {
|
||||
try {
|
||||
const session = await auth()
|
||||
const session = await auth();
|
||||
|
||||
if (!session?.user?.id) {
|
||||
return { success: false, error: 'Vous devez être connecté' }
|
||||
return { success: false, error: "Vous devez être connecté" };
|
||||
}
|
||||
|
||||
await eventRegistrationService.unregisterUserFromEvent(
|
||||
session.user.id,
|
||||
eventId
|
||||
)
|
||||
);
|
||||
|
||||
revalidatePath('/events')
|
||||
revalidatePath('/')
|
||||
revalidatePath("/events");
|
||||
revalidatePath("/");
|
||||
|
||||
return { success: true, message: 'Inscription annulée' }
|
||||
return { success: true, message: "Inscription annulée" };
|
||||
} catch (error) {
|
||||
console.error('Unregistration error:', error)
|
||||
return { success: false, error: 'Une erreur est survenue lors de l\'annulation' }
|
||||
console.error("Unregistration error:", error);
|
||||
return {
|
||||
success: false,
|
||||
error: "Une erreur est survenue lors de l'annulation",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +1,20 @@
|
||||
'use server'
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { auth } from '@/lib/auth'
|
||||
import { userService } from '@/services/users/user.service'
|
||||
import {
|
||||
ValidationError,
|
||||
NotFoundError,
|
||||
} from '@/services/errors'
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { userService } from "@/services/users/user.service";
|
||||
import { ValidationError, NotFoundError } from "@/services/errors";
|
||||
|
||||
export async function updatePassword(data: {
|
||||
currentPassword: string
|
||||
newPassword: string
|
||||
confirmPassword: string
|
||||
currentPassword: string;
|
||||
newPassword: string;
|
||||
confirmPassword: string;
|
||||
}) {
|
||||
try {
|
||||
const session = await auth()
|
||||
const session = await auth();
|
||||
|
||||
if (!session?.user) {
|
||||
return { success: false, error: 'Non authentifié' }
|
||||
return { success: false, error: "Non authentifié" };
|
||||
}
|
||||
|
||||
await userService.validateAndUpdatePassword(
|
||||
@@ -25,22 +22,24 @@ export async function updatePassword(data: {
|
||||
data.currentPassword,
|
||||
data.newPassword,
|
||||
data.confirmPassword
|
||||
)
|
||||
);
|
||||
|
||||
revalidatePath('/profile')
|
||||
revalidatePath("/profile");
|
||||
|
||||
return { success: true, message: 'Mot de passe modifié avec succès' }
|
||||
return { success: true, message: "Mot de passe modifié avec succès" };
|
||||
} catch (error) {
|
||||
console.error('Error updating password:', error)
|
||||
console.error("Error updating password:", error);
|
||||
|
||||
if (error instanceof ValidationError) {
|
||||
return { success: false, error: error.message }
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
if (error instanceof NotFoundError) {
|
||||
return { success: false, error: error.message }
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
||||
return { success: false, error: 'Erreur lors de la modification du mot de passe' }
|
||||
return {
|
||||
success: false,
|
||||
error: "Erreur lors de la modification du mot de passe",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,22 @@
|
||||
'use server'
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { auth } from '@/lib/auth'
|
||||
import { userService } from '@/services/users/user.service'
|
||||
import { CharacterClass } from '@/prisma/generated/prisma/client'
|
||||
import {
|
||||
ValidationError,
|
||||
ConflictError,
|
||||
} from '@/services/errors'
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { userService } from "@/services/users/user.service";
|
||||
import { CharacterClass } from "@/prisma/generated/prisma/client";
|
||||
import { ValidationError, ConflictError } from "@/services/errors";
|
||||
|
||||
export async function updateProfile(data: {
|
||||
username?: string
|
||||
avatar?: string | null
|
||||
bio?: string | null
|
||||
characterClass?: string | null
|
||||
username?: string;
|
||||
avatar?: string | null;
|
||||
bio?: string | null;
|
||||
characterClass?: string | null;
|
||||
}) {
|
||||
try {
|
||||
const session = await auth()
|
||||
const session = await auth();
|
||||
|
||||
if (!session?.user) {
|
||||
return { success: false, error: 'Non authentifié' }
|
||||
return { success: false, error: "Non authentifié" };
|
||||
}
|
||||
|
||||
const updatedUser = await userService.validateAndUpdateUserProfile(
|
||||
@@ -28,7 +25,9 @@ export async function updateProfile(data: {
|
||||
username: data.username,
|
||||
avatar: data.avatar,
|
||||
bio: data.bio,
|
||||
characterClass: data.characterClass ? (data.characterClass as CharacterClass) : null,
|
||||
characterClass: data.characterClass
|
||||
? (data.characterClass as CharacterClass)
|
||||
: null,
|
||||
},
|
||||
{
|
||||
id: true,
|
||||
@@ -44,20 +43,19 @@ export async function updateProfile(data: {
|
||||
level: true,
|
||||
score: true,
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
revalidatePath('/profile')
|
||||
revalidatePath('/')
|
||||
revalidatePath("/profile");
|
||||
revalidatePath("/");
|
||||
|
||||
return { success: true, data: updatedUser }
|
||||
return { success: true, data: updatedUser };
|
||||
} catch (error) {
|
||||
console.error('Error updating profile:', error)
|
||||
console.error("Error updating profile:", error);
|
||||
|
||||
if (error instanceof ValidationError || error instanceof ConflictError) {
|
||||
return { success: false, error: error.message }
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
|
||||
return { success: false, error: 'Erreur lors de la mise à jour du profil' }
|
||||
return { success: false, error: "Erreur lors de la mise à jour du profil" };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user