Skip to content

Commit

Permalink
Merge pull request #16 from azeddine-hmd/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
azeddine-hmd authored Dec 16, 2023
2 parents a30a07f + bdbe7ed commit 69f72e2
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 45 deletions.
14 changes: 4 additions & 10 deletions backend/src/api/auth/auth-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions backend/types/express.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ declare namespace Express {
id: number;
username: string;
}

export interface Request {
files: { [filename: string]: Express.Multer.File[] };
}
}
4 changes: 2 additions & 2 deletions frontend/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -19,7 +19,7 @@ export default function RootLayout({
return (
<html lang="en">
<body className={inter.className}>
<GlobalTemplateConfig>{children}</GlobalTemplateConfig>
<GlobalTemplateConfig>{children}</GlobalTemplateConfig>
</body>
</html>
);
Expand Down
7 changes: 0 additions & 7 deletions frontend/app/test/page.tsx

This file was deleted.

1 change: 1 addition & 0 deletions frontend/components/molecules/dropdown-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function FloatingMenu({
fireItemSelection();
setInputKeyPress("");
}
// eslint-disable-next-line
}, [inputkeyPress, setInputKeyPress, items.length]);

return (
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/molecules/search-result-new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function SearchResults<T>({
.toLowerCase()
.includes(searchText.toLowerCase())
),
[results, searchText]
[results, searchText, targetKey]
);

return (
Expand Down
26 changes: 26 additions & 0 deletions frontend/components/templates/global-config.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
<QueryClientProvider client={queryClient}>
<GlobalTemplate>{children}</GlobalTemplate>
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
</>
);
}
26 changes: 1 addition & 25 deletions frontend/components/templates/global.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
<QueryClientProvider client={queryClient}>
<GlobalTemplate>{children}</GlobalTemplate>
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
</>
);
}

export default function GlobalTemplate({ children }: GlobalTemplateProps) {
const [onRender, setOnRender] = useState(false);

Expand Down

0 comments on commit 69f72e2

Please sign in to comment.