From 3ae3f1d797aa6f652b06c9e04fadfacd459f43e5 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Sun, 19 Apr 2026 15:36:45 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Final:=20Fix=20stats,=20staff=20?= =?UTF-8?q?list,=20settings=20profile,=20and=20logout=20redirect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/modules/auth/auth.controller.ts | 10 ++++++++ backend/src/modules/auth/auth.service.ts | 23 +++++++++++++++++++ .../modules/dashboard/dashboard.service.ts | 7 ------ frontend/src/components/layout/Sidebar.tsx | 10 ++++++-- frontend/src/pages/staff/StaffPage.tsx | 4 ++-- 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/backend/src/modules/auth/auth.controller.ts b/backend/src/modules/auth/auth.controller.ts index cd64f2f..85a9f4e 100644 --- a/backend/src/modules/auth/auth.controller.ts +++ b/backend/src/modules/auth/auth.controller.ts @@ -62,6 +62,16 @@ export class AuthController { return this.authService.logout(user.id); } + /** + * الملف الشخصي الحالي والبيانات الأساسية + */ + @UseGuards(JwtAuthGuard) + @Get('me') + @HttpCode(HttpStatus.OK) + async me(@CurrentUser() user: any) { + return this.authService.getMe(user.id); + } + /** * الملف الشخصي */ diff --git a/backend/src/modules/auth/auth.service.ts b/backend/src/modules/auth/auth.service.ts index a8a45e5..9ca8dec 100644 --- a/backend/src/modules/auth/auth.service.ts +++ b/backend/src/modules/auth/auth.service.ts @@ -179,6 +179,29 @@ export class AuthService { }; } + /** + * الحصول على بيانات المستخدم والاشتراك الحالي + */ + async getMe(userId: string) { + const user = await this.dataSource.getRepository(User).findOne({ + where: { id: userId }, + relations: ['tenant'], + }); + + if (!user) throw new UnauthorizedException(); + + return { + user: { + id: user.id, + name: user.name, + email: user.email, + role: user.role, + tenantId: user.tenant_id, + }, + tenant: user.tenant, + }; + } + /** * تسجيل خروج */ diff --git a/backend/src/modules/dashboard/dashboard.service.ts b/backend/src/modules/dashboard/dashboard.service.ts index 5ede99a..035cb5e 100644 --- a/backend/src/modules/dashboard/dashboard.service.ts +++ b/backend/src/modules/dashboard/dashboard.service.ts @@ -22,13 +22,6 @@ export class DashboardService { where: { tenant_id: tenantId, status: InvoiceStatus.APPROVED }, }); - const pendingInvoices = await this.invoiceRepository.count({ - where: { - tenant_id: tenantId, - status: Buffer.from('approved').toString() === InvoiceStatus.APPROVED ? InvoiceStatus.UPLOADED : InvoiceStatus.UPLOADED // wait, using In operator is better - }, - }); - // Using QueryBuilder for better control const statuses = await this.invoiceRepository .createQueryBuilder('invoice') diff --git a/frontend/src/components/layout/Sidebar.tsx b/frontend/src/components/layout/Sidebar.tsx index 22e96da..707467f 100644 --- a/frontend/src/components/layout/Sidebar.tsx +++ b/frontend/src/components/layout/Sidebar.tsx @@ -4,7 +4,7 @@ * ════════════════════════════════════════════════════════════ */ -import { NavLink } from 'react-router-dom'; +import { NavLink, useNavigate } from 'react-router-dom'; import { LayoutDashboard, FileText, @@ -24,8 +24,14 @@ const menuItems = [ ]; export const Sidebar = () => { + const navigate = useNavigate(); const clearAuth = useAuthStore((state) => state.clearAuth); + const handleLogout = () => { + clearAuth(); + navigate('/login'); + }; + return (