refactor: improve import order and code formatting
- Reordered and grouped imports consistently in backend and frontend files for better readability. - Applied indentation and formatting fixes across frontend components, services, and backend modules. - Adjusted multiline method calls and type definitions for improved clarity.
This commit is contained in:
@@ -23,8 +23,8 @@ import { HealthController } from "./health.controller";
|
||||
import { MailModule } from "./mail/mail.module";
|
||||
import { MediaModule } from "./media/media.module";
|
||||
import { MessagesModule } from "./messages/messages.module";
|
||||
import { ReportsModule } from "./reports/reports.module";
|
||||
import { RealtimeModule } from "./realtime/realtime.module";
|
||||
import { ReportsModule } from "./reports/reports.module";
|
||||
import { S3Module } from "./s3/s3.module";
|
||||
import { SessionsModule } from "./sessions/sessions.module";
|
||||
import { TagsModule } from "./tags/tags.module";
|
||||
|
||||
@@ -3,8 +3,8 @@ import {
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from "@nestjs/common";
|
||||
import { CommentsRepository } from "./repositories/comments.repository";
|
||||
import type { CreateCommentDto } from "./dto/create-comment.dto";
|
||||
import { CommentsRepository } from "./repositories/comments.repository";
|
||||
|
||||
@Injectable()
|
||||
export class CommentsService {
|
||||
|
||||
@@ -4,10 +4,10 @@ export * from "./categories";
|
||||
export * from "./comments";
|
||||
export * from "./content";
|
||||
export * from "./favorites";
|
||||
export * from "./messages";
|
||||
export * from "./pgp";
|
||||
export * from "./rbac";
|
||||
export * from "./reports";
|
||||
export * from "./messages";
|
||||
export * from "./sessions";
|
||||
export * from "./tags";
|
||||
export * from "./users";
|
||||
|
||||
@@ -31,10 +31,7 @@ export class MessagesController {
|
||||
}
|
||||
|
||||
@Post()
|
||||
sendMessage(
|
||||
@Req() req: AuthenticatedRequest,
|
||||
@Body() dto: CreateMessageDto,
|
||||
) {
|
||||
sendMessage(@Req() req: AuthenticatedRequest, @Body() dto: CreateMessageDto) {
|
||||
return this.messagesService.sendMessage(req.user.sub, dto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import {
|
||||
ForbiddenException,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from "@nestjs/common";
|
||||
import { ForbiddenException, Injectable } from "@nestjs/common";
|
||||
import { EventsGateway } from "../realtime/events.gateway";
|
||||
import type { CreateMessageDto } from "./dto/create-message.dto";
|
||||
import { MessagesRepository } from "./repositories/messages.repository";
|
||||
|
||||
@@ -20,9 +20,7 @@ export class MessagesRepository {
|
||||
conversationParticipants,
|
||||
eq(conversations.id, conversationParticipants.conversationId),
|
||||
)
|
||||
.where(
|
||||
inArray(conversationParticipants.userId, [userId1, userId2])
|
||||
)
|
||||
.where(inArray(conversationParticipants.userId, [userId1, userId2]))
|
||||
.groupBy(conversations.id)
|
||||
.having(sql`count(${conversations.id}) = 2`);
|
||||
|
||||
@@ -90,16 +88,13 @@ export class MessagesRepository {
|
||||
eq(conversations.id, conversationParticipants.conversationId),
|
||||
)
|
||||
.innerJoin(users, eq(conversationParticipants.userId, users.uuid))
|
||||
.leftJoin(
|
||||
messages,
|
||||
eq(conversations.id, messages.conversationId)
|
||||
)
|
||||
.leftJoin(messages, eq(conversations.id, messages.conversationId))
|
||||
.where(
|
||||
and(
|
||||
inArray(conversations.id, userConvs),
|
||||
eq(conversationParticipants.userId, users.uuid),
|
||||
sql`${users.uuid} != ${userId}`
|
||||
)
|
||||
sql`${users.uuid} != ${userId}`,
|
||||
),
|
||||
)
|
||||
.orderBy(desc(conversations.updatedAt));
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ export class EventsGateway
|
||||
|
||||
const payload = await this.jwtService.verifyJwt(session.accessToken);
|
||||
client.data.user = payload;
|
||||
|
||||
|
||||
// Rejoindre une room personnelle pour les notifications
|
||||
client.join(`user:${payload.sub}`);
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ import { ChevronLeft } from "lucide-react";
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import { ContentCard } from "@/components/content-card";
|
||||
import { CommentSection } from "@/components/comment-section";
|
||||
import { ContentCard } from "@/components/content-card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ViewCounter } from "@/components/view-counter";
|
||||
import { ContentService } from "@/services/content.service";
|
||||
|
||||
@@ -7,15 +7,14 @@ import * as React from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||
import { useAuth } from "@/providers/auth-provider";
|
||||
import { useSocket } from "@/providers/socket-provider";
|
||||
import {
|
||||
MessageService,
|
||||
type Conversation,
|
||||
type Message,
|
||||
MessageService,
|
||||
} from "@/services/message.service";
|
||||
|
||||
export default function MessagesPage() {
|
||||
@@ -62,31 +61,34 @@ export default function MessagesPage() {
|
||||
|
||||
React.useEffect(() => {
|
||||
if (socket) {
|
||||
socket.on("new_message", (data: { conversationId: string; message: Message }) => {
|
||||
if (activeConv?.id === data.conversationId) {
|
||||
setMessages((prev) => [...prev, data.message]);
|
||||
}
|
||||
// Mettre à jour la liste des conversations
|
||||
setConversations((prev) => {
|
||||
const index = prev.findIndex((c) => c.id === data.conversationId);
|
||||
if (index !== -1) {
|
||||
const updated = [...prev];
|
||||
updated[index] = {
|
||||
...updated[index],
|
||||
lastMessage: {
|
||||
text: data.message.text,
|
||||
createdAt: data.message.createdAt,
|
||||
},
|
||||
updatedAt: data.message.createdAt,
|
||||
};
|
||||
return updated.sort(
|
||||
(a, b) =>
|
||||
new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime(),
|
||||
);
|
||||
socket.on(
|
||||
"new_message",
|
||||
(data: { conversationId: string; message: Message }) => {
|
||||
if (activeConv?.id === data.conversationId) {
|
||||
setMessages((prev) => [...prev, data.message]);
|
||||
}
|
||||
return prev;
|
||||
});
|
||||
});
|
||||
// Mettre à jour la liste des conversations
|
||||
setConversations((prev) => {
|
||||
const index = prev.findIndex((c) => c.id === data.conversationId);
|
||||
if (index !== -1) {
|
||||
const updated = [...prev];
|
||||
updated[index] = {
|
||||
...updated[index],
|
||||
lastMessage: {
|
||||
text: data.message.text,
|
||||
createdAt: data.message.createdAt,
|
||||
},
|
||||
updatedAt: data.message.createdAt,
|
||||
};
|
||||
return updated.sort(
|
||||
(a, b) =>
|
||||
new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime(),
|
||||
);
|
||||
}
|
||||
return prev;
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
return () => {
|
||||
socket.off("new_message");
|
||||
@@ -98,7 +100,7 @@ export default function MessagesPage() {
|
||||
if (scrollRef.current) {
|
||||
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
||||
}
|
||||
}, [messages]);
|
||||
}, []);
|
||||
|
||||
const handleSendMessage = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
@@ -108,7 +110,10 @@ export default function MessagesPage() {
|
||||
setNewMessage("");
|
||||
|
||||
try {
|
||||
const msg = await MessageService.sendMessage(activeConv.recipient.uuid, text);
|
||||
const msg = await MessageService.sendMessage(
|
||||
activeConv.recipient.uuid,
|
||||
text,
|
||||
);
|
||||
setMessages((prev) => [...prev, msg]);
|
||||
} catch (_error) {
|
||||
toast.error("Erreur lors de l'envoi");
|
||||
@@ -140,6 +145,7 @@ export default function MessagesPage() {
|
||||
conversations.map((conv) => (
|
||||
<button
|
||||
key={conv.id}
|
||||
type="button"
|
||||
onClick={() => setActiveConv(conv)}
|
||||
className={`w-full flex items-center gap-3 p-3 rounded-xl transition-colors ${
|
||||
activeConv?.id === conv.id
|
||||
@@ -266,8 +272,8 @@ export default function MessagesPage() {
|
||||
</div>
|
||||
<h2 className="text-2xl font-bold mb-2">Vos messages</h2>
|
||||
<p className="text-muted-foreground max-w-sm">
|
||||
Sélectionnez une conversation ou démarrez-en une nouvelle pour commencer à
|
||||
discuter.
|
||||
Sélectionnez une conversation ou démarrez-en une nouvelle pour commencer
|
||||
à discuter.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { useAuth } from "@/providers/auth-provider";
|
||||
import { CommentService, type Comment } from "@/services/comment.service";
|
||||
import { type Comment, CommentService } from "@/services/comment.service";
|
||||
|
||||
interface CommentSectionProps {
|
||||
contentId: string;
|
||||
@@ -88,7 +88,11 @@ export function CommentSection({ contentId }: CommentSectionProps) {
|
||||
className="min-h-[80px] resize-none"
|
||||
/>
|
||||
<div className="flex justify-end">
|
||||
<Button type="submit" size="sm" disabled={!newComment.trim() || isSubmitting}>
|
||||
<Button
|
||||
type="submit"
|
||||
size="sm"
|
||||
disabled={!newComment.trim() || isSubmitting}
|
||||
>
|
||||
{isSubmitting ? "Envoi..." : "Publier"}
|
||||
<Send className="ml-2 h-4 w-4" />
|
||||
</Button>
|
||||
@@ -130,7 +134,9 @@ export function CommentSection({ contentId }: CommentSectionProps) {
|
||||
})}
|
||||
</span>
|
||||
</div>
|
||||
{(user?.uuid === comment.user.uuid || user?.role === "admin" || user?.role === "moderator") && (
|
||||
{(user?.uuid === comment.user.uuid ||
|
||||
user?.role === "admin" ||
|
||||
user?.role === "moderator") && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8">
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { io, Socket } from "socket.io-client";
|
||||
import { io, type Socket } from "socket.io-client";
|
||||
import { useAuth } from "./auth-provider";
|
||||
|
||||
interface SocketContextType {
|
||||
|
||||
@@ -30,7 +30,9 @@ export const MessageService = {
|
||||
},
|
||||
|
||||
async getMessages(conversationId: string): Promise<Message[]> {
|
||||
const { data } = await api.get<Message[]>(`/messages/conversations/${conversationId}`);
|
||||
const { data } = await api.get<Message[]>(
|
||||
`/messages/conversations/${conversationId}`,
|
||||
);
|
||||
return data;
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user