Added new design to modals
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
import { getCurrentUser } from '@/lib/auth';
|
||||
import { createNotificationForAllUsers } from '@/lib/notifications';
|
||||
|
||||
// GET - Récupérer un trajet spécifique
|
||||
export async function GET(
|
||||
@@ -103,6 +104,57 @@ export async function PUT(
|
||||
},
|
||||
});
|
||||
|
||||
// Créer une notification si le statut a changé
|
||||
if (statut) {
|
||||
const oldTrajet = await prisma.trajet.findUnique({
|
||||
where: { id: params.id },
|
||||
include: {
|
||||
adherent: {
|
||||
select: {
|
||||
nom: true,
|
||||
prenom: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (oldTrajet && oldTrajet.statut !== statut) {
|
||||
const dateFormatted = new Date(trajet.date).toLocaleDateString('fr-FR', {
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
});
|
||||
|
||||
let notificationType: 'trajet_cancelled' | 'trajet_completed' | null = null;
|
||||
let notificationTitle = '';
|
||||
let notificationMessage = '';
|
||||
|
||||
if (statut === 'Annulé') {
|
||||
notificationType = 'trajet_cancelled';
|
||||
notificationTitle = 'Trajet annulé';
|
||||
notificationMessage = `Le trajet pour ${trajet.adherent.prenom} ${trajet.adherent.nom} du ${dateFormatted} a été annulé`;
|
||||
} else if (statut === 'Terminé') {
|
||||
notificationType = 'trajet_completed';
|
||||
notificationTitle = 'Trajet terminé';
|
||||
notificationMessage = `Le trajet pour ${trajet.adherent.prenom} ${trajet.adherent.nom} du ${dateFormatted} est terminé`;
|
||||
}
|
||||
|
||||
if (notificationType) {
|
||||
await createNotificationForAllUsers(
|
||||
{
|
||||
type: notificationType,
|
||||
title: notificationTitle,
|
||||
message: notificationMessage,
|
||||
link: '/dashboard/calendrier',
|
||||
},
|
||||
user.id
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json(trajet);
|
||||
} catch (error) {
|
||||
console.error('Erreur lors de la mise à jour du trajet:', error);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
import { getCurrentUser } from '@/lib/auth';
|
||||
import { createNotificationForAllUsers } from '@/lib/notifications';
|
||||
|
||||
// GET - Liste tous les trajets avec leurs relations
|
||||
export async function GET(request: NextRequest) {
|
||||
@@ -125,6 +126,25 @@ export async function POST(request: NextRequest) {
|
||||
},
|
||||
});
|
||||
|
||||
// Créer une notification pour tous les utilisateurs sauf celui qui a créé le trajet
|
||||
const dateFormatted = new Date(date).toLocaleDateString('fr-FR', {
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
});
|
||||
|
||||
await createNotificationForAllUsers(
|
||||
{
|
||||
type: 'trajet_created',
|
||||
title: 'Nouveau trajet programmé',
|
||||
message: `Trajet programmé pour ${trajet.adherent.prenom} ${trajet.adherent.nom} le ${dateFormatted}`,
|
||||
link: '/dashboard/calendrier',
|
||||
},
|
||||
user.id
|
||||
);
|
||||
|
||||
return NextResponse.json(trajet, { status: 201 });
|
||||
} catch (error) {
|
||||
console.error('Erreur lors de la création du trajet:', error);
|
||||
|
||||
Reference in New Issue
Block a user