Skip to content

Commit aef68b4

Browse files
authored
Merge pull request #56 from CS3219-AY2425S1/ms3-jared/user-service
Add user service endpoints
2 parents 2b905e3 + 4884d5c commit aef68b4

20 files changed

+209
-54
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Module } from '@nestjs/common';
22
import { ClientsModule, Transport } from '@nestjs/microservices';
33
import { UserController } from './modules/user/user.controller';
44
import { AuthController } from './modules/auth/auth.controller';
5-
import { UserService } from './modules/user/user.service';
65
import { QuestionController } from './modules/question/question.controller';
76
import { APP_GUARD } from '@nestjs/core';
87
import { AtAuthGuard, RtAuthGuard } from './common/guards';
@@ -38,7 +37,6 @@ import { AtAuthGuard, RtAuthGuard } from './common/guards';
3837
],
3938
controllers: [UserController, QuestionController, AuthController],
4039
providers: [
41-
UserService,
4240
RtAuthGuard,
4341
{
4442
provide: APP_GUARD,

backend/gateway-service/src/common/interceptors/response.interceptor.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,30 @@ export class ResponseInterceptor<T> implements NestInterceptor {
2929
data,
3030
})),
3131
catchError((error) => {
32-
// Handle errors and format the response
3332
const statusCode =
3433
error instanceof HttpException
3534
? error.getStatus()
3635
: HttpStatus.INTERNAL_SERVER_ERROR;
3736

38-
const message = error.message || 'Internal Server Error';
39-
37+
// Custom handling for BadRequestException
38+
let message = 'Internal Server Error';
39+
if (statusCode === HttpStatus.BAD_REQUEST) {
40+
if (Array.isArray(error.response?.message)) {
41+
message = error.response.message.join(', ');
42+
} else {
43+
message = error.response.message || 'Validation Error';
44+
}
45+
} else {
46+
message = error.message || 'Internal Server Error';
47+
}
4048
const response = {
4149
statusCode,
4250
message,
43-
error: error.response || error.stack || null,
4451
};
4552

4653
return throwError(() => response);
4754
}),
4855
);
4956
}
5057
}
58+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export enum AccountProvider {
2+
LOCAL = 'local',
3+
GOOGLE = 'google',
4+
GITHUB = 'github',
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export enum Languages {
2+
PYTHON = 'Python',
3+
JAVA = 'Java',
4+
CPLUSPLUS = 'C++',
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export {Proficiency} from './proficiency-level.enum';
2+
export {Languages} from './coding-languages.enum';
3+
export {AccountProvider} from './account-provider.enum';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export enum Proficiency {
2+
BEGINNER = 'Beginner',
3+
INTERMEDIATE = 'Intermediate',
4+
ADVANCED = 'Advanced',
5+
}

backend/gateway-service/src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { NestFactory } from '@nestjs/core';
1+
import { NestFactory, Reflector } from '@nestjs/core';
22
import { AppModule } from './app.module';
3-
import { ValidationPipe } from '@nestjs/common';
3+
import { ClassSerializerInterceptor, ValidationPipe } from '@nestjs/common';
44
import { ResponseInterceptor } from './common/interceptors/response.interceptor';
55
import { setupSwagger } from './common/configs/swagger.config';
66

@@ -23,7 +23,7 @@ async function bootstrap() {
2323
allowedHeaders: 'Content-Type, Accept',
2424
});
2525
app.useGlobalInterceptors(new ResponseInterceptor());
26-
26+
app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector)));
2727
setupSwagger(app);
2828

2929
await app.listen(4000);

backend/gateway-service/src/modules/question/question.controller.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { ClientProxy } from '@nestjs/microservices';
2020
import { Public } from 'src/common/decorators';
2121

2222
@ApiTags('questions')
23-
@Public()
2423
@Controller('questions')
2524
export class QuestionController {
2625
constructor(
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export { CreateUserDto } from './create-user.dto';
2+
export { UpdateUserDto } from './update-user.dto';
3+
export { UsersResponseDto } from './user-response.dto';
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { IsNotEmpty, IsString, IsEnum, IsBoolean, IsOptional } from 'class-validator';
3+
import { Languages, Proficiency } from 'src/constants';
4+
5+
export class UpdateUserDto {
6+
7+
@ApiProperty({
8+
example: 'testUsername',
9+
})
10+
@IsString()
11+
@IsOptional()
12+
username: string;
13+
14+
@ApiProperty({
15+
example: 'testDisplayname',
16+
})
17+
@IsString()
18+
@IsOptional()
19+
displayName: string;
20+
21+
@ApiProperty({
22+
example: Proficiency.BEGINNER,
23+
})
24+
@IsEnum(Proficiency)
25+
@IsOptional()
26+
proficiency: Proficiency;
27+
28+
@ApiProperty({
29+
example: [Languages.JAVA],
30+
})
31+
@IsEnum(Languages, { each: true })
32+
@IsOptional()
33+
languages: Languages[];
34+
35+
@ApiProperty({
36+
example: true,
37+
})
38+
@IsBoolean()
39+
@IsOptional()
40+
isOnboarded: boolean;
41+
}

0 commit comments

Comments
 (0)