Skip to content

Commit

Permalink
ruta user/:id
Browse files Browse the repository at this point in the history
  • Loading branch information
sibas1 committed Dec 17, 2024
1 parent b33b424 commit d515862
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
14 changes: 14 additions & 0 deletions server/apps/gateway/src/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import {
Controller,
Get,
Logger,
Param,
Put,
Request,
Response,
} from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { UsersService } from './users.service';
import { AuthorizationToken } from 'src/utils/authorization';
import { profile } from 'console';


@Controller('users')
Expand Down Expand Up @@ -37,4 +39,16 @@ export class UsersController {
.json({ message: 'Error al obtener el perfil del usuario' });
}
}
@Get(':id')
async profileAll(@Param('id') id: string) {
try {
const userProfile = await this.usersService.profile(id);
return userProfile;
} catch (error) {
Logger.error('Error in profile endpoint', error.message);
return error
.status(500)
.json({ message: 'Error al obtener el perfil del usuario' });
}
}
}
20 changes: 20 additions & 0 deletions server/apps/gateway/src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,24 @@ export class UsersService {
return { message: 'Error al conectarse al Microservicio Users' };
}
}
async profileAll(userId: string): Promise<any> {
try {
Logger.log('Peticion Profile')
const response = await this.httpService
.get(`${this.userServiceUrl}/users/profile/${userId}`)
.toPromise();
return response.data;

} catch (error) {
Logger.error('Error in profileAll service', error.message);

if (error.response) {
return {
status: error.response.status,
message: error.response.data,
};
}
return { message: 'Error al conectarse al Microservicio Users' };
}
}
}
17 changes: 17 additions & 0 deletions server/apps/users/src/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BadGatewayException, BadRequestException, Controller,
HttpCode,
HttpStatus,
Logger,
Param,
Req,
} from "@nestjs/common";
import { UsersService } from "./users.service";
Expand Down Expand Up @@ -33,6 +34,22 @@ export class UsersController {
}
}
}
@Get(':id')
async prifile(@Param('id') id: Request) {
Logger.log('Recibiendo peticion profile')
try{
const resp = await this.usersService.findUserById(id)
return resp as unknown as Promise<ProfileSuccess>;
}catch(error){
Logger.error(error)
return {
succes: false,
messager: 'Error en la autenticación'
}
}
}



// profile user
// @MessagePattern({ cmd: 'getProfile' })
Expand Down

0 comments on commit d515862

Please sign in to comment.