diff --git a/backend/src/main.ts b/backend/src/main.ts index f381fe3..bbde0f4 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -7,7 +7,7 @@ async function bootstrap(): Promise { app.enableCors({ origin: 'http://localhost:5173', // replace with your client's origin methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', - allowedHeaders: 'Content-Type, Accept, Authorization', + allowedHeaders: 'Content-Type, Accept, Authorization, Cache-Control', credentials: true }); const config = new DocumentBuilder() diff --git a/backend/src/modules/product/entities/product.entity.ts b/backend/src/modules/product/entities/product.entity.ts index c7316c9..8a6c188 100644 --- a/backend/src/modules/product/entities/product.entity.ts +++ b/backend/src/modules/product/entities/product.entity.ts @@ -8,12 +8,12 @@ import { } from 'typeorm'; export enum ProductStatus { - REVIEWING, - PUBLISHED, - EXCHANGING, - EXCHANGED, - BANNED, - REMOVED + REVIEWING = 'REVIEWING', + PUBLISHED = 'PUBLISHED', + EXCHANGING = 'EXCHANGING', + EXCHANGED = 'EXCHANGED', + BANNED = 'BANNED', + REMOVED = 'REMOVED' } @Entity('products') diff --git a/backend/src/modules/transactions/entities/ExchangeEntity.ts b/backend/src/modules/transactions/entities/ExchangeEntity.ts index 51c8e16..a77dc27 100644 --- a/backend/src/modules/transactions/entities/ExchangeEntity.ts +++ b/backend/src/modules/transactions/entities/ExchangeEntity.ts @@ -8,9 +8,9 @@ import { } from 'typeorm'; export enum ExchangeStatus { - PENDING, - ACCEPTED, - REJECTED + PENDING = 'PENDING', + ACCEPTED = 'ACCEPTED', + REJECTED = 'REJECTED' } @Entity('exchange') diff --git a/backend/src/modules/transactions/web/exchange-request.controller.ts b/backend/src/modules/transactions/web/exchange-request.controller.ts index 191a8f2..c79a7bd 100644 --- a/backend/src/modules/transactions/web/exchange-request.controller.ts +++ b/backend/src/modules/transactions/web/exchange-request.controller.ts @@ -16,6 +16,7 @@ import { } from '../../user/notification.entity'; @Controller('exchanges') +@UseGuards(JwtAuthGuard) export class ExchangeRequestController { constructor( private readonly productService: ProductService, @@ -24,7 +25,6 @@ export class ExchangeRequestController { ) {} @Post('/accept/:exchangeId') - @UseGuards(JwtAuthGuard) async acceptExchangeRequest( @Param('exchangeId') exchangeId: number ): Promise { @@ -49,7 +49,6 @@ export class ExchangeRequestController { } @Post('/reject/:exchangeId') - @UseGuards(JwtAuthGuard) async rejectExchangeRequest( @Param('exchangeId') exchangeId: number ): Promise { @@ -74,7 +73,6 @@ export class ExchangeRequestController { } @Post('/request') - @UseGuards(JwtAuthGuard) async create( @Body() exchangeRequestBody: ExchangeRequestBodyDto ): Promise { @@ -97,10 +95,6 @@ export class ExchangeRequestController { productExchanged, exchangeRequest ); - void this.changeStatusOfProductToExchanging( - exchangeRequestBody.productId, - exchangeRequestBody.productToExchangeId - ); return exchangeRequest; }); } diff --git a/backend/src/modules/user/notification.entity.ts b/backend/src/modules/user/notification.entity.ts index ae97fd7..d2b0bfd 100644 --- a/backend/src/modules/user/notification.entity.ts +++ b/backend/src/modules/user/notification.entity.ts @@ -9,7 +9,7 @@ import { import {UserEntity} from './user.entity'; export enum NotificationType { - EXCHANGE_REQUEST + EXCHANGE_REQUEST = 'EXCHANGE_REQUEST' } @Entity('notifications') diff --git a/backend/src/modules/user/user.entity.ts b/backend/src/modules/user/user.entity.ts index f07c57f..a2285b6 100644 --- a/backend/src/modules/user/user.entity.ts +++ b/backend/src/modules/user/user.entity.ts @@ -11,8 +11,8 @@ import {PartialType} from '@nestjs/swagger'; import {NotificationEntity} from './notification.entity'; export enum UserStatus { - ACTIVE, - BANNED + ACTIVE = 'ACTIVE', + BANNED = 'BANNED' } @Entity('users') diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index 2b7ab13..84263d5 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -8,18 +8,20 @@ import './index.css'; import '@assets/styles/styles.scss'; import {AuthProviderProps} from 'oidc-react/build/src/AuthContextInterface'; import {AuthProvider} from 'oidc-react'; +import React from 'react'; const oidcConfig: AuthProviderProps = { authority: import.meta.env.VITE_APP_AUTHORITY as string, clientId: import.meta.env.VITE_APP_CLIENT_ID as string, responseType: 'code', - redirectUri: import.meta.env.VITE_APP_REDIRECT_URI as string + redirectUri: import.meta.env.VITE_APP_REDIRECT_URI as string, + autoSignIn: false }; ReactDOM.createRoot(document.getElementById('root')!).render( - // - - - - // + + + + + ); diff --git a/frontend/src/modules/homepage/model/productDto.ts b/frontend/src/modules/homepage/model/productDto.ts index b0a5bb7..51a9711 100644 --- a/frontend/src/modules/homepage/model/productDto.ts +++ b/frontend/src/modules/homepage/model/productDto.ts @@ -17,12 +17,12 @@ export interface ProductDTO { } export enum ProductStatus { - REVIEWING, - PUBLISHED, - EXCHANGING, - EXCHANGED, - BANNED, - REMOVED + REVIEWING = 'REVIEWING', + PUBLISHED = 'PUBLISHED', + EXCHANGING = 'EXCHANGING', + EXCHANGED = 'EXCHANGED', + BANNED = 'BANNED', + REMOVED = 'REMOVED' } export const getProductStatusDisplay = ( diff --git a/frontend/src/modules/shared/components/header/AppHeader.tsx b/frontend/src/modules/shared/components/header/AppHeader.tsx index 7c2f53a..9714cd3 100644 --- a/frontend/src/modules/shared/components/header/AppHeader.tsx +++ b/frontend/src/modules/shared/components/header/AppHeader.tsx @@ -10,12 +10,14 @@ import {formatDistanceToNow} from 'date-fns'; import {vi} from 'date-fns/locale'; import {ExchangeResponseModal} from '../../../transactions/components/exchange-response-modal/ExchangeResponseModal.tsx'; import {useModal} from '../modal/useModal.tsx'; +import {useApplicationService} from '../../services/application.service.ts'; export default function AppHeader({ currentUser }: { currentUser: UserDto | null; }): ReactElement { + const applicationService = useApplicationService(); const navigate = useNavigate(); const [showNotifications, setShowNotifications] = useState(false); const modalContext = useModal(); @@ -183,13 +185,16 @@ export default function AppHeader({
!currentUser && applicationService.signIn()} >
- {currentUser?.firstName} {currentUser?.lastName} + {currentUser + ? `${currentUser.firstName} ${currentUser.lastName}` + : 'Login'}
diff --git a/frontend/src/modules/shared/models/userDto.ts b/frontend/src/modules/shared/models/userDto.ts index 925c685..5a2adbe 100644 --- a/frontend/src/modules/shared/models/userDto.ts +++ b/frontend/src/modules/shared/models/userDto.ts @@ -18,5 +18,5 @@ export interface NotificationDto { } export enum NotificationType { - EXCHANGE_REQUEST + EXCHANGE_REQUEST = 'EXCHANGE_REQUEST' } diff --git a/frontend/src/modules/shared/services/application.service.ts b/frontend/src/modules/shared/services/application.service.ts index 5aecf61..36f9bd2 100644 --- a/frontend/src/modules/shared/services/application.service.ts +++ b/frontend/src/modules/shared/services/application.service.ts @@ -28,17 +28,19 @@ class ApplicationService { return response.data; } + public signIn(): void { + void this.auth?.signIn(); + } + public signOutRedirect(): void { - if (this.auth) { - this.auth - .signOutRedirect() - .then(() => { - alert('Successfully logged out'); - }) - .catch(error => { - alert(error); - }); - } + this.auth + ?.signOutRedirect() + .then(() => { + alert('Successfully logged out'); + }) + .catch(error => { + alert(error); + }); } public isAuthenticated(): boolean { @@ -48,12 +50,12 @@ class ApplicationService { public createApiClient(): AxiosInstance { const apiClient: AxiosInstance = axios.create(); const accessToken: string | undefined = this.auth?.userData?.access_token; - apiClient.interceptors.request.use( config => { if (accessToken) { config.headers.Authorization = `Bearer ${accessToken}`; } + config.headers['Cache-Control'] = 'no-cache'; this.startLoading(); return config; },