JavaScript 56.7%
TypeScript 42.6%
1import { prisma } from "./prisma";23export async function createNotification(userId: string, type: string, title: string, message: string, data?: Record<string, unknown>) {4 return prisma.notification.create({ data: { userId, type, title, message, data: data ? JSON.stringify(data) : null } });5}67export async function getNotifications(userId: string, unreadOnly = false) {8 const where: Record<string, unknown> = { userId };9 if (unreadOnly) where.read = false;10 return prisma.notification.findMany({ where, orderBy: { createdAt: "desc" }, take: 50 });11}1213export async function markAsRead(notificationId: string) {14 return prisma.notification.update({ where: { id: notificationId }, data: { read: true } });15}1617export async function markAllAsRead(userId: string) {18 return prisma.notification.updateMany({ where: { userId, read: false }, data: { read: true } });19}2021export async function getUnreadCount(userId: string): Promise<number> {22 return prisma.notification.count({ where: { userId, read: false } });23}2425export async function notifyUploadComplete(userId: string, fileName: string, fileId: string) {26 return createNotification(userId, "upload_complete", "Upload terminé", `${fileName} uploadé avec succès`, { fileId });27}2829export async function notifyBackupComplete(userId: string, backupId: string) {30 return createNotification(userId, "backup_complete", "Backup terminé", "Le backup a été créé avec succès", { backupId });31}3233export async function notifyAiComplete(userId: string, fileName: string, action: string) {34 return createNotification(userId, "ai_complete", "Analyse IA", `${action} terminée pour ${fileName}`);35}3637export async function notifyFileComment(userId: string, commenterName: string, fileName: string, fileId: string) {38 return createNotification(userId, "comment", "Nouveau commentaire", `${commenterName} a commenté sur ${fileName}`, { fileId });39}4041export async function notifySharedSpaceUpload(spaceId: string, uploaderUserId: string, fileName: string, fileId: string) {42 const members = await prisma.sharedSpaceMember.findMany({43 where: { sharedSpaceId: spaceId, userId: { not: uploaderUserId } },44 select: { userId: true },45 });46 const uploader = await prisma.user.findUnique({47 where: { id: uploaderUserId },48 select: { name: true, username: true },49 });50 const uploaderName = uploader?.name || uploader?.username || "Quelqu'un";51 for (const member of members) {52 await createNotification(member.userId, "share", "Nouveau fichier partage", `${uploaderName} a ajoute ${fileName}`, { fileId, spaceId });53 }54}55