Add event registration and feedback points to site preferences: Update SitePreferences model and related components to include eventRegistrationPoints and eventFeedbackPoints, ensuring proper handling of user scores during event interactions.
This commit is contained in:
@@ -3,6 +3,7 @@ import type { EventRegistration } from "@/prisma/generated/prisma/client";
|
||||
import { ValidationError, NotFoundError, ConflictError } from "../errors";
|
||||
import { eventService } from "./event.service";
|
||||
import { calculateEventStatus } from "@/lib/eventStatus";
|
||||
import { sitePreferencesService } from "../preferences/site-preferences.service";
|
||||
|
||||
/**
|
||||
* Service de gestion des inscriptions aux événements
|
||||
@@ -24,18 +25,39 @@ export class EventRegistrationService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Désinscrit un utilisateur d'un événement
|
||||
* Désinscrit un utilisateur d'un événement et retire les points attribués
|
||||
*/
|
||||
async unregisterUserFromEvent(
|
||||
userId: string,
|
||||
eventId: string
|
||||
): Promise<void> {
|
||||
await prisma.eventRegistration.deleteMany({
|
||||
where: {
|
||||
userId,
|
||||
eventId,
|
||||
},
|
||||
});
|
||||
// Vérifier que l'utilisateur est bien inscrit avant de retirer les points
|
||||
const isRegistered = await this.checkUserRegistration(userId, eventId);
|
||||
if (!isRegistered) {
|
||||
return; // Pas d'inscription, rien à faire
|
||||
}
|
||||
|
||||
// Récupérer les points à retirer depuis les préférences du site
|
||||
const sitePreferences = await sitePreferencesService.getOrCreateSitePreferences();
|
||||
const pointsToRemove = sitePreferences.eventRegistrationPoints || 100;
|
||||
|
||||
// Supprimer l'inscription et retirer les points en parallèle
|
||||
await Promise.all([
|
||||
prisma.eventRegistration.deleteMany({
|
||||
where: {
|
||||
userId,
|
||||
eventId,
|
||||
},
|
||||
}),
|
||||
prisma.user.update({
|
||||
where: { id: userId },
|
||||
data: {
|
||||
score: {
|
||||
decrement: pointsToRemove,
|
||||
},
|
||||
},
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,8 +145,24 @@ export class EventRegistrationService {
|
||||
throw new ConflictError("Vous êtes déjà inscrit à cet événement");
|
||||
}
|
||||
|
||||
// Créer l'inscription
|
||||
return this.registerUserToEvent(userId, eventId);
|
||||
// Récupérer les points à attribuer depuis les préférences du site
|
||||
const sitePreferences = await sitePreferencesService.getOrCreateSitePreferences();
|
||||
const pointsToAward = sitePreferences.eventRegistrationPoints || 100;
|
||||
|
||||
// Créer l'inscription et attribuer les points en parallèle
|
||||
const [registration] = await Promise.all([
|
||||
this.registerUserToEvent(userId, eventId),
|
||||
prisma.user.update({
|
||||
where: { id: userId },
|
||||
data: {
|
||||
score: {
|
||||
increment: pointsToAward,
|
||||
},
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
return registration;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user