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