From f3c5c8f3a69848f473cf157a267bc2a3d16d83b1 Mon Sep 17 00:00:00 2001 From: Azeddine Hamdaoui Date: Sat, 16 Dec 2023 17:30:02 +0100 Subject: [PATCH 1/2] declare type for req.files --- backend/src/api/auth/auth-controller.ts | 14 ++++---------- backend/types/express.d.ts | 4 ++++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/backend/src/api/auth/auth-controller.ts b/backend/src/api/auth/auth-controller.ts index 2b4bb9c..a2584e8 100644 --- a/backend/src/api/auth/auth-controller.ts +++ b/backend/src/api/auth/auth-controller.ts @@ -12,18 +12,15 @@ export async function register(req: Request, res: Response) { const registerDto = plainToClass(RegisterDto, req.body); const validationError = await validate(registerDto); if (validationError.length > 0) return res.status(400).json(validationError); - const user = await authService.registerUser(registerDto); - res.status(201).send(); + await authService.registerUser(registerDto); + res.status(204).send(); } export async function uploadAvatar(req: Request, res: Response) { const user = await authService.getUser(req.body.email, req.body.password); - const avatar = await profileService.uploadAvatar( - user, - req.files['avatar'][0] - ); + await profileService.uploadAvatar(user, req.files['avatar'][0]); await authService.sendEmailVerification(user); - res.status(201).send({ url: avatar.url }); + res.status(204).send(); } export async function login(req: Request, res: Response) { @@ -40,9 +37,6 @@ export async function verifyEmail(req: Request, res: Response) { const validationError = await validate(verifyEmailDto); if (validationError.length > 0) return res.status(400).json(validationError); const user = await authService.verifyEmail(verifyEmailDto.code); - res.status(200).send(); - return; - const { token } = await authService.login(user.email); res.cookie(`${process.env.JWT_COOKIE_NAME}`, token, defaultCookieOptions); res.status(200).send(); diff --git a/backend/types/express.d.ts b/backend/types/express.d.ts index 0d40d66..8ad45f9 100644 --- a/backend/types/express.d.ts +++ b/backend/types/express.d.ts @@ -3,4 +3,8 @@ declare namespace Express { id: number; username: string; } + + export interface Request { + files: { [filename: string]: Express.Multer.File[] }; + } } From bdbe7edf0684f3425b404a623511d7a8c53199e2 Mon Sep 17 00:00:00 2001 From: Azeddine Hamdaoui Date: Sat, 16 Dec 2023 17:37:38 +0100 Subject: [PATCH 2/2] separate global template --- frontend/app/layout.tsx | 4 +-- frontend/app/test/page.tsx | 7 ----- .../components/molecules/dropdown-menu.tsx | 1 + .../molecules/search-result-new.tsx | 2 +- .../components/templates/global-config.tsx | 26 +++++++++++++++++++ frontend/components/templates/global.tsx | 26 +------------------ 6 files changed, 31 insertions(+), 35 deletions(-) delete mode 100644 frontend/app/test/page.tsx create mode 100644 frontend/components/templates/global-config.tsx diff --git a/frontend/app/layout.tsx b/frontend/app/layout.tsx index 6b91b7c..525df5f 100644 --- a/frontend/app/layout.tsx +++ b/frontend/app/layout.tsx @@ -1,7 +1,7 @@ import "./globals.css"; import React from "react"; import { Inter } from "next/font/google"; -import { GlobalTemplateConfig } from "@/components/templates/global"; +import GlobalTemplateConfig from "@/components/templates/global-config"; export const metadata = { title: "ChiChat | Chat and Hang Out With Friends", @@ -19,7 +19,7 @@ export default function RootLayout({ return ( - {children} + {children} ); diff --git a/frontend/app/test/page.tsx b/frontend/app/test/page.tsx deleted file mode 100644 index 943b6d6..0000000 --- a/frontend/app/test/page.tsx +++ /dev/null @@ -1,7 +0,0 @@ -export default function Test() { - return ( -
-

Test Page

-
- ); -} diff --git a/frontend/components/molecules/dropdown-menu.tsx b/frontend/components/molecules/dropdown-menu.tsx index f5db050..64d9714 100644 --- a/frontend/components/molecules/dropdown-menu.tsx +++ b/frontend/components/molecules/dropdown-menu.tsx @@ -59,6 +59,7 @@ function FloatingMenu({ fireItemSelection(); setInputKeyPress(""); } + // eslint-disable-next-line }, [inputkeyPress, setInputKeyPress, items.length]); return ( diff --git a/frontend/components/molecules/search-result-new.tsx b/frontend/components/molecules/search-result-new.tsx index ea86de0..869557d 100644 --- a/frontend/components/molecules/search-result-new.tsx +++ b/frontend/components/molecules/search-result-new.tsx @@ -31,7 +31,7 @@ export default function SearchResults({ .toLowerCase() .includes(searchText.toLowerCase()) ), - [results, searchText] + [results, searchText, targetKey] ); return ( diff --git a/frontend/components/templates/global-config.tsx b/frontend/components/templates/global-config.tsx new file mode 100644 index 0000000..bf6c275 --- /dev/null +++ b/frontend/components/templates/global-config.tsx @@ -0,0 +1,26 @@ +"use client"; + +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { ReactQueryDevtools } from "@tanstack/react-query-devtools"; +import GlobalTemplate from "./global"; + +const queryClient = new QueryClient(); + +export type GlobalTemplateConfigProps = { + children?: React.ReactNode; +}; + +export default function GlobalTemplateConfig({ + children, +}: { + children: React.ReactNode; +}) { + return ( + <> + + {children} + + + + ); +} diff --git a/frontend/components/templates/global.tsx b/frontend/components/templates/global.tsx index a66a68e..8a5481f 100644 --- a/frontend/components/templates/global.tsx +++ b/frontend/components/templates/global.tsx @@ -1,40 +1,16 @@ "use client"; -import { - QueryClient, - QueryClientProvider, - useMutation, -} from "@tanstack/react-query"; +import { useMutation } from "@tanstack/react-query"; import React, { useEffect, useState } from "react"; import { io } from "socket.io-client"; import { api } from "@/config"; -import { ReactQueryDevtools } from "@tanstack/react-query-devtools"; let pathWhitelist = ["/login", "/register", "/verify-email"]; -if (process.env.NODE_ENV === "development") pathWhitelist.push("/test"); - type GlobalTemplateProps = { children?: React.ReactNode; }; -const queryClient = new QueryClient(); - -export function GlobalTemplateConfig({ - children, -}: { - children: React.ReactNode; -}) { - return ( - <> - - {children} - - - - ); -} - export default function GlobalTemplate({ children }: GlobalTemplateProps) { const [onRender, setOnRender] = useState(false);