diff --git a/envoy.yaml b/envoy.yaml index cd42584..971ba6e 100644 --- a/envoy.yaml +++ b/envoy.yaml @@ -26,7 +26,7 @@ static_resources: allow_origin_string_match: - prefix: "*" allow_methods: GET, PUT, DELETE, POST, OPTIONS - allow_headers: keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,custom-header-1,access_token,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout + allow_headers: authorization, keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,custom-header-1,access_token,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout max_age: "1728000" expose_headers: custom-header-1,access_token,grpc-status,grpc-message http_filters: diff --git a/src/user/_utils/dto/response/user-language-response.dto.ts b/src/user/_utils/dto/response/user-language-response.dto.ts new file mode 100644 index 0000000..7db4c10 --- /dev/null +++ b/src/user/_utils/dto/response/user-language-response.dto.ts @@ -0,0 +1,8 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { IsString } from 'class-validator'; + +export class UserLanguageResponseDto { + @ApiProperty() + @IsString() + lan: string; +} diff --git a/src/user/_utils/user.proto b/src/user/_utils/user.proto index 9c7bb3d..6a4828d 100644 --- a/src/user/_utils/user.proto +++ b/src/user/_utils/user.proto @@ -54,6 +54,12 @@ message ChangeLanguageRequest { string language = 1; } +message UserLanguageResponse { + string lan = 1; +} + +message UserRequest {} + // The UserService defines the methods that our service exposes service User { rpc SignIn(SignInSignUpRequest) returns (UserResponse); @@ -66,4 +72,5 @@ service User { rpc GetUsers(EmptyRequest) returns (GetUsersResponse); rpc DeleteUser(EmailRequest) returns (EmptyResponse); rpc ChangeLanguage(ChangeLanguageRequest) returns (EmptyResponse); + rpc GetUserLanguage(UserRequest) returns (UserLanguageResponse); } diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts index 3d34755..c998aa7 100644 --- a/src/user/user.controller.ts +++ b/src/user/user.controller.ts @@ -14,6 +14,8 @@ import { GrpcAuthGuard } from './_utils/jwt/grpc-auth.guard'; import { MetadataWithUser } from './_utils/interface/metadata-with-user.interface'; import { GetUsersListDto } from './_utils/dto/response/get-users-list.dto'; import { ActivateResponseDto } from './_utils/dto/response/activate-response.dto'; +import { UserRequestDto } from './_utils/dto/request/user-request.dto'; +import { UserLanguageResponseDto } from './_utils/dto/response/user-language-response.dto'; @Controller('user') @ApiTags('User') @@ -72,4 +74,9 @@ export class UserController { changeLanguage(data: ChangeLanguageRequestDto, meta: MetadataWithUser): Promise { return this.userService.changeLanguage(data.language, meta.user); } + @UseGuards(GrpcAuthGuard) + @GrpcMethod('User', 'getUserLanguage') + getUserLanguage(data: UserRequestDto, meta: MetadataWithUser): Promise { + return this.userService.getUserLanguage(meta.user); + } } diff --git a/src/user/user.repository.ts b/src/user/user.repository.ts index d6ee2e2..f0f7014 100644 --- a/src/user/user.repository.ts +++ b/src/user/user.repository.ts @@ -92,9 +92,10 @@ export class UserRepository { .orFail(new RpcException({ code: status.NOT_FOUND, message: 'USER_NOT_FOUND' })) .exec(); - updateLanguageByUserId = (userId: Types.ObjectId, newLanguage: string): Promise => - this.model - .findByIdAndUpdate(userId, {lan: newLanguage}, {new: true}) - .orFail(new RpcException('USER_NOT_FOUND')) - .exec(); + updateLanguageByUserId = (userId: Types.ObjectId, newLanguage: string): Promise => { + return this.model + .findByIdAndUpdate(userId, { lan: newLanguage }, {new: true}) + .orFail(new RpcException('USER_NOT_FOUND')) + .exec(); + } } diff --git a/src/user/user.service.ts b/src/user/user.service.ts index ecde845..7011147 100644 --- a/src/user/user.service.ts +++ b/src/user/user.service.ts @@ -18,6 +18,7 @@ import { MailsService } from '../mails/mails.service'; import { EmailRequestDto } from './_utils/dto/request/email-request.dto'; import { ActivateUserRequestDto } from './_utils/dto/request/activate-request.dto'; import { ActivateResponseDto } from './_utils/dto/response/activate-response.dto'; +import { UserLanguageResponseDto } from './_utils/dto/response/user-language-response.dto'; import { Status } from '@grpc/grpc-js/build/src/constants'; @Injectable() @@ -146,4 +147,8 @@ export class UserService implements OnModuleInit { this.usersRepository .updateLanguageByUserId(user._id, newLanguage) .then(() => ({ message: 'langue modifié avec succès !' })); + + async getUserLanguage(user: UserDocument): Promise { + return { lan: user.lan }; + } }