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:
@@ -2,6 +2,7 @@ import { prisma } from "../database";
|
||||
import type { EventFeedback, Prisma } from "@/prisma/generated/prisma/client";
|
||||
import { ValidationError, NotFoundError } from "../errors";
|
||||
import { eventService } from "./event.service";
|
||||
import { sitePreferencesService } from "../preferences/site-preferences.service";
|
||||
|
||||
export interface CreateOrUpdateFeedbackInput {
|
||||
rating: number;
|
||||
@@ -168,11 +169,34 @@ export class EventFeedbackService {
|
||||
throw new NotFoundError("Événement");
|
||||
}
|
||||
|
||||
// Créer ou mettre à jour le feedback
|
||||
return this.createOrUpdateFeedback(userId, eventId, {
|
||||
rating: data.rating,
|
||||
comment: data.comment || null,
|
||||
});
|
||||
// Vérifier si c'est un nouveau feedback ou une mise à jour
|
||||
const existingFeedback = await this.getUserFeedback(userId, eventId);
|
||||
const isNewFeedback = !existingFeedback;
|
||||
|
||||
// Récupérer les points à attribuer depuis les préférences du site
|
||||
const sitePreferences = await sitePreferencesService.getOrCreateSitePreferences();
|
||||
const pointsToAward = sitePreferences.eventFeedbackPoints || 100;
|
||||
|
||||
// Créer ou mettre à jour le feedback et attribuer les points (seulement pour nouveau feedback)
|
||||
const [feedback] = await Promise.all([
|
||||
this.createOrUpdateFeedback(userId, eventId, {
|
||||
rating: data.rating,
|
||||
comment: data.comment || null,
|
||||
}),
|
||||
// Attribuer les points seulement si c'est un nouveau feedback
|
||||
isNewFeedback
|
||||
? prisma.user.update({
|
||||
where: { id: userId },
|
||||
data: {
|
||||
score: {
|
||||
increment: pointsToAward,
|
||||
},
|
||||
},
|
||||
})
|
||||
: Promise.resolve(null),
|
||||
]);
|
||||
|
||||
return feedback;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user