Skip to content

Commit cd130dd

Browse files
committed
Add base code for matching service
1 parent dc7cd77 commit cd130dd

27 files changed

+9770
-5
lines changed

backend/docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ services:
1919
- question-service
2020
- user-service
2121
- auth-service
22+
- matching-service
2223
networks:
2324
- backend-network
2425

@@ -70,6 +71,22 @@ services:
7071
ports:
7172
- "3003:4000"
7273

74+
matching-service:
75+
build:
76+
context: ./matching-service
77+
target: development
78+
container_name: matching-service
79+
volumes:
80+
- ./matching-service:/app
81+
- /app/node_modules
82+
command: npm run start:dev
83+
env_file:
84+
- ./matching-service/.env
85+
networks:
86+
- backend-network
87+
ports:
88+
- "3003:4000"
89+
7390
networks:
7491
backend-network:
7592
driver: bridge

backend/gateway-service/package-lock.json

Lines changed: 181 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/gateway-service/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
"@nestjs/microservices": "^10.4.1",
2626
"@nestjs/passport": "^10.0.3",
2727
"@nestjs/platform-express": "^10.0.0",
28+
"@nestjs/platform-socket.io": "^10.4.4",
2829
"@nestjs/swagger": "^7.4.2",
30+
"@nestjs/websockets": "^10.4.4",
2931
"class-transformer": "^0.5.1",
3032
"class-validator": "^0.14.1",
3133
"passport-jwt": "^4.0.1",

backend/gateway-service/src/app.module.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { AuthController } from './modules/auth/auth.controller';
55
import { QuestionController } from './modules/question/question.controller';
66
import { APP_GUARD } from '@nestjs/core';
77
import { AtAuthGuard, RtAuthGuard } from './common/guards';
8+
import { MatchController } from './modules/match/match.controller';
89

910
@Module({
1011
imports: [
@@ -33,9 +34,17 @@ import { AtAuthGuard, RtAuthGuard } from './common/guards';
3334
port: 3003,
3435
},
3536
},
37+
{
38+
name: 'MATCHING_SERVICE',
39+
transport: Transport.REDIS,
40+
options: {
41+
host: 'localhost',
42+
port: 6379,
43+
},
44+
}
3645
]),
3746
],
38-
controllers: [UserController, QuestionController, AuthController],
47+
controllers: [UserController, QuestionController, AuthController, MatchController],
3948
providers: [
4049
RtAuthGuard,
4150
{
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* import { createParamDecorator, ExecutionContext, UnauthorizedException } from '@nestjs/common';
2+
import { JwtService } from '@nestjs/jwt'; // Assuming you're using JwtService for token verification
3+
import { JwtPayload } from '../interfaces/auth'; // Your existing JWT payload interface
4+
5+
export const GetCurrentUserId = createParamDecorator(
6+
async (_: undefined, context: ExecutionContext): Promise<string> => {
7+
const client = context.switchToWs().getClient(); // Access WebSocket client
8+
const token = client.handshake?.auth?.token; // Extract JWT from the handshake auth
9+
10+
if (!token) {
11+
throw new UnauthorizedException('No token found in handshake');
12+
}
13+
14+
try {
15+
const jwtService = new JwtService({ secret: 'your-secret' }); // Use your JWT secret
16+
const decoded = jwtService.verify<JwtPayload>(token); // Verify the token
17+
18+
return decoded.sub; // Return the user ID (sub) from the JWT payload
19+
} catch (error) {
20+
throw new UnauthorizedException('Invalid or expired token');
21+
}
22+
},
23+
); */
24+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { UserMatchOptionsDto } from './user-match-options.dto';

0 commit comments

Comments
 (0)