diff --git a/src/presentation/middlewares/auth.middleware.ts b/src/presentation/middlewares/auth.middleware.ts index 4f193f6..e20eeaf 100644 --- a/src/presentation/middlewares/auth.middleware.ts +++ b/src/presentation/middlewares/auth.middleware.ts @@ -28,12 +28,12 @@ export class AuthMiddleware { // Check if refresh token and access token are present if (!refreshToken && !accessToken) - throw new UnauthenticatedError('Please first login'); + throw new UnauthenticatedError('Por favor loguea con tu cuenta'); if (accessToken) { // Validate access token const payload = this.jwt.validateToken(accessToken); - if (!payload) throw new UnauthorizedError('Invalid token validation'); + if (!payload) throw new UnauthorizedError('Token JWT inválido'); req.user = payload.user; const wsToken = this.jwt.generateToken({ user: payload.user }, '1d'); req.user.wsToken = wsToken; @@ -42,7 +42,7 @@ export class AuthMiddleware { // Validate refresh token const payload = this.jwt.validateToken(refreshToken); - if (!payload) throw new UnauthorizedError('Invalid token validation'); + if (!payload) throw new UnauthorizedError('Token JWT inválido'); const existingToken = await prisma.token.findUnique({ where: { userId: payload.user.id, refreshToken: payload.refreshToken }, @@ -50,7 +50,7 @@ export class AuthMiddleware { // Check if existing token is valid if (!existingToken || !existingToken?.isValid) - throw new UnauthenticatedError('Authentication Invalid'); + throw new UnauthenticatedError('No autentificado'); const { user } = payload; @@ -84,7 +84,9 @@ export class AuthMiddleware { if (role === 'admin') return next(); if (!roles.includes(role!)) - throw new UnauthorizedError('Unauthorized to access this resource'); + throw new UnauthorizedError( + 'No estás autorizado para acceder a este recurso' + ); next(); }; diff --git a/src/presentation/middlewares/error-handler.middleware.ts b/src/presentation/middlewares/error-handler.middleware.ts index 6a9c6c6..fce6423 100644 --- a/src/presentation/middlewares/error-handler.middleware.ts +++ b/src/presentation/middlewares/error-handler.middleware.ts @@ -33,7 +33,7 @@ export class ErrorHandlerMiddleware { // Handle jwt expired errors if (err?.name && err?.name === 'TokenExpiredError') { statusCode = 401; - message = 'JWT token expired'; + message = 'Sin autentificar'; } // Handle CustomAPIError diff --git a/src/presentation/middlewares/file-upload.middleware.ts b/src/presentation/middlewares/file-upload.middleware.ts index a618764..7aedb82 100644 --- a/src/presentation/middlewares/file-upload.middleware.ts +++ b/src/presentation/middlewares/file-upload.middleware.ts @@ -70,7 +70,7 @@ export class FileUploadMiddleware { include: { shelter: { select: { images: true } } }, }); - if (!user) throw new NotFoundError('User not found'); + if (!user) throw new NotFoundError('Usuario no encontrado'); name = user.username; id = user.id; @@ -89,7 +89,7 @@ export class FileUploadMiddleware { name: true, }, }); - if (!animal) throw new NotFoundError('Animal not found'); + if (!animal) throw new NotFoundError('Animal no encontrado'); name = animal.name; id = animal.createdBy; resourceId = animal.id; @@ -97,7 +97,7 @@ export class FileUploadMiddleware { default: throw new BadRequestError( - `Invalid resource: ${resource}, valid ones: users, animals` + `Recurso invalido: ${resource}, validos: users, animals` ); } diff --git a/src/presentation/middlewares/not-found.middleware.ts b/src/presentation/middlewares/not-found.middleware.ts index e156a20..8457dc3 100644 --- a/src/presentation/middlewares/not-found.middleware.ts +++ b/src/presentation/middlewares/not-found.middleware.ts @@ -9,6 +9,6 @@ export class NotFoundMiddleware { static init(req: Request, res: Response) { res .status(HttpCodes.NOT_FOUND) - .json({ message: `Route ${req.url} not found` }); + .json({ message: `Ruta ${req.url} no encontrada` }); } } diff --git a/src/presentation/users/service.ts b/src/presentation/users/service.ts index bec671c..36289e7 100644 --- a/src/presentation/users/service.ts +++ b/src/presentation/users/service.ts @@ -212,7 +212,9 @@ export class UserService { if (city) { filters.cityId = city.id; } else { - throw new NotFoundError(`City ${shelterFilterDto.city} not found`); + throw new NotFoundError( + `Ciudad ${shelterFilterDto.city} no encontrada` + ); } } @@ -309,7 +311,7 @@ export class UserService { }, }); - if (!user) throw new NotFoundError('User not found'); + if (!user) throw new NotFoundError('Usuario no encontrado'); const userEntity = UserEntity.fromObject(user); @@ -371,7 +373,7 @@ export class UserService { public async getSingleUser(term: string) { const user = await this.getUserFromTerm(term); - if (!user) throw new NotFoundError('User not found'); + if (!user) throw new NotFoundError('Usuario no encontrado'); const userEntity = UserEntity.fromObject(user); @@ -407,7 +409,7 @@ export class UserService { }), ]); - if (!userToDelete) throw new NotFoundError('User not found'); + if (!userToDelete) throw new NotFoundError('Usuario no encontrado'); CheckPermissions.check(user, userToDelete.id); @@ -465,14 +467,14 @@ export class UserService { ) { const user = await prisma.user.findUnique({ where: { id: userId } }); - if (!user) throw new NotFoundError('User not found'); + if (!user) throw new NotFoundError('Usuario no encontrado'); if (user) { const isValid = prisma.user.validatePassword({ password: oldPassword, hash: user.password, }); - if (!isValid) throw new BadRequestError('Invalid password'); + if (!isValid) throw new BadRequestError('Password no valido'); const hashPassword = prisma.user.hashPassword(newPassword); await prisma.user.update({ where: { id: userId }, @@ -495,7 +497,7 @@ export class UserService { where: { email: user.email }, }); - if (!userFound) throw new NotFoundError('User or shelter not found'); + if (!userFound) throw new NotFoundError('Usuaro o refugio no encontrados'); CheckPermissions.check(user, userFound.id); @@ -539,7 +541,7 @@ export class UserService { where: { email: user.email }, }); - if (!userToUpdate) throw new NotFoundError('User not found'); + if (!userToUpdate) throw new NotFoundError('Usuario no encontrado'); CheckPermissions.check(user, userToUpdate.id); @@ -624,7 +626,7 @@ export class UserService { }, }); - if (!userToUpdate) throw new NotFoundError('User not found'); + if (!userToUpdate) throw new NotFoundError('Usuario no encontrado'); let updateQuery: { avatar?: string[]; @@ -633,7 +635,7 @@ export class UserService { if (userToUpdate.role === 'shelter') { if (!userToUpdate.shelter) - throw new NotFoundError('Shelter not found for user'); + throw new NotFoundError('El usuario no es un refugio'); const images = userToUpdate.shelter.images; const resultImages = await this.buildImages(images, deleteImages, files); @@ -852,9 +854,9 @@ export class UserService { }, }); - if (!notification) throw new NotFoundError('Notification not found'); + if (!notification) throw new NotFoundError('Notificacion no encontrada'); if (notification.isRead) - throw new BadRequestError('Notification is already read'); + throw new BadRequestError('La notificacion ya ha sido leida'); CheckPermissions.check(user, notification.userId); @@ -878,7 +880,7 @@ export class UserService { }, }); - if (!notification) throw new NotFoundError('Notification not found'); + if (!notification) throw new NotFoundError('Notificacion no encontrada'); CheckPermissions.check(user, notification.userId);