diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..e69de29 diff --git a/package-lock.json b/package-lock.json index 473cde9..b87ea38 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,8 @@ "process": "^0.11.10", "sequelize": "^6.32.1", "sqlite3": "^5.1.7", - "yup": "^1.2.0" + "yup": "^1.2.0", + "zod": "^3.23.8" }, "devDependencies": { "jest": "^29.6.2", @@ -6996,6 +6997,15 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/zod": { + "version": "3.23.8", + "resolved": "https://npm.artifacts.furycloud.io/repository/all/zod/-/zod-3.23.8.tgz", + "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } } } } diff --git a/package.json b/package.json index aa6a1eb..31df441 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { - "name": "api-e-banco-de-dados", + "name": "social-network", "version": "1.0.0", - "description": "", + "description": "Fake social network project using nodejs", "main": "users.js", "scripts": { "test": "jest --detectOpenHandles", - "dev": "nodemon server.js", + "dev": "nodemon test.js", "db:drop": "knex migrate:down", "db:migrate": "knex migrate:latest", "db:seed": "knex seed:run", @@ -33,7 +33,8 @@ "process": "^0.11.10", "sequelize": "^6.32.1", "sqlite3": "^5.1.7", - "yup": "^1.2.0" + "yup": "^1.2.0", + "zod": "^3.23.8" }, "devDependencies": { "jest": "^29.6.2", diff --git a/src/controller/albumController.js b/src/controller/albumController.js index f137c6d..df8df76 100644 --- a/src/controller/albumController.js +++ b/src/controller/albumController.js @@ -6,41 +6,41 @@ class AlbumController { this.tokenService = tokenService; } async createAlbum(req, res) { - const { description, target_id } = req.body; - const album = await this.albumService.createAlbum(description, target_id); + const { description, target_id: targetId } = req.body; + const album = await this.albumService.createAlbum(description, targetId); return res.status(httpStatus.CREATED).json({ message: 'Album created successfully!', data: album }); } async getAlbumById(req, res) { - const { id } = req.params; + const { id: albumId } = req.params; const { authorization: token } = req.headers; await this.tokenService.verifyToken(token); - const album = await this.albumService.getAlbumById(id); + const album = await this.albumService.getAlbumById(albumId); return res.status(httpStatus.OK).json(album); } async getAlbums(req, res) { const { authorization: token } = req.headers; - const albumId = await this.tokenService.getIdFromToken(token); - const album = await this.albumService.getAllAlbums(albumId); + const userId = await this.tokenService.getIdFromToken(token); + const album = await this.albumService.getAllAlbums(userId); return res.status(httpStatus.OK).json(album); } async updateAlbum(req, res) { - const { id } = req.params; + const { id: albumId } = req.params; const { authorization: token } = req.headers; await this.tokenService.verifyToken(token); - const { description, target_id } = req.body; - await this.albumService.updateAlbum(id, description, target_id); + const { description, target_id: targetId } = req.body; + await this.albumService.updateAlbum(albumId, description, targetId); return res.status(httpStatus.OK).json({ details: "Album updated successfully" }); } async deleteAlbum(req, res) { - const { id } = req.params; + const { id: albumId } = req.params; const { authorization: token } = req.headers; await this.tokenService.verifyToken(token); - await this.albumService.deleteAlbum(id); + await this.albumService.deleteAlbum(albumId); return res.status(httpStatus.OK).json({ details: "Album deleted successfully" }); diff --git a/src/controller/albumItemController.js b/src/controller/albumItemController.js index 7fc3898..43a4c6a 100644 --- a/src/controller/albumItemController.js +++ b/src/controller/albumItemController.js @@ -8,8 +8,8 @@ class AlbumItemController { async createAlbumItem(req, res) { const { authorization: token } = req.headers; await this.tokenService.verifyToken(token); - const { post_id, album_id } = req.body; - const albumItem = await this.albumItemService.createAlbumItem(post_id, album_id); + const { post_id: postId, album_id: albumItemId } = req.body; + const albumItem = await this.albumItemService.createAlbumItem(postId, albumItemId); return res.status(httpStatus.CREATED).json({ message: 'Album item created successfully!', data: albumItem @@ -17,18 +17,19 @@ class AlbumItemController { } async getAlbumItems(req, res) { const { authorization: token } = req.headers; - const albumID = await this.tokenService.getIdFromToken(token); - const albumItem = await this.albumItemService.getAllAlbumItem(albumID); + const albumItemId = await this.tokenService.getIdFromToken(token); + const albumItem = await this.albumItemService.getAllAlbumItem(albumItemId); return res.status(httpStatus.OK).json(albumItem); } async deleteAlbumItem(req, res) { - const { id } = req.params; + const { id: albumItemId } = req.params; const { authorization: token } = req.headers; await this.tokenService.verifyToken(token); - await this.albumItemService.deleteAlbumItem(id); + await this.albumItemService.deleteAlbumItem(albumItemId); return res.status(httpStatus.OK).json({ details: "Album item deleted successfully" }); } } + module.exports = AlbumItemController; diff --git a/src/controller/commentController.js b/src/controller/commentController.js index ba9f4a6..f52f0fd 100644 --- a/src/controller/commentController.js +++ b/src/controller/commentController.js @@ -7,46 +7,46 @@ class CommentController { } async create(req, res) { const { authorization: token } = req.headers; - await this.tokenService.verifyToken(token); - const { description, user_id, post_id } = req.body; - const comment = await this.commentService.create(description, user_id, post_id); + const userId = await this.tokenService.getIdFromToken(token); + const { description, post_id: postId } = req.body; + const comment = await this.commentService.create(description, userId, postId); return res.status(httpStatus.CREATED).json({ message: 'Comment created successfully!', data: comment }); } async getCommentById(req, res) { - const { id } = req.params; + const { id: commentId } = req.params; const { authorization: token } = req.headers; await this.tokenService.verifyToken(token); - const comment = await this.commentService.getCommentById(id); + const comment = await this.commentService.getCommentById(commentId); return res.status(httpStatus.OK).json(comment); } async getCommentsByPostId(req, res) { const { authorization: token } = req.headers; - const commentId = await this.tokenService.getIdFromToken(token); - const comments = await this.commentService.getAllComments(commentId); + const userId = await this.tokenService.getIdFromToken(token); + const comments = await this.commentService.getAllComments(userId); return res.status(httpStatus.OK).json(comments); - } + }; async updateComment(req, res) { const { authorization: token } = req.headers; await this.tokenService.verifyToken(token); - const { id } = req.params; - const { description, user_id, post_id } = req.body; - await this.commentService.updateComment(id, description, user_id, post_id); + const { id: commentId } = req.params; + const { description} = req.body; + await this.commentService.updateComment(commentId, description); return res.status(httpStatus.OK).json({ details: "Comment updated successfully" }); - } + }; async deleteComment(req, res) { const { authorization: token } = req.headers; await this.tokenService.verifyToken(token); - const { id } = req.params; - await this.commentService.deleteComment(id); + const { id: commentId } = req.params; + await this.commentService.deleteComment(commentId); return res.status(httpStatus.OK).json({ details: "Comment deleted successfully" }); - } + }; } module.exports = CommentController; diff --git a/src/controller/friendshipRequestController.js b/src/controller/friendshipRequestController.js index fab2bf3..6c005bf 100644 --- a/src/controller/friendshipRequestController.js +++ b/src/controller/friendshipRequestController.js @@ -5,7 +5,7 @@ class FriendshipRequestController { this.friendshipRequestService = friendshipRequestService; this.tokenService = tokenService; this.friendshipService = friendshipService; - } + }; async sendFriendshipRequest(req, res) { const { authorization: token } = req.headers; const senderID = await this.tokenService.getIdFromToken(token); diff --git a/src/controller/friendshipRequestTypeController.js b/src/controller/friendshipRequestTypeController.js index 0c323c8..0d83664 100644 --- a/src/controller/friendshipRequestTypeController.js +++ b/src/controller/friendshipRequestTypeController.js @@ -3,7 +3,7 @@ const httpStatus = require('../utils/statusCodes'); class FriendshipRequestTypeController { constructor(friendshipRequestTypeService) { this.friendshipRequestTypeService = friendshipRequestTypeService; - } + }; async create(req, res) { const { type } = req.body; const friendshipRequestType = await this.friendshipRequestTypeService.create(type); diff --git a/src/controller/postController.js b/src/controller/postController.js index 08c241d..9fbb2d2 100644 --- a/src/controller/postController.js +++ b/src/controller/postController.js @@ -8,8 +8,8 @@ class PostController { async createPost(req, res) { const { authorization: token } = req.headers; const userId = await this.tokenService.getIdFromToken(token); - const { description, target_id, type_id } = req.body; - const post = await this.postService.createPost(description, userId, target_id, type_id); + const { description, target_id: targetId, type_id: typeId } = req.body; + const post = await this.postService.createPost(description, userId, targetId, typeId); return res.status(httpStatus.CREATED).json({ message: 'Post created successfully!', data: post diff --git a/src/controller/reactionController.js b/src/controller/reactionController.js index a9d3d8b..a764a5a 100644 --- a/src/controller/reactionController.js +++ b/src/controller/reactionController.js @@ -8,8 +8,8 @@ class ReactionController { async createReaction(req, res) { const { authorization: token } = req.headers; const userId = await this.tokenService.getIdFromToken(token); - const { reaction_type_id, post_id } = req.body; - const reaction = await this.reactionService.createReaction(userId, reaction_type_id, post_id); + const { reaction_type_id: reactionTypeId, post_id: postId } = req.body; + const reaction = await this.reactionService.createReaction(userId, reactionTypeId, postId); return res.status(httpStatus.CREATED).json({ message: 'Reaction created successfully!', data: reaction @@ -32,8 +32,8 @@ class ReactionController { const { authorization: token } = req.headers; await this.tokenService.verifyToken(token); const { id } = req.params; - const { user_id, reaction_type_id, post_id } = req.body; - await this.reactionService.updateReaction(id, user_id, reaction_type_id, post_id); + const { user_id: userId, reaction_type_id: reactionTypeId, post_id: postId } = req.body; + await this.reactionService.updateReaction(id, userId, reactionTypeId, postId); return res.status(httpStatus.OK).json({ details: "Reaction updated successfully" }); diff --git a/src/controller/targetPublicController.js b/src/controller/targetPublicController.js index bf785a5..321443e 100644 --- a/src/controller/targetPublicController.js +++ b/src/controller/targetPublicController.js @@ -13,7 +13,7 @@ class TargetPublicController { data: targetPublic }); } - async getTargetPublics(req, res) { + async getTargetPublic(req, res) { const targetPublic = await this.targetPublicService.getAllTargetPublic(); return res.status(httpStatus.OK).json(targetPublic); } diff --git a/src/controller/userController.js b/src/controller/userController.js index 2d54952..6af3421 100644 --- a/src/controller/userController.js +++ b/src/controller/userController.js @@ -6,10 +6,10 @@ class UserController { this.userService = userService; this.authenticateService = authenticateService; this.tokenService = tokenService; - } + }; async create(req, res) { - const { full_name, email, password } = req.body; - const user = await this.userService.create(full_name, email, password); + const { full_name: fullName, email, password } = req.body; + const user = await this.userService.create(fullName, email, password); return res.status(httpStatus.CREATED).json({ message: 'User created successfully!', data: user @@ -35,10 +35,10 @@ class UserController { }); }; async getUserById(req, res) { - const { id } = req.params; + const { id: userId } = req.params; const { authorization: token } = req.headers; await this.tokenService.verifyToken(token); - const user = await this.userService.getUserById(id); + const user = await this.userService.getUserById(userId); return res.status(httpStatus.OK).json(user); }; async getUsers(req, res) { @@ -48,8 +48,8 @@ class UserController { async updateUser(req, res) { const { authorization: token } = req.headers; const userId = await this.tokenService.getIdFromToken(token); - const { full_name, email, password } = req.body; - await this.userService.updateUserById(userId, full_name, email, password); + const { full_name: fullName, email, password } = req.body; + await this.userService.updateUserById(userId, fullName, email, password); return res.status(httpStatus.OK).json({ details: "User updated successfully" }); diff --git a/src/features/albumContainer.js b/src/features/albumContainer.js index a24c7d9..f07a913 100644 --- a/src/features/albumContainer.js +++ b/src/features/albumContainer.js @@ -11,9 +11,9 @@ const { ITokenRepository } = require("../repositories/interfaces/tokenRepository function configureAlbumContainer() { const albumRepositoryImplementation = new AlbumRepositoryImplementation(); - const tokenRepositoryImplementation = new TokenRepositoryImplementation(); - const tokenRepository = new TokenRepository(tokenRepositoryImplementation, contract=ITokenRepository); - const albumRepository = new AlbumRepository(albumRepositoryImplementation, contract=IAlbumRepository); + const tokenRepositoryImplementation = new TokenRepositoryImplementation(); + const tokenRepository = new TokenRepository(tokenRepositoryImplementation, ITokenRepository); + const albumRepository = new AlbumRepository(albumRepositoryImplementation, IAlbumRepository); const tokenService = new TokenService(tokenRepository); const albumService = new AlbumService(albumRepository); const albumController = new AlbumController(albumService, tokenService); diff --git a/src/features/albumItemContainer.js b/src/features/albumItemContainer.js index 010de9b..bba9bc1 100644 --- a/src/features/albumItemContainer.js +++ b/src/features/albumItemContainer.js @@ -12,8 +12,8 @@ const { ITokenRepository } = require("../repositories/interfaces/tokenRepository function configureAlbumItemContainer() { const albumItemRepositoryImplementation = new AlbumItemRepositoryImplementation(); const tokenRepositoryImplementation = new TokenRepositoryImplementation(); - const tokenRepository = new TokenRepository(tokenRepositoryImplementation, contract=ITokenRepository); - const albumItemRepository = new AlbumItemRepository(albumItemRepositoryImplementation, contract=IAlbumItemRepository); + const tokenRepository = new TokenRepository(tokenRepositoryImplementation, ITokenRepository); + const albumItemRepository = new AlbumItemRepository(albumItemRepositoryImplementation, IAlbumItemRepository); const tokenService = new TokenService(tokenRepository); const albumItemService = new AlbumItemService(albumItemRepository); const albumItemController = new AlbumItemController(albumItemService, tokenService); diff --git a/src/features/commentContainer.js b/src/features/commentContainer.js index e443940..646ae1b 100644 --- a/src/features/commentContainer.js +++ b/src/features/commentContainer.js @@ -12,8 +12,8 @@ const { ITokenRepository } = require("../repositories/interfaces/tokenRepository function configureCommentContainer() { const commentRepositoryImplementation = new CommentRepositoryImplementation(); const tokenRepositoryImplementation = new TokenRepositoryImplementation(); - const commentRepository = new CommentRepository(commentRepositoryImplementation, contract=ICommentRepository); - const tokenRepository = new TokenRepository(tokenRepositoryImplementation, contract=ITokenRepository); + const commentRepository = new CommentRepository(commentRepositoryImplementation, ICommentRepository); + const tokenRepository = new TokenRepository(tokenRepositoryImplementation, ITokenRepository); const tokenService = new TokenService(tokenRepository); const commentService = new CommentService(commentRepository); const commentController = new CommentController(commentService, tokenService); diff --git a/src/features/fileTypeContainer.js b/src/features/fileTypeContainer.js index d830427..4503ce6 100644 --- a/src/features/fileTypeContainer.js +++ b/src/features/fileTypeContainer.js @@ -8,7 +8,7 @@ const { IFileTypeRepository } = require("../repositories/interfaces/fileTypeRepo function configureFileTypeContainer() { const fileTypeRepositoryImplementation = new FileTypeRepositoryImplementation(); - const fileTypeRepository = new FileTypeRepository(fileTypeRepositoryImplementation, contract=IFileTypeRepository); + const fileTypeRepository = new FileTypeRepository(fileTypeRepositoryImplementation, IFileTypeRepository); const fileTypeService = new FileTypeService(fileTypeRepository); const fileTypeController = new FileTypeController(fileTypeService); const fileTypeRoutes = createFileTypeRoutes(fileTypeController); diff --git a/src/features/friendshipContainer.js b/src/features/friendshipContainer.js index 3235a53..b78aff2 100644 --- a/src/features/friendshipContainer.js +++ b/src/features/friendshipContainer.js @@ -12,8 +12,8 @@ const { ITokenRepository } = require("../repositories/interfaces/tokenRepository function configureFriendshipContainer() { const friendshipRepositoryImplementation = new FriendshipRepositoryImplementation(); const tokenRepositoryImplementation = new TokenRepositoryImplementation(); - const friendshipRepository = new FriendshipRepository(friendshipRepositoryImplementation, contract=IFriendshipRepository); - const tokenRepository = new TokenRepository(tokenRepositoryImplementation, contract=ITokenRepository); + const friendshipRepository = new FriendshipRepository(friendshipRepositoryImplementation, IFriendshipRepository); + const tokenRepository = new TokenRepository(tokenRepositoryImplementation, ITokenRepository); const tokenService = new TokenService(tokenRepository); const friendshipService = new FriendshipService(friendshipRepository); const friendshipController = new FriendshipController(friendshipService, tokenService); diff --git a/src/features/friendshipRequestContainer.js b/src/features/friendshipRequestContainer.js index 691ac68..6bd4608 100644 --- a/src/features/friendshipRequestContainer.js +++ b/src/features/friendshipRequestContainer.js @@ -18,9 +18,9 @@ function configureFriendshipRequestContainer() { const tokenRepositoryImplementation = new TokenRepositoryImplementation(); const friendshipRequestRepositoryImplementation = new FriendshipRequestRepositoryImplementation(); const friendshipRepositoryImplementation = new FriendshipRepositoryImplementation(); - const friendshipRequestRepository = new FriendshipRequestRepository(friendshipRequestRepositoryImplementation, contract=IFriendshipRequestRepository); - const tokenRepository = new TokenRepository(tokenRepositoryImplementation, contract=ITokenRepository); - const friendshipRepository = new FriendshipRepository(friendshipRepositoryImplementation, contract=IFriendshipRepository); + const friendshipRequestRepository = new FriendshipRequestRepository(friendshipRequestRepositoryImplementation, IFriendshipRequestRepository); + const tokenRepository = new TokenRepository(tokenRepositoryImplementation, ITokenRepository); + const friendshipRepository = new FriendshipRepository(friendshipRepositoryImplementation, IFriendshipRepository); const hashService = new HashService(); const tokenService = new TokenService(tokenRepository, hashService); const friendshipService = new FriendshipService(friendshipRepository); diff --git a/src/features/friendshipRequestTypeContainer.js b/src/features/friendshipRequestTypeContainer.js index 5ec4191..8196829 100644 --- a/src/features/friendshipRequestTypeContainer.js +++ b/src/features/friendshipRequestTypeContainer.js @@ -7,7 +7,7 @@ const { IFriendshipRequestTypeRepository } = require("../repositories/interfaces function configureFriendshipRequestTypeContainer() { const friendshipRequestTypeRepositoryImplementation = new FriendshipRequestTypeRepositoryImplementation(); - const friendshipRequestTypeRepository = new FriendshipRequestTypeRepository(friendshipRequestTypeRepositoryImplementation, contract=IFriendshipRequestTypeRepository); + const friendshipRequestTypeRepository = new FriendshipRequestTypeRepository(friendshipRequestTypeRepositoryImplementation, IFriendshipRequestTypeRepository); const friendshipRequestTypeService = new FriendshipRequestTypeService(friendshipRequestTypeRepository); const friendshipRequestTypeController = new FriendshipRequestTypeController(friendshipRequestTypeService); const friendshipRequestTypeRoutes = createFriendshipRequestTypeRoutes(friendshipRequestTypeController); diff --git a/src/features/postContainer.js b/src/features/postContainer.js index 7d6e88c..af11a94 100644 --- a/src/features/postContainer.js +++ b/src/features/postContainer.js @@ -12,8 +12,8 @@ const { ITokenRepository } = require("../repositories/interfaces/tokenRepository function configurePostContainer() { const postRepositoryImplementation = new PostRepositoryImplementation(); const tokenRepositoryImplementation = new TokenRepositoryImplementation(); - const postRepository = new PostRepository(postRepositoryImplementation, contract=IPostRepository); - const tokenRepository = new TokenRepository(tokenRepositoryImplementation, contract=ITokenRepository); + const postRepository = new PostRepository(postRepositoryImplementation, IPostRepository); + const tokenRepository = new TokenRepository(tokenRepositoryImplementation, ITokenRepository); const postService = new PostService(postRepository); const tokenService = new TokenService(tokenRepository); const postController = new PostController(postService, tokenService); diff --git a/src/features/reactionContainer.js b/src/features/reactionContainer.js index 7659131..2049621 100644 --- a/src/features/reactionContainer.js +++ b/src/features/reactionContainer.js @@ -12,8 +12,8 @@ const { ITokenRepository } = require("../repositories/interfaces/tokenRepository function configureReactionContainer() { const reactionRepositoryImplementation = new ReactionRepositoryImplementation(); const tokenRepositoryImplementation = new TokenRepositoryImplementation(); - const reactionRepository = new ReactionRepository(reactionRepositoryImplementation, contract=IReactionRepository); - const tokenRepository = new TokenRepository(tokenRepositoryImplementation, contract=ITokenRepository); + const reactionRepository = new ReactionRepository(reactionRepositoryImplementation, IReactionRepository); + const tokenRepository = new TokenRepository(tokenRepositoryImplementation, ITokenRepository); const tokenService = new TokenService(tokenRepository); const reactionService = new ReactionService(reactionRepository); const reactionController = new ReactionController(reactionService, tokenService); diff --git a/src/features/reactionTypeContainer.js b/src/features/reactionTypeContainer.js index ad020d9..4a6a296 100644 --- a/src/features/reactionTypeContainer.js +++ b/src/features/reactionTypeContainer.js @@ -12,8 +12,8 @@ const { ITokenRepository } = require("../repositories/interfaces/tokenRepository function configureReactionTypeContainer() { const reactionTypeRepositoryImplementation = new ReactionTypeRepositoryImplementation(); const tokenRepositoryImplementation = new TokenRepositoryImplementation(); - const reactionTypeRepository = new ReactionTypeRepository(reactionTypeRepositoryImplementation, contract=IReactionTypeRepository); - const tokenRepository = new TokenRepository(tokenRepositoryImplementation, contract=ITokenRepository); + const reactionTypeRepository = new ReactionTypeRepository(reactionTypeRepositoryImplementation, IReactionTypeRepository); + const tokenRepository = new TokenRepository(tokenRepositoryImplementation, ITokenRepository); const tokenService = new TokenService(tokenRepository); const reactionTypeService = new ReactionTypeService(reactionTypeRepository); const reactionTypeController = new ReactionTypeController(reactionTypeService, tokenService); diff --git a/src/features/targetPublicContainer.js b/src/features/targetPublicContainer.js index 2626382..97f29a9 100644 --- a/src/features/targetPublicContainer.js +++ b/src/features/targetPublicContainer.js @@ -12,8 +12,8 @@ const { ITokenRepository } = require("../repositories/interfaces/tokenRepository function configureTargetPublicContainer(){ const targetPublicRepositoryImplementation = new TargetPublicRepositoryImplementation(); const tokenRepositoryImplementation = new TokenRepositoryImplementation(); - const tokenRepository = new TokenRepository(tokenRepositoryImplementation, contract=ITokenRepository); - const targetPublicRepository = new TargetPublicRepository(targetPublicRepositoryImplementation, contract=ITargetPublicRepository); + const tokenRepository = new TokenRepository(tokenRepositoryImplementation, ITokenRepository); + const targetPublicRepository = new TargetPublicRepository(targetPublicRepositoryImplementation, ITargetPublicRepository); const tokenService = new TokenService(tokenRepository); const targetPublicService = new TargetPublicService(targetPublicRepository); const targetPublicController = new TargetPublicController(targetPublicService, tokenService); diff --git a/src/features/userContainer.js b/src/features/userContainer.js index 459f8f7..e00b1c5 100644 --- a/src/features/userContainer.js +++ b/src/features/userContainer.js @@ -14,10 +14,10 @@ const { ITokenRepository } = require("../repositories/interfaces/tokenRepository function configureUserContainer(){ const tokenRepositoryImplementation = new TokenRepositoryImplementation(); const userRepositoryImplementation = new UserRepositoryImplementation(); - const tokenRepository = new TokenRepository(tokenRepositoryImplementation, contract=ITokenRepository); + const tokenRepository = new TokenRepository(tokenRepositoryImplementation, ITokenRepository); const hashService = new HashService(); const tokenService = new TokenService(tokenRepository, hashService); - const userRepository = new UserRepository(userRepositoryImplementation, contract=IUserRepository); + const userRepository = new UserRepository(userRepositoryImplementation, IUserRepository); const authenticateService = new AuthenticateService(userRepository, hashService); const userService = new UserService(userRepository, hashService); const userController = new UserController(userService, authenticateService, tokenService); diff --git a/src/middlewares/albumItemValidation.js b/src/middlewares/albumItemValidation.js index 9991f7d..f33cd88 100644 --- a/src/middlewares/albumItemValidation.js +++ b/src/middlewares/albumItemValidation.js @@ -2,14 +2,14 @@ const ApiError = require("../utils/ApiError"); const httpStatus = require("../utils/statusCodes"); const validateSchema = (schema) => async (req, res, next) => { try { - const { post_id, album_id } = req.body; + const { post_id: postId, album_id: albumId } = req.body; const { authorization } = req.headers; const { id } = req.params; await schema.validate({ - id, - authorization, - post_id, - album_id + id: id, + authorization: authorization, + post_id: postId, + album_id: albumId }) next(); } catch (error) { diff --git a/src/middlewares/albumValidation.js b/src/middlewares/albumValidation.js index 947066d..cfe782c 100644 --- a/src/middlewares/albumValidation.js +++ b/src/middlewares/albumValidation.js @@ -2,14 +2,14 @@ const ApiError = require("../utils/ApiError"); const httpStatus = require("../utils/statusCodes"); const validateSchema = (schema) => async (req, res, next) => { try { - const { description, target_id } = req.body; + const { description, target_id: targetId } = req.body; const { authorization } = req.headers; - const { id } = req.params; + const { id: albumId } = req.params; await schema.validate({ - id, - authorization, - description, - target_id + album_id: albumId, + authorization: authorization, + description: description, + target_id: targetId }) next(); } catch (error) { diff --git a/src/middlewares/commentsValidation.js b/src/middlewares/commentsValidation.js index ce67a17..24549a0 100644 --- a/src/middlewares/commentsValidation.js +++ b/src/middlewares/commentsValidation.js @@ -2,15 +2,15 @@ const ApiError = require("../utils/ApiError"); const httpStatus = require("../utils/statusCodes"); const validateSchema = (schema) => async (req, res, next) => { try { - const { description, user_id, post_id } = req.body; - const { id } = req.params; + const { description, user_id: userId, post_id: postId } = req.body; + const { id: commentId } = req.params; const { authorization } = req.headers; await schema.validate({ - id, - authorization, - description, - user_id, - post_id + id: commentId, + authorization: authorization, + description: description, + user_id: userId, + post_id: postId }) next(); } catch (error) { diff --git a/src/middlewares/error.js b/src/middlewares/error.js index 5573b3f..8fde7c4 100644 --- a/src/middlewares/error.js +++ b/src/middlewares/error.js @@ -1,4 +1,5 @@ const errorHandler = (err, req, res, next) => { + console.error(`Some error occurred: ${err}`); return res.status(err.statusCode).json({ message: err.message }); diff --git a/src/middlewares/fileTypeValidation.js b/src/middlewares/fileTypeValidation.js index 39f89b6..b316cc0 100644 --- a/src/middlewares/fileTypeValidation.js +++ b/src/middlewares/fileTypeValidation.js @@ -1,5 +1,6 @@ const ApiError = require("../utils/ApiError"); const httpStatus = require("../utils/statusCodes"); + const validateSchema = (schema) => async (req, res, next) => { try { const { type } = req.body; diff --git a/src/middlewares/friendshipRequestTypeValidation.js b/src/middlewares/friendshipRequestTypeValidation.js index a98c0bf..b316cc0 100644 --- a/src/middlewares/friendshipRequestTypeValidation.js +++ b/src/middlewares/friendshipRequestTypeValidation.js @@ -15,4 +15,4 @@ const validateSchema = (schema) => async (req, res, next) => { } } -module.exports = validateSchema; \ No newline at end of file +module.exports = validateSchema; diff --git a/src/middlewares/friendshipRequestValidation.js b/src/middlewares/friendshipRequestValidation.js index ce09963..06e9f3c 100644 --- a/src/middlewares/friendshipRequestValidation.js +++ b/src/middlewares/friendshipRequestValidation.js @@ -3,14 +3,14 @@ const httpStatus = require("../utils/statusCodes"); const validateSchema = (schema) => async (req, res, next) => { try { - const { sender_id, receiver_id } = req.body; + const { sender_id: senderId, receiver_id: receiverId } = req.body; const { id } = req.params; const { authorization } = req.headers; await schema.validate({ authorization, id, - sender_id, - receiver_id + sender_id: senderId, + receiver_id: receiverId }) next(); } catch (error) { diff --git a/src/middlewares/postValidation.js b/src/middlewares/postValidation.js index 48bb9c4..d135ea0 100644 --- a/src/middlewares/postValidation.js +++ b/src/middlewares/postValidation.js @@ -2,15 +2,15 @@ const ApiError = require("../utils/ApiError"); const httpStatus = require("../utils/statusCodes"); const validateSchema = (schema) => async (req, res, next) => { try { - const { description, target_id, type_id } = req.body; + const { description, target_id: targetId, type_id: typeId } = req.body; const { id } = req.params; const { authorization } = req.headers; await schema.validate({ - id, - authorization, - description, - target_id, - type_id + id: id, + authorization: authorization, + description: description, + target_id: targetId, + type_id: typeId }) next(); } catch (error) { diff --git a/src/middlewares/reactionValidation.js b/src/middlewares/reactionValidation.js index 5f2f18b..c02a3b6 100644 --- a/src/middlewares/reactionValidation.js +++ b/src/middlewares/reactionValidation.js @@ -2,14 +2,14 @@ const ApiError = require("../utils/ApiError"); const httpStatus = require("../utils/statusCodes"); const validateSchema = (schema) => async (req, res, next) => { try { - const { reaction_type_id, post_id } = req.body; + const { reaction_type_id: reactionTypeId, post_id: postId } = req.body; const { authorization } = req.headers; const { id } = req.params; await schema.validate({ - id, - authorization, - reaction_type_id, - post_id + id: id, + authorization: authorization, + reaction_type_id: reactionTypeId, + post_id: postId }) next(); } catch (error) { diff --git a/src/middlewares/userValidation.js b/src/middlewares/userValidation.js index 46705f3..17d5142 100644 --- a/src/middlewares/userValidation.js +++ b/src/middlewares/userValidation.js @@ -2,13 +2,13 @@ const ApiError = require("../utils/ApiError"); const httpStatus = require("../utils/statusCodes"); const validateSchema = (schema) => async (req, res, next) => { try { - const { full_name, email, password } = req.body; + const { full_name: fullName, email, password } = req.body; const { id } = req.params; const { authorization } = req.headers; await schema.validate({ authorization, id, - full_name, + fullName, email, password }) diff --git a/src/repositories/albumItemRepository.js b/src/repositories/albumItemRepository.js index 751764a..354efbe 100644 --- a/src/repositories/albumItemRepository.js +++ b/src/repositories/albumItemRepository.js @@ -4,18 +4,18 @@ class AlbumItemRepository { constructor(repository, contract) { assertIsInstanceOfContract(repository, contract); this.repository = repository; - } - async create(post_id, album_id) { - return this.repository.create(post_id, album_id); }; - async getById(id){ - return this.repository.getById(id); + create(postId, albumItemId) { + return this.repository.create(postId, albumItemId); }; - async getAll(AlbumId){ - return this.repository.getAll(AlbumId); + getById(albumItemId){ + return this.repository.getById(albumItemId); }; - async delete (id) { - this.repository.delete(id); + getAll(albumItemId){ + return this.repository.getAll(albumItemId); + }; + delete (albumItemId) { + this.repository.delete(albumItemId); }; } diff --git a/src/repositories/albumRepository.js b/src/repositories/albumRepository.js index 4032076..a896778 100644 --- a/src/repositories/albumRepository.js +++ b/src/repositories/albumRepository.js @@ -4,21 +4,21 @@ class AlbumRepository { constructor(repository, contract) { assertIsInstanceOfContract(repository, contract); this.repository = repository; - } - async create(description, target_id) { - return this.repository.create(description, target_id); }; - async getById(id){ - return this.repository.getById(id); + create(description, targetId) { + return this.repository.create(description, targetId); }; - async getAll(albumId){ + getById(albumId){ + return this.repository.getById(albumId); + }; + getAll(albumId){ return this.repository.getAll(albumId); }; - async update(id, description, target_id) { - this.repository.update(id, description, target_id); + update(albumId, description, targetId) { + this.repository.update(albumId, description, targetId); }; - async delete (id) { - this.repository.delete(id); + delete (albumId) { + this.repository.delete(albumId); }; } diff --git a/src/repositories/commentRepository.js b/src/repositories/commentRepository.js index 2e1792f..1e594d5 100644 --- a/src/repositories/commentRepository.js +++ b/src/repositories/commentRepository.js @@ -4,21 +4,21 @@ class CommentRepository { constructor(repository, contract) { assertIsInstanceOfContract(repository, contract); this.repository = repository; - } - async create(description, user_id, post_id) { - return this.repository.create(description, user_id, post_id); }; - async getById(id){ - return this.repository.getById(id); + create(description, userId, postId) { + return this.repository.create(description, userId, postId); }; - async getAll(commentId){ + getById(postId){ + return this.repository.getById(postId); + }; + getAll(commentId){ return this.repository.getAll(commentId); }; - async update(id, description, user_id, post_id) { - this.repository.update(id, description, user_id, post_id); + update(id, description, userId, postId) { + this.repository.update(id, description, userId, postId); }; - async delete (id) { - this.repository.delete(id); + delete (commentId) { + this.repository.delete(commentId); }; } diff --git a/src/repositories/fileTypeRepository.js b/src/repositories/fileTypeRepository.js index 88d1f28..2867e93 100644 --- a/src/repositories/fileTypeRepository.js +++ b/src/repositories/fileTypeRepository.js @@ -4,18 +4,18 @@ class FileTypeRepository { constructor(repository, contract) { assertIsInstanceOfContract(repository, contract); this.repository = repository; - } - async create(type) { - return this.repository.create(type); }; - async getAll(){ + create(newFileType) { + return this.repository.create(newFileType); + }; + getAll(){ return this.repository.getAll(); }; - async getById(id){ - return this.repository.getById(id); + getById(fileTypeId){ + return this.repository.getById(fileTypeId); } - async delete (id) { - this.repository.delete(id); + delete (fileTypeId) { + this.repository.delete(fileTypeId); }; } diff --git a/src/repositories/friendshipRepository.js b/src/repositories/friendshipRepository.js index b7779ef..1d560bb 100644 --- a/src/repositories/friendshipRepository.js +++ b/src/repositories/friendshipRepository.js @@ -4,18 +4,18 @@ class FriendshipRepository { constructor(repository, contract) { assertIsInstanceOfContract(repository, contract); this.repository = repository; - } - async create(principal_user_id, friend_id) { - return this.repository.create(principal_user_id, friend_id); }; - async getAll(userId){ + create(principalUserId, friendId) { + return this.repository.create(principalUserId, friendId); + }; + getAll(userId){ return this.repository.getAll(userId); }; - async getById(id){ - return this.repository.getById(id); + getById(userId){ + return this.repository.getById(userId); }; - async delete(id){ - this.repository.delete(id); + delete(userId){ + this.repository.delete(userId); }; } diff --git a/src/repositories/friendshipRequestRepository.js b/src/repositories/friendshipRequestRepository.js index 5100be2..8d325f5 100644 --- a/src/repositories/friendshipRequestRepository.js +++ b/src/repositories/friendshipRequestRepository.js @@ -1,22 +1,22 @@ const { assertIsInstanceOfContract } = require("./interfaces/validation"); class FriendshipRequestRepository { - constructor(repository, contract) { - assertIsInstanceOfContract(repository, contract); - this.repository = repository; - } - async create(senderId, receiveId) { - return this.repository.create(senderId, receiveId); - } - async getAll(userId) { - return this.repository.getAll(userId); - } - async accept(requestId) { - return this.repository.accept(requestId); - } - async delete(requestId) { - return this.repository.delete(requestId); - } + constructor(repository, contract) { + assertIsInstanceOfContract(repository, contract); + this.repository = repository; + }; + create(senderId, receiverId) { + return this.repository.create(senderId, receiverId); + }; + getAll(userId) { + return this.repository.getAll(userId); + }; + accept(requestId) { + return this.repository.accept(requestId); + }; + delete(requestId) { + return this.repository.delete(requestId); + }; } module.exports = FriendshipRequestRepository; diff --git a/src/repositories/friendshipRequestTypeRepository.js b/src/repositories/friendshipRequestTypeRepository.js index 071b7a5..c03c5b5 100644 --- a/src/repositories/friendshipRequestTypeRepository.js +++ b/src/repositories/friendshipRequestTypeRepository.js @@ -4,19 +4,19 @@ class FriendshipRequestTypeRepository { constructor(repository, contract) { assertIsInstanceOfContract(repository, contract); this.repository = repository; - } - async create(type) { - return this.repository.create(type); - } - async getAll(){ + }; + create(newFriendshipRequestType) { + return this.repository.create(newFriendshipRequestType); + }; + getAll(){ return this.repository.getAll(); - } - async getById(id){ - return this.repository.getById(id); - } - async delete(id){ - return this.repository.delete(id); - } + }; + getById(friendshipRequestId){ + return this.repository.getById(friendshipRequestId); + }; + delete(friendshipRequestId){ + return this.repository.delete(friendshipRequestId); + }; } module.exports = FriendshipRequestTypeRepository; \ No newline at end of file diff --git a/src/repositories/implementation/albumItemRepositoryImplementation.js b/src/repositories/implementation/albumItemRepositoryImplementation.js index 455bca6..cd03b68 100644 --- a/src/repositories/implementation/albumItemRepositoryImplementation.js +++ b/src/repositories/implementation/albumItemRepositoryImplementation.js @@ -5,13 +5,13 @@ const { IAlbumItemRepository } = require("../interfaces/albumItemRepositoryAbstr class AlbumItemRepositoryImplementation extends IAlbumItemRepository { - async create(post_id, album_id) { + async create(postId, albumItemId) { try { return await db.transaction(async (trx) => { const [createdItem] = await db('Album_Item') .insert({ - post_id: post_id, - album_id: album_id + post_id: postId, + album_id: albumItemId }) .returning(['id', 'post_id', 'album_id', 'is_active']) .transacting(trx); @@ -23,25 +23,29 @@ class AlbumItemRepositoryImplementation extends IAlbumItemRepository { } } - async getById(id) { - return db('Album_Item') - .where({ id: id }) - .select(['id', 'post_id', 'album_id', 'is_active']) - .first(); + getById(albumItemId) { + try { + return db('Album_Item') + .where({ id: albumItemId }) + .select(['id', 'post_id', 'album_id', 'is_active']) + .first(); + } catch (err){ + console.error(err); + } } - async getAll(albumId) { + getAll(albumItemId) { return db('Album_Item') - .where({ id: albumId }) + .where({ id: albumItemId }) .select(['id', 'post_id', 'album_id', 'is_active']); } - async delete(id) { + async delete(albumItemId) { try { await db.transaction(async (trx) => { await db('Album_Item') .update({ is_active: false }) - .where({ id: id }) + .where({ id: albumItemId }) .transacting(trx); }); } catch (error) { diff --git a/src/repositories/implementation/albumRepositoryImplementation.js b/src/repositories/implementation/albumRepositoryImplementation.js index 906cbdc..990fa3f 100644 --- a/src/repositories/implementation/albumRepositoryImplementation.js +++ b/src/repositories/implementation/albumRepositoryImplementation.js @@ -2,15 +2,15 @@ const db = require('../../database/config/db'); const ApiError = require("../../utils/ApiError"); const httpStatus = require("../../utils/statusCodes"); const { IAlbumRepository } = require("../interfaces/albumRepositoryAbstract"); -const {where} = require("sequelize"); + class AlbumRepositoryImplementation extends IAlbumRepository{ - async create(description, target_id) { + async create(description, targetId) { try { const[album] = await db('album') .insert({ - description, - target_id + description: description, + target_id: targetId }) .returning('*'); return album @@ -18,24 +18,25 @@ class AlbumRepositoryImplementation extends IAlbumRepository{ throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR,'Error while creating a new album'); } }; - async getById(id){ + getById(albumId){ return db('album') - .where({ id }) + .where({ id: albumId }) .select('id', 'description', 'target_id', 'is_active') .first(); }; - async getAll(albumId){ + getAll(albumId){ return db('album') .where({ id: albumId }) .select('id', 'description', 'target_id', 'is_active'); }; - async update(id, description, target_id) { + + async update(albumId, description, targetId) { try { await db.transaction(async (trx) => { await db('album') - .where({ id }) + .where({ id: albumId }) .update({ - description, target_id + description, targetId }) .transacting(trx); }); @@ -43,11 +44,12 @@ class AlbumRepositoryImplementation extends IAlbumRepository{ throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR,'Error while updating album'); } }; - async delete (id) { + + async delete (albumId) { try { await db.transaction(async (trx) => { await db('album') - .where({ id }) + .where({ id: albumId }) .update({ is_active: false }) .transacting(trx); }); diff --git a/src/repositories/implementation/commentRepositoryImplementation.js b/src/repositories/implementation/commentRepositoryImplementation.js index 835ac20..47b19b9 100644 --- a/src/repositories/implementation/commentRepositoryImplementation.js +++ b/src/repositories/implementation/commentRepositoryImplementation.js @@ -21,49 +21,44 @@ class CommentRepositoryImplementation extends ICommentRepository{ throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while creating a comment'); } } - getById(id) { try { return db('comment').where({ id }).first(); } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while fetching comment by id'); } - } - + }; getAll(commentId) { try { return db('comment').where({ user_id: commentId }); } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, error); } - } - - async update(id, description, user_id, post_id) { + }; + async update(commentId, description) { try { - const [comment] = await db('comment') - .where({ id }) - .update({ - description, - user_id, - post_id, - updated_at: new Date() - }) - .returning('*'); - return comment; + await db.transaction(async (trx) => { + await db('comment') + .where({id: commentId}) + .update({ + description: description, + updated_at: new Date() + }) + .transacting(trx); + }); } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while updating comment'); } - } - - async delete(id) { + }; + async delete(commentId) { try { await db('comment') - .where({ id }) + .where({ id: commentId }) .update({ is_active: false }); } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while deleting comment'); } - } + }; } module.exports = CommentRepositoryImplementation; diff --git a/src/repositories/implementation/fileTypeRepositoryImplementation.js b/src/repositories/implementation/fileTypeRepositoryImplementation.js index 04c5fae..a5aff72 100644 --- a/src/repositories/implementation/fileTypeRepositoryImplementation.js +++ b/src/repositories/implementation/fileTypeRepositoryImplementation.js @@ -4,13 +4,13 @@ const ApiError = require("../../utils/ApiError"); const { IFileTypeRepository } = require("../interfaces/fileTypeRepositoryAbstract"); class FileTypeRepositoryImplementation extends IFileTypeRepository { - async create(type) { + async create(newFileType) { try { const [fileType] = await db.transaction(async (trx) => { return db('file_type') .transacting(trx) .insert({ - type, + type: newFileType, is_active: true }); }); @@ -20,23 +20,23 @@ class FileTypeRepositoryImplementation extends IFileTypeRepository { } }; - async getAll(){ + getAll(){ return db('file_type') .select('id', 'type', 'is_active'); }; - async getById(id){ + getById(fileTypeId){ return db('file_type') - .where({ id }) + .where({ id: fileTypeId }) .select('id', 'type', 'is_active') .first(); }; - async delete (id) { + async delete (fileTypeId) { try { await db.transaction(async (trx) => { await db('file_type') - .where({ id }) + .where({ id: fileTypeId }) .update({ is_active: false }) .transacting(trx); }); diff --git a/src/repositories/implementation/friendshipRepositoryImplementation.js b/src/repositories/implementation/friendshipRepositoryImplementation.js index 4904124..65aa738 100644 --- a/src/repositories/implementation/friendshipRepositoryImplementation.js +++ b/src/repositories/implementation/friendshipRepositoryImplementation.js @@ -4,14 +4,14 @@ const ApiError = require("../../utils/ApiError"); const { IFriendshipRepository } = require("../interfaces/friendshipRepositoryAbstract"); class FriendshipRepositoryImplementation extends IFriendshipRepository { - async create(principal_user_id, friend_id) { + async create(principalUserId, friendId) { try { const [friendship] = await db.transaction(async (trx) => { return db('friendship') .transacting(trx) .insert({ - principal_user_id, - friend_id, + principal_user_id: principalUserId, + friend_id: friendId, is_active: true }); }); diff --git a/src/repositories/implementation/friendshipRequestRepository.js b/src/repositories/implementation/friendshipRequestRepository.js index 2b2a993..3ddca2f 100644 --- a/src/repositories/implementation/friendshipRequestRepository.js +++ b/src/repositories/implementation/friendshipRequestRepository.js @@ -5,32 +5,30 @@ const friendshipRequestTypeStatus = require("../../utils/friendshipRequestTypeSt const httpStatus = require('../../utils/statusCodes'); class FriendshipRequestRepositoryImplementation extends IFriendshipRequestRepository { - async create(senderId, receiveId) { + create(senderId, receiverId) { try { - await db("friendship_request").insert({ + db("friendship_request").insert({ sender_id: senderId, - receiver_id: receiveId, + receiver_id: receiverId, request_type_id: friendshipRequestTypeStatus.AWAITING_APPROVAL }); } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while creating friendship request'); } - } - - async getAll(userId) { + }; + getAll(userId) { try { - return await db("friendship_request") + return db("friendship_request") .where("sender_id", userId) .orWhere("receiver_id", userId) .select("*"); } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while getting all friendship requests'); } - } - - async accept(requestId) { + }; + accept(requestId) { try { - await db("friendship_request") + db("friendship_request") .where({ id: requestId }) .update({ request_type_id: friendshipRequestTypeStatus.ACCEPTED, @@ -39,17 +37,16 @@ class FriendshipRequestRepositoryImplementation extends IFriendshipRequestReposi } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while accepting friendship request'); } - } - - async delete(requestId) { + }; + delete(requestId) { try { - await db("friendship_request") + db("friendship_request") .where({ id: requestId }) .del(); } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while deleting friendship request'); } - } + }; } module.exports = FriendshipRequestRepositoryImplementation; diff --git a/src/repositories/implementation/friendshipRequestTypeRepository.js b/src/repositories/implementation/friendshipRequestTypeRepository.js index 69233ad..1924329 100644 --- a/src/repositories/implementation/friendshipRequestTypeRepository.js +++ b/src/repositories/implementation/friendshipRequestTypeRepository.js @@ -4,46 +4,43 @@ const ApiError = require("../../utils/ApiError"); const { IFriendshipRequestTypeRepository } = require("../interfaces/friendshipRequestTypeAbstract"); class FriendshipRequestTypeRepositoryImplementation extends IFriendshipRequestTypeRepository { - async create(type) { + create(newFriendShipRequestType) { try { - await db("friendship_request_type").insert({ - type: type, + db("friendship_request_type").insert({ + type: newFriendShipRequestType, created_at: new Date(), updated_at: new Date() }); } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while creating friendship request type'); } - } - - async getAll() { + }; + getAll() { try { - return await db("friendship_request_type").select("id", "type"); + return db("friendship_request_type").select("id", "type"); } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while getting all friendship request types'); } - } - - async getById(id) { + }; + getById(friendShipRequestTypeId) { try { - return await db("friendship_request_type") - .where({ id: id }) + return db("friendship_request_type") + .where({ id: friendShipRequestTypeId }) .first() .select("id", "type"); } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while getting friendship request type by id'); } - } - - async delete(id) { + }; + delete(friendShipRequestTypeId) { try { - await db("friendship_request_type") - .where({ id: id }) + db("friendship_request_type") + .where({ id: friendShipRequestTypeId }) .del(); } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while deleting friendship request type'); } - } + }; } module.exports = FriendshipRequestTypeRepositoryImplementation; diff --git a/src/repositories/implementation/postRepositoryImplementation.js b/src/repositories/implementation/postRepositoryImplementation.js index 0dd333b..a04aa39 100644 --- a/src/repositories/implementation/postRepositoryImplementation.js +++ b/src/repositories/implementation/postRepositoryImplementation.js @@ -4,16 +4,16 @@ const ApiError = require("../../utils/ApiError"); const { IPostRepository } = require("../interfaces/postRepositoryAbstract"); class PostRepositoryImplementation extends IPostRepository { - async create(description, userId, target_id, type_id) { + async create(description, userId, targetId, typeId) { try { const [post] = await db.transaction(async (trx) => { return db('post') .transacting(trx) .insert({ - description, + description: description, user_id: userId, - target_id, - type_id + target_id: targetId, + type_id: typeId }); }); return post; @@ -22,9 +22,9 @@ class PostRepositoryImplementation extends IPostRepository { } }; - async getById(id){ + async getById(postId){ return db('post') - .where({ id }) + .where({ id: postId }) .select('id', 'description', 'user_id', 'target_id', 'type_id', 'is_active') .first(); }; @@ -35,15 +35,15 @@ class PostRepositoryImplementation extends IPostRepository { .select('id', 'description', 'user_id', 'target_id', 'type_id', 'is_active'); }; - async update(id, description, target_id, type_id) { + async update(id, description, targetId, typeId) { try { await db.transaction(async (trx) => { await db('post') .where({ id }) .update({ description: description, - target_id: target_id, - type_id: type_id + target_id: targetId, + type_id: typeId }) .transacting(trx); }); @@ -52,11 +52,11 @@ class PostRepositoryImplementation extends IPostRepository { } }; - async delete (id) { + async delete (postId) { try { await db.transaction(async (trx) => { await db('post') - .where({ id }) + .where({ id: postId }) .update({ is_active: false }) .transacting(trx); }); diff --git a/src/repositories/implementation/reactionRepositoryImplementation.js b/src/repositories/implementation/reactionRepositoryImplementation.js index d22afb6..99f79b5 100644 --- a/src/repositories/implementation/reactionRepositoryImplementation.js +++ b/src/repositories/implementation/reactionRepositoryImplementation.js @@ -21,9 +21,9 @@ class ReactionRepositoryImplementation extends IReactionRepository { } }; - async getById(id){ + async getById(reactionId){ return db('reaction') - .where({ id }) + .where({ id: reactionId }) .select('id', 'user_id', 'reaction_type_id', 'post_id', 'is_active') .first(); }; @@ -51,11 +51,11 @@ class ReactionRepositoryImplementation extends IReactionRepository { } }; - async delete (id) { + async delete (reactionId) { try { await db.transaction(async (trx) => { await db('reaction') - .where({ id }) + .where({ id: reactionId }) .update({ is_active: false }) .transacting(trx); }); diff --git a/src/repositories/implementation/reactionTypeRepositoryImplementation.js b/src/repositories/implementation/reactionTypeRepositoryImplementation.js index 409ad2f..160420e 100644 --- a/src/repositories/implementation/reactionTypeRepositoryImplementation.js +++ b/src/repositories/implementation/reactionTypeRepositoryImplementation.js @@ -17,14 +17,14 @@ class ReactionTypeRepositoryImplementation extends IReactionTypeRepository { } }; - async getById(id){ + getById(reactionTypeId){ return db('reaction_type') - .where({ id }) + .where({ id: reactionTypeId }) .select('id', 'description', 'is_active') .first(); }; - async getAll(){ + getAll(){ return db('reaction_type') .select('id', 'description', 'is_active'); }; diff --git a/src/repositories/implementation/targetPublicRepositoryImplementation.js b/src/repositories/implementation/targetPublicRepositoryImplementation.js index 276b78e..e1cc7d4 100644 --- a/src/repositories/implementation/targetPublicRepositoryImplementation.js +++ b/src/repositories/implementation/targetPublicRepositoryImplementation.js @@ -4,12 +4,12 @@ const httpStatus = require("../../utils/statusCodes"); const { ITargetPublicRepository } = require("../interfaces/targetPublicRepositoryAbstract"); class TargetPublicRepositoryImplementation extends ITargetPublicRepository { - async create(type) { + async create(newTargetPublicType) { try { const [target] = await db.transaction(async (trx) => { return db('target_public') .transacting(trx) - .insert({ type }); + .insert({ type: newTargetPublicType }); }); return target; } catch (error) { @@ -22,18 +22,18 @@ class TargetPublicRepositoryImplementation extends ITargetPublicRepository { .select('id', 'type', 'is_active'); }; - async getById(id){ + async getById(targetPublicTypeId){ return db('target_public') - .where({ id }) + .where({ id: targetPublicTypeId }) .select('id', 'type', 'is_active') .first(); }; - async delete(id) { + async delete(targetPublicTypeId) { try { await db.transaction(async (trx) => { await db('target_public') - .where({ id }) + .where({ id: targetPublicTypeId }) .update({ is_active: false }) .transacting(trx); }); diff --git a/src/repositories/implementation/tokenRepositoryImplementation.js b/src/repositories/implementation/tokenRepositoryImplementation.js index 45b13d1..0997edf 100644 --- a/src/repositories/implementation/tokenRepositoryImplementation.js +++ b/src/repositories/implementation/tokenRepositoryImplementation.js @@ -4,39 +4,40 @@ const httpStatus = require("../../utils/statusCodes"); const {ITokenRepository} = require("../interfaces/tokenRepositoryAbstract"); class TokenRepositoryImplementation extends ITokenRepository{ -async create(token, user_id) { - try { - const result = await db('token').insert({ - value: token, - user_id: user_id - }); - return result; - } catch (error) { - throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR,'Error while creating token'); - } + create(token, userId) { + try { + return db('token').insert({ + value: token, + user_id: userId + }); + } catch (error) { + throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR,'Error while creating token'); + } } -async getTokenByUserId(userId) { + + getTokenByUserId(userId) { try { - const token = await db('token').where({ user_id: userId }).first(); - return token; + return db('token').where({ user_id: userId }).first(); } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR,'Error while revoking token'); } } -async revokeTokenByUserId(userId) { - try { - await db('token').where({ user_id: userId }).del(); - } catch (error) { - throw new Error('Error while revoking token'); + + revokeTokenByUserId(userId) { + try { + db('token').where({ user_id: userId }).del(); + } catch (error) { + throw new Error('Error while revoking token'); + } } -} -async updateById(id, newToken) { - try { - await db('token').where({ id: id }).update({ value: newToken }); - } catch (error) { - throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR,'Error while deleting token'); + updateById(id, newToken) { + try { + db('token').where({ id: id }).update({ value: newToken }); + } catch (error) { + throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR,'Error while deleting token'); + } } -}} +} module.exports = TokenRepositoryImplementation; diff --git a/src/repositories/implementation/userRepositoryImplementation.js b/src/repositories/implementation/userRepositoryImplementation.js index a75a8b4..8464357 100644 --- a/src/repositories/implementation/userRepositoryImplementation.js +++ b/src/repositories/implementation/userRepositoryImplementation.js @@ -2,14 +2,13 @@ const db = require('../../database/config/db'); const httpStatus = require("../../utils/statusCodes"); const { IUserRepository } = require("../interfaces/userRepositoryAbstract"); const ApiError = require("../../utils/ApiError"); -const knex = require('knex'); class UserRepositoryImplementation extends IUserRepository{ - async create(full_name, email, hashedPassword) { + async create(fullName, email, hashedPassword) { try { const [userId] = await db('user').insert({ - full_name, - email, + full_name: fullName, + email: email, password: hashedPassword, created_at: new Date(), updated_at: new Date(), @@ -19,65 +18,60 @@ class UserRepositoryImplementation extends IUserRepository{ } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR,'Error while creating user'); } - } - async getByEmail(email) { + }; + getByEmail(email) { try { - return await db('user') + return db('user') .where({ email: email }) .first(); } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while getting a email by id'); } }; - - async getById(id){ + getById(userId){ try { - return await db('user') + return db('user') .select('id', 'full_name', 'email', 'password') - .where({ id }) + .where({ id: userId }) .first(); } catch (error) { throw new ApiError(httpStatus.NOT_FOUND, 'Error while getting user by id'); } }; - - async getAll(){ + getAll(){ try { - return await db('user') + return db('user') .select('id', 'full_name', 'email') - // .where({ is_active: true }); + .where({ is_active: true }); } catch (error) { throw new Error('Error while getting all users'); } }; - - async update(id, full_name, email) { + update(userId, fullName, email) { try { - await db('user') - .where({ id }) + db('user') + .where({ id: userId }) .update({ - full_name, - email, + full_name: fullName, + email: email, updated_at: new Date() }); } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR,'Error while updating user'); } }; - - async delete (id) { + delete (userId) { try { - await db('user') - .where({ id }) + db('user') + .where({ id: userId }) .update({ is_active: false }); } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR,'Error while deleting user'); } }; - - async getFeedNews(id) { + getFeedNews(userId) { try { - return await db.raw(` + return db.raw(` SELECT post_id, post_description, @@ -132,16 +126,15 @@ class UserRepositoryImplementation extends IUserRepository{ ) AS R ON R.post_id = P.id WHERE U.id = :userId) AS subquery GROUP BY post_id, post_description, created_at, comment_quantity - ORDER BY post_id`, { userId: id } + ORDER BY post_id`, { userId: userId } ); } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while getting a feed'); } }; - - async getPostStatistics() { + getPostStatistics() { try { - return await db.raw(` + return db.raw(` SELECT post_id, post_description, @@ -202,7 +195,6 @@ class UserRepositoryImplementation extends IUserRepository{ throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while getting a post statistics'); } }; - } module.exports = UserRepositoryImplementation; diff --git a/src/repositories/postRepository.js b/src/repositories/postRepository.js index c19ffe5..bbdd90a 100644 --- a/src/repositories/postRepository.js +++ b/src/repositories/postRepository.js @@ -4,21 +4,21 @@ class PostRepository { constructor(repository, contract) { assertIsInstanceOfContract(repository, contract); this.repository = repository; - } - async create(description, user_id, target_id, type_id) { - return this.repository.create(description, user_id, target_id, type_id); }; - async getById(id){ - return this.repository.getById(id); + create(description, userId, targetId, typeId) { + return this.repository.create(description, userId, targetId, typeId); }; - async getAll(userId){ + getById(postId){ + return this.repository.getById(postId); + }; + getAll(userId){ return this.repository.getAll(userId); }; - async update(id, description, user_id, target_id, type_id) { - this.repository.update(id, description, user_id, target_id, type_id); + update(postId, description, userId, targetId, typeId) { + this.repository.update(postId, description, userId, targetId, typeId); }; - async delete (id) { - this.repository.delete(id); + delete (postId) { + this.repository.delete(postId); }; } diff --git a/src/repositories/reactionRepository.js b/src/repositories/reactionRepository.js index b41fdcf..ad11bfc 100644 --- a/src/repositories/reactionRepository.js +++ b/src/repositories/reactionRepository.js @@ -5,20 +5,20 @@ class ReactionRepository { assertIsInstanceOfContract(repository, contract); this.repository = repository; } - async create(userId, reaction_type_id, post_id) { - return this.repository.create(userId, reaction_type_id, post_id); + create(userId, reactionTypeId, postId) { + return this.repository.create(userId, reactionTypeId, postId); }; - async getById(id){ - return this.repository.getById(id); + getById(reactionId){ + return this.repository.getById(reactionId); }; - async getAll(userId){ + getAll(userId){ return this.repository.getAll(userId); }; - async update(id, user_id, reaction_type_id, post_id) { - this.repository.update(id, user_id, reaction_type_id, post_id); + update(reactionId, userId, reactionTypeId, postId) { + this.repository.update(reactionId, userId, reactionTypeId, postId); }; - async delete (id) { - this.repository.delete(id); + delete (reactionId) { + this.repository.delete(reactionId); }; } diff --git a/src/repositories/reactionTypeRepository.js b/src/repositories/reactionTypeRepository.js index d4bec19..3089fbd 100644 --- a/src/repositories/reactionTypeRepository.js +++ b/src/repositories/reactionTypeRepository.js @@ -5,17 +5,17 @@ class ReactionTypeRepository { assertIsInstanceOfContract(repository, contract); this.repository = repository; } - async create(description) { - return this.repository.create(description); + create(reactionTypeDescription) { + return this.repository.create(reactionTypeDescription); }; - async getById(id){ - return this.repository.getById(id); + getById(reactionTypeId){ + return this.repository.getById(reactionTypeId); }; - async getAll(){ + getAll(){ return this.repository.getAll(); }; - async delete (id) { - return this.repository.delete(id); + delete (reactionTypeId) { + return this.repository.delete(reactionTypeId); }; } diff --git a/src/repositories/targetPublicRepository.js b/src/repositories/targetPublicRepository.js index 1f6697e..56b6071 100644 --- a/src/repositories/targetPublicRepository.js +++ b/src/repositories/targetPublicRepository.js @@ -5,17 +5,17 @@ class TargetPublicRepository { assertIsInstanceOfContract(repository, contract); this.repository = repository; } - async create(type) { + create(type) { return this.repository.create(type); }; - async getAll(){ + getAll(){ return this.repository.getAll() }; - async getById(id){ - return this.repository.getById(id); + getById(targetPublicId){ + return this.repository.getById(targetPublicId); }; - async delete(id) { - return this.repository.delete(id); + delete(targetPublicId) { + return this.repository.delete(targetPublicId); }; } diff --git a/src/repositories/tokenRepository.js b/src/repositories/tokenRepository.js index c9d6821..f8fe201 100644 --- a/src/repositories/tokenRepository.js +++ b/src/repositories/tokenRepository.js @@ -4,19 +4,19 @@ class TokenRepository { constructor(repository, contract) { assertIsInstanceOfContract(repository, contract); this.repository = repository; - } - async create(token, user_id) { - return this.repository.create(token, user_id); }; - async getTokenByUserId(userId) { + create(token, userId) { + return this.repository.create(token, userId); + }; + getTokenByUserId(userId) { return this.repository.getTokenByUserId(userId); }; - async revokeTokenByUserId(userId){ + revokeTokenByUserId(userId){ return this.repository.revokeTokenByUserId(userId); - } - async updateById(id, newToken){ - return this.repository.updateById(id, newToken); - } + }; + updateById(tokenId, newToken){ + return this.repository.updateById(tokenId, newToken); + }; } module.exports = TokenRepository; diff --git a/src/repositories/userRepository.js b/src/repositories/userRepository.js index ff39bfe..936dd25 100644 --- a/src/repositories/userRepository.js +++ b/src/repositories/userRepository.js @@ -5,28 +5,28 @@ class UserRepository { assertIsInstanceOfContract(repository, contract); this.repository = repository; } - async create(full_name, email, hashedPassword) { - return this.repository.create(full_name, email, hashedPassword); + create(fullName, email, hashedPassword) { + return this.repository.create(fullName, email, hashedPassword); }; - async getByEmail(email) { + getByEmail(email) { return this.repository.getByEmail(email); }; - async getById(id){ - return this.repository.getById(id); + getById(userId){ + return this.repository.getById(userId); }; - async getAll(){ + getAll(){ return this.repository.getAll(); }; - async update(id, full_name, email, hashedPassword) { - this.repository.update(id, full_name, email, hashedPassword); + update(userId, fullName, email, hashedPassword) { + this.repository.update(userId, fullName, email, hashedPassword); }; - async delete (userId) { + delete (userId) { this.repository.delete(userId); }; - async getFeedNews(userId) { + getFeedNews(userId) { return this.repository.getFeedNews(userId); }; - async getPostStatistics() { + getPostStatistics() { return this.repository.getPostStatistics(); }; } diff --git a/src/routes/targetPublicRoutes.js b/src/routes/targetPublicRoutes.js index 15c7dde..5f0c53c 100644 --- a/src/routes/targetPublicRoutes.js +++ b/src/routes/targetPublicRoutes.js @@ -3,7 +3,7 @@ const express = require('express'); function createTargetPublicRoutes(targetPublicController){ const router = express.Router(); router.post('/', targetPublicController.createTargetPublic.bind(targetPublicController)); - router.get('/', targetPublicController.getTargetPublics.bind(targetPublicController)); + router.get('/', targetPublicController.getTargetPublic.bind(targetPublicController)); router.delete('/:id', targetPublicController.deleteTargetPublic.bind(targetPublicController)); return router } diff --git a/src/schemas/albumSchema.js b/src/schemas/albumSchema.js index de283e2..66e62d5 100644 --- a/src/schemas/albumSchema.js +++ b/src/schemas/albumSchema.js @@ -6,13 +6,13 @@ const createAlbumSchema = yup.object({ }); const updateAlbumSchema = yup.object({ - id: yup.number().integer().required(), + album_id: yup.number().integer().required(), description: yup.string().required(), target_id: yup.number().integer().required() }); const getByIdSchema = yup.object({ - id: yup.number().integer().required() + album_id: yup.number().integer().required() }); const authorizationSchema = yup.object().shape({ diff --git a/src/schemas/commentsSchema.js b/src/schemas/commentsSchema.js index cb6bdcf..3127f97 100644 --- a/src/schemas/commentsSchema.js +++ b/src/schemas/commentsSchema.js @@ -1,21 +1,18 @@ const yup = require('yup'); const createCommentSchema = yup.object({ - authorization: yup.string().required(), description: yup.string().required(), - user_id: yup.number().integer().required(), post_id: yup.number().integer().required() }); const updateCommentSchema = yup.object({ id: yup.number().integer().required(), description: yup.string().required(), - user_id: yup.number().integer().required(), - post_id: yup.number().integer().required() }); const getByIdSchema = yup.object({ - id: yup.number().integer().required() + id: yup.number().integer().required(), + authorization: yup.string().required(), }); const authorizationSchema = yup.object().shape({ @@ -27,4 +24,4 @@ module.exports = { updateCommentSchema, getByIdSchema, authorizationSchema -}; \ No newline at end of file +}; diff --git a/src/schemas/fileTypeSchema.js b/src/schemas/fileTypeSchema.js index 787cf3a..bb224c8 100644 --- a/src/schemas/fileTypeSchema.js +++ b/src/schemas/fileTypeSchema.js @@ -8,7 +8,6 @@ const getByIdSchema = yup.object({ id: yup.number().integer().required() }); - module.exports = { createFileTypeSchema, getByIdSchema diff --git a/src/schemas/friendshipSchema.js b/src/schemas/friendshipSchema.js index 7ab5ce7..6b28638 100644 --- a/src/schemas/friendshipSchema.js +++ b/src/schemas/friendshipSchema.js @@ -12,4 +12,4 @@ const authorizationSchema = yup.object().shape({ module.exports = { getByIdSchema, authorizationSchema -}; \ No newline at end of file +}; diff --git a/src/schemas/idSchema.js b/src/schemas/idSchema.js index 8eea5cb..25a214c 100644 --- a/src/schemas/idSchema.js +++ b/src/schemas/idSchema.js @@ -1,4 +1,5 @@ const yup = require('yup'); + const userSchema = yup.object({ id: yup.string().required() }); diff --git a/src/schemas/postSchema.js b/src/schemas/postSchema.js index f6a33f7..3eef878 100644 --- a/src/schemas/postSchema.js +++ b/src/schemas/postSchema.js @@ -29,4 +29,4 @@ module.exports = { updatePostSchema, getByIdSchema, authorizationSchema -}; \ No newline at end of file +}; diff --git a/src/schemas/reactionsSchema.js b/src/schemas/reactionsSchema.js index 3b30eb0..5f7001b 100644 --- a/src/schemas/reactionsSchema.js +++ b/src/schemas/reactionsSchema.js @@ -18,6 +18,7 @@ const updateReactionsSchemaAuthorization = yup.object().shape({ id: yup.number().integer().required(), authorization: yup.string().required() }); + module.exports = { createReactionsSchema, updateReactionsSchemaAuthorization, diff --git a/src/schemas/userSchema.js b/src/schemas/userSchema.js index ed6eee6..8a2e6bd 100644 --- a/src/schemas/userSchema.js +++ b/src/schemas/userSchema.js @@ -16,6 +16,7 @@ const updateUserSchema = yup.object().shape({ email: yup.string().email(), password: yup.string(), }); + const getByIdSchema = yup.object().shape({ id: yup.number().integer().required(), }); @@ -25,4 +26,4 @@ module.exports = { updateUserSchema, getByIdSchema, authorizationSchema -}; \ No newline at end of file +}; diff --git a/src/services/albumItemService.js b/src/services/albumItemService.js index 66dcf50..9e0e585 100644 --- a/src/services/albumItemService.js +++ b/src/services/albumItemService.js @@ -4,17 +4,17 @@ const httpStatus = require("../utils/statusCodes"); class AlbumItemService { constructor(albumItemRepository) { this.albumItemRepository = albumItemRepository; - } - async createAlbumItem(post_id, album_id) { - return this.albumItemRepository.create(post_id, album_id); }; - async getAllAlbumItem(albumId) { - return this.albumItemRepository.getAll(albumId); + createAlbumItem(postId, albumItemId) { + return this.albumItemRepository.create(postId, albumItemId); }; - async deleteAlbumItem(id) { - const albumItem = await this.albumItemRepository.getById(id); + getAllAlbumItem(albumItemId) { + return this.albumItemRepository.getAll(albumItemId); + }; + async deleteAlbumItem(albumItemId) { + const albumItem = await this.albumItemRepository.getById(albumItemId); if (!albumItem) throw new ApiError(httpStatus.NOT_FOUND, 'Album item not found'); - await this.albumItemRepository.delete(id); + await this.albumItemRepository.delete(albumItemId); }; } diff --git a/src/services/albumService.js b/src/services/albumService.js index b9feda2..ede4af6 100644 --- a/src/services/albumService.js +++ b/src/services/albumService.js @@ -4,27 +4,27 @@ const ApiError = require("../utils/ApiError"); class AlbumService { constructor(albumRepository) { this.albumRepository = albumRepository; - } - async createAlbum(description, target_id) { - return this.albumRepository.create(description, target_id); }; - async getAlbumById(id) { - const album = await this.albumRepository.getById(id); + createAlbum(description, targetId) { + return this.albumRepository.create(description, targetId); + }; + async getAlbumById(albumId) { + const album = await this.albumRepository.getById(albumId); if (!album) throw new ApiError(httpStatus.NOT_FOUND, 'Album not found!'); return album; }; - async getAllAlbums(albumId) { + getAllAlbums(albumId) { return this.albumRepository.getAll(albumId); }; - async updateAlbum(id, description, target_id) { - const album = await this.albumRepository.getById(id); + async updateAlbum(albumId, description, targetId) { + const album = await this.albumRepository.getById(albumId); if (!album) throw new ApiError(httpStatus.NOT_FOUND, 'Album not found!'); - await this.albumRepository.update(id, description, target_id); + await this.albumRepository.update(albumId, description, targetId); }; - async deleteAlbum(id) { - const album = await this.albumRepository.getById(id); + async deleteAlbum(albumId) { + const album = await this.albumRepository.getById(albumId); if (!album) throw new ApiError(httpStatus.NOT_FOUND, 'Album not found!'); - await this.albumRepository.delete(id); + await this.albumRepository.delete(albumId); }; } diff --git a/src/services/authService.js b/src/services/authService.js index 50d1b54..bbc7071 100644 --- a/src/services/authService.js +++ b/src/services/authService.js @@ -6,7 +6,7 @@ class AuthenticateService { constructor(userRepository, hashService) { this.userRepository = userRepository; this.hashService = hashService; - } + }; async authenticateLoginUser(email, password) { const user = await this.userRepository.getByEmail(email); if (!user) throw new ApiError(httpStatus.UNAUTHORIZED, 'Email or password incorrect'); diff --git a/src/services/commentService.js b/src/services/commentService.js index 6fbfd77..45bf95c 100644 --- a/src/services/commentService.js +++ b/src/services/commentService.js @@ -4,27 +4,27 @@ const httpStatus = require("../utils/statusCodes"); class CommentService { constructor(commentRepository) { this.commentRepository = commentRepository; - } - async create(description, user_id, post_id) { - return this.commentRepository.create(description, user_id, post_id); }; - async getCommentById(id) { - const comment = await this.commentRepository.getById(id); + create(description, userId, postId) { + return this.commentRepository.create(description, userId, postId); + }; + async getCommentById(commentId) { + const comment = await this.commentRepository.getById(commentId); if (!comment) throw new ApiError(httpStatus.NOT_FOUND, 'Comment not found'); return comment; }; - async getAllComments(commentId) { + getAllComments(commentId) { return this.commentRepository.getAll(commentId); }; - async updateComment(id, description, user_id, post_id) { - const comment = await this.commentRepository.getById(id); + async updateComment(commentId, description) { + const comment = await this.commentRepository.getById(commentId); if (!comment) throw new ApiError(httpStatus.NOT_FOUND, 'Comment not found'); - await this.commentRepository.update(id, description, user_id, post_id); + await this.commentRepository.update(commentId, description); }; - async deleteComment(id) { - const comment = await this.commentRepository.getById(id); + async deleteComment(commentId) { + const comment = await this.commentRepository.getById(commentId); if (!comment) throw new ApiError(httpStatus.NOT_FOUND, 'Comment not found'); - await this.commentRepository.delete(id); + await this.commentRepository.delete(commentId); }; } diff --git a/src/services/cryptoService.js b/src/services/cryptoService.js index 5b16f0c..f3fc2d7 100644 --- a/src/services/cryptoService.js +++ b/src/services/cryptoService.js @@ -1,13 +1,12 @@ const bcrypt = require('bcrypt'); class CryptoService { - async hash (input) { + hash (input) { return bcrypt.hash(input, 10); }; - - async compare (input, hashedOutput) { + compare (input, hashedOutput) { return bcrypt.compare(input, hashedOutput); - } + }; } module.exports = CryptoService; diff --git a/src/services/fileTypeService.js b/src/services/fileTypeService.js index 716764d..77c1425 100644 --- a/src/services/fileTypeService.js +++ b/src/services/fileTypeService.js @@ -4,21 +4,22 @@ const httpStatus = require("../utils/statusCodes"); class FileTypeService { constructor(fileTypeRepository) { this.fileTypeRepository = fileTypeRepository; - } - async createFileType(type) { - return this.fileTypeRepository.create(type) }; - async getById(id){ - const fileType = await this.fileTypeRepository.getById(id); + createFileType(newFileType) { + return this.fileTypeRepository.create(newFileType) + }; + async getById(fileTypeId){ + const fileType = await this.fileTypeRepository.getById(fileTypeId); if (!fileType) throw new ApiError(httpStatus.NOT_FOUND, 'File type not found!'); return fileType; } - async getAllFileType() { + getAllFileType() { return this.fileTypeRepository.getAll(); }; - async deleteFileType(id) { - await this.getById(id); - await this.fileTypeRepository.delete(id); + async deleteFileType(fileTypeId) { + const fileType = await this.fileTypeRepository.getById(fileTypeId); + if (!fileType) throw new ApiError(httpStatus.NOT_FOUND, 'File type not found!'); + await this.fileTypeRepository.delete(fileTypeId); }; } diff --git a/src/services/friendshipRequestService.js b/src/services/friendshipRequestService.js index cbd135c..cdcbac8 100644 --- a/src/services/friendshipRequestService.js +++ b/src/services/friendshipRequestService.js @@ -1,19 +1,19 @@ class FriendshipRequestService { constructor(friendshipRequestRepository) { this.friendshipRequestRepository = friendshipRequestRepository; - } - async sendFriendshipRequest(senderId, receiverId) { + }; + sendFriendshipRequest(senderId, receiverId) { return this.friendshipRequestRepository.create(senderId, receiverId); - } - async getAllFriendshipRequests(userId) { + }; + getAllFriendshipRequests(userId) { return this.friendshipRequestRepository.getAll(userId); - } - async acceptFriendshipRequest(requestId) { + }; + acceptFriendshipRequest(requestId) { this.friendshipRequestRepository.accept(requestId); - } - async rejectFriendshipRequest(requestId) { + }; + rejectFriendshipRequest(requestId) { return this.friendshipRequestRepository.delete(requestId); - } + }; } module.exports = FriendshipRequestService; diff --git a/src/services/friendshipRequestTypeService.js b/src/services/friendshipRequestTypeService.js index c413faf..ce4dc72 100644 --- a/src/services/friendshipRequestTypeService.js +++ b/src/services/friendshipRequestTypeService.js @@ -4,22 +4,23 @@ const httpStatus = require("../utils/statusCodes"); class FriendshipRequestTypeService { constructor(friendshipRequestTypeRepository) { this.friendshipRequestTypeRepository = friendshipRequestTypeRepository; - } - async create(type) { - return this.friendshipRequestTypeRepository.create(type); - } - async getAll(){ + }; + create(newFriendshipRequestType) { + return this.friendshipRequestTypeRepository.create(newFriendshipRequestType); + }; + getAll(){ return this.friendshipRequestTypeRepository.getAll(); - } - async getById(id){ - const friendshipRequestType = await this.friendshipRequestTypeRepository.getById(id); + }; + async getById(friendshipRequestTypeId){ + const friendshipRequestType = await this.friendshipRequestTypeRepository.getById(friendshipRequestTypeId); if (!friendshipRequestType) throw new ApiError(httpStatus.NOT_FOUND, 'Friendship request type not found.'); return friendshipRequestType; - } - async delete(id){ - await this.getById(id); - return this.friendshipRequestTypeRepository.delete(id); - } + }; + async delete(friendshipRequestTypeId){ + const friendshipRequestType = await this.friendshipRequestTypeRepository.getById(friendshipRequestTypeId); + if(!friendshipRequestType) throw new ApiError(httpStatus.NOT_FOUND, 'Friendship request type not found.') + return this.friendshipRequestTypeRepository.delete(friendshipRequestTypeId); + }; } -module.exports = FriendshipRequestTypeService; \ No newline at end of file +module.exports = FriendshipRequestTypeService; diff --git a/src/services/friendshipServices.js b/src/services/friendshipServices.js index b3f764e..462eab9 100644 --- a/src/services/friendshipServices.js +++ b/src/services/friendshipServices.js @@ -4,21 +4,22 @@ const httpStatus = require("../utils/statusCodes"); class FriendshipService { constructor(friendshipRepository) { this.friendshipRepository = friendshipRepository; - } - async create(principal_user_id, friend_id) { - return this.friendshipRepository.create(principal_user_id, friend_id); }; - async getAllFriendships(userId) { + create(principalUserId, friendId) { + return this.friendshipRepository.create(principalUserId, friendId); + }; + getAllFriendships(userId) { return this.friendshipRepository.getAll(userId); }; - async getById(id){ - const friendship = await this.friendshipRepository.getById(id); + async getById(friendshipId){ + const friendship = await this.friendshipRepository.getById(friendshipId); if (!friendship) throw new ApiError(httpStatus.NOT_FOUND, 'Friendship not found.'); return friendship; }; - async deleteFriendship(id) { - await this.getById(id); - await this.friendshipRepository.delete(id); + async deleteFriendship(friendshipId) { + const friendship = await this.friendshipRepository.getById(friendshipId); + if (!friendship) throw new ApiError(httpStatus.NOT_FOUND, 'Friendship not found.'); + await this.friendshipRepository.delete(friendshipId); }; } diff --git a/src/services/postService.js b/src/services/postService.js index 080a98b..1e9de16 100644 --- a/src/services/postService.js +++ b/src/services/postService.js @@ -4,27 +4,27 @@ const httpStatus = require("../utils/statusCodes"); class PostService { constructor(postRepository) { this.postRepository = postRepository; - } - async createPost(description, userId, target_id, type_id) { - return this.postRepository.create(description, userId, target_id, type_id); + }; + createPost(description, userId, targetId, typeId) { + return this.postRepository.create(description, userId, targetId, typeId); }; async getPostById(id) { const post = await this.postRepository.getById(id); if (!post) throw new ApiError(httpStatus.NOT_FOUND, 'Post not found'); return post; }; - async getAllPosts(userId) { + getAllPosts(userId) { return this.postRepository.getAll(userId); }; - async updatePost(id, description, target_id, type_id) { + async updatePost(postId, description, targetId, typeId) { const post = await this.postRepository.getById(id); if (!post) throw new ApiError(httpStatus.NOT_FOUND, 'Post not found.'); - return this.postRepository.update(id, description, target_id, type_id); + return this.postRepository.update(postId, description, targetId, typeId); }; - async deletePost(id) { - const post = await this.postRepository.getById(id); + async deletePost(postId) { + const post = await this.postRepository.getById(postId); if (!post) throw new ApiError(httpStatus.NOT_FOUND, 'Post not found.'); - await this.postRepository.delete(id); + await this.postRepository.delete(postId); }; } diff --git a/src/services/reactionService.js b/src/services/reactionService.js index 857125c..1038dd1 100644 --- a/src/services/reactionService.js +++ b/src/services/reactionService.js @@ -4,27 +4,27 @@ const httpStatus = require("../utils/statusCodes"); class ReactionService { constructor(reactionRepository) { this.reactionRepository = reactionRepository; - } - async createReaction(userId, reaction_type_id, post_id) { - return this.reactionRepository.create(userId, reaction_type_id, post_id); + }; + createReaction(userId, reactionTypeId, postId) { + return this.reactionRepository.create(userId, reactionTypeId, postId); }; async getReactionById(id) { const reaction = await this.reactionRepository.getById(id); if (!reaction) throw new ApiError(httpStatus.NOT_FOUND,'Reaction not found'); return reaction; }; - async getAllReactions(userId) { + getAllReactions(userId) { return this.reactionRepository.getAll(userId); }; - async updateReaction(id, user_id, reaction_type_id, post_id) { + async updateReaction(id, userId, reactionId, postId) { const reaction = await this.reactionRepository.getById(id); if (!reaction) throw new ApiError(httpStatus.NOT_FOUND,'Reaction not found'); - return this.reactionRepository.update(id, user_id, reaction_type_id, post_id); + return this.reactionRepository.update(id, userId, reactionId, postId); }; - async deleteReaction(id) { - const reaction = await this.reactionRepository.getById(id); + async deleteReaction(reactionId) { + const reaction = await this.reactionRepository.getById(reactionId); if (!reaction) throw new ApiError(httpStatus.NOT_FOUND,'Reaction not found'); - await this.reactionRepository.delete(id); + await this.reactionRepository.delete(reactionId); }; } diff --git a/src/services/reactionTypeService.js b/src/services/reactionTypeService.js index 9bc3f86..4d025e8 100644 --- a/src/services/reactionTypeService.js +++ b/src/services/reactionTypeService.js @@ -5,16 +5,16 @@ class ReactionTypeService { constructor(reactionTypeRepository) { this.reactionTypeRepository = reactionTypeRepository; } - async createReactionType(description) { + createReactionType(description) { return this.reactionTypeRepository.create(description); }; - async getAllReactionsType() { + getAllReactionsType() { return this.reactionTypeRepository.getAll(); }; - async deleteReactionType(id) { - const reactionsType = await this.reactionTypeRepository.getById(id); + async deleteReactionType(reactionTypeId) { + const reactionsType = await this.reactionTypeRepository.getById(reactionTypeId); if (!reactionsType) throw new ApiError(httpStatus.NOT_FOUND, 'Reaction type not found'); - await this.reactionTypeRepository.delete(id); + await this.reactionTypeRepository.delete(reactionTypeId); }; } diff --git a/src/services/targetPublicService.js b/src/services/targetPublicService.js index 1ca426d..5b32b10 100644 --- a/src/services/targetPublicService.js +++ b/src/services/targetPublicService.js @@ -4,21 +4,22 @@ const httpStatus = require("../utils/statusCodes"); class TargetPublicService { constructor(targetPublicRepository) { this.targetPublicRepository = targetPublicRepository; - } - async createTargetPublic(type) { - return this.targetPublicRepository.create(type); }; - async getAllTargetPublic() { + createTargetPublic(newTargetPublicType) { + return this.targetPublicRepository.create(newTargetPublicType); + }; + getAllTargetPublic() { return this.targetPublicRepository.getAll(); }; - async getById(id){ - const targetPublic = await this.targetPublicRepository.getById(id); + async getById(targetPublicId){ + const targetPublic = await this.targetPublicRepository.getById(targetPublicId); if (!targetPublic) throw new ApiError(httpStatus.NOT_FOUND, 'Target public not found.'); return targetPublic; }; - async deleteTargetPublic(id) { - await this.getById(id); - await this.targetPublicRepository.delete(id); + async deleteTargetPublic(targetPublicId) { + const targetPublic = await this.targetPublicRepository.getById(targetPublicId); + if (!targetPublic) throw new ApiError(httpStatus.NOT_FOUND, 'Target public not found.'); + await this.targetPublicRepository.delete(targetPublicId); }; } diff --git a/src/services/tokenService.js b/src/services/tokenService.js index 9afe038..a6efa89 100644 --- a/src/services/tokenService.js +++ b/src/services/tokenService.js @@ -6,7 +6,7 @@ class TokenService { constructor(tokenRepository, hashService) { this.tokenRepository = tokenRepository; this.hashService = hashService; - } + }; async generateAuthTokens(user) { const payload = {id: user}; const token = await this.generateToken(payload, process.env.JWT_SECRET, '2h'); diff --git a/src/services/userServices.js b/src/services/userServices.js index d333418..ec1f265 100644 --- a/src/services/userServices.js +++ b/src/services/userServices.js @@ -5,12 +5,12 @@ class UserService { constructor(userRepository, hashService) { this.userRepository = userRepository; this.hashService = hashService; - } - async create(full_name, email, password) { + }; + async create(fullName, email, password) { const isEmailTaken = await this.userRepository.getByEmail(email); if (isEmailTaken) throw new ApiError(httpStatus.CONFLICT,'Email already taken'); const hashedPassword = await this.hashService.hash(password); - this.userRepository.create(full_name, email, hashedPassword); + return this.userRepository.create(fullName, email, hashedPassword); }; async getUserById(id) { const user = await this.userRepository.getById(id); diff --git a/src/utils/targetPublicStatus.js b/src/utils/targetPublicStatus.js new file mode 100644 index 0000000..d508f9b --- /dev/null +++ b/src/utils/targetPublicStatus.js @@ -0,0 +1,7 @@ +module.exports = { + PUBLIC: 1, + FRIENDS: 2, + FRIENDS_EXCEPT: 3, + ONLY_ME: 4, + CUSTOM: 5, +} \ No newline at end of file diff --git a/tests/integration/album.test.js b/tests/integration/album.test.js index e798e12..a1db50c 100644 --- a/tests/integration/album.test.js +++ b/tests/integration/album.test.js @@ -9,24 +9,24 @@ describe('Testing album feature', () => { let loginResponse; beforeAll(async () => { await db('user').insert({ - id: 100, + id: 99876, full_name: 'Tadeu Smith', - email: 'tadeusmit@gmail.com', + email: 'taa@gmail.com', password: '$2b$10$OMDQ.q5dkZAZkQH1g5W6IOP4ZLCwBV4xnTCHDng2pNhlWOpq/n5xO', created_at: new Date(), updated_at: new Date(), is_active: true }); - tempUser = await db('user').where({ id: 100 }).first(); + tempUser = await db('user').where({ id: 99876 }).first(); loginResponse = await request(app).post('/login').send({"email": tempUser.email, "password": "1234"}); await db(`album`).insert({ - id: 1000, + id: 55432, description: "Test Album", target_id: 1, is_active: true }) - tempAlbum = await db('album').where({ id: 1000 }).first(); + tempAlbum = await db('album').where({ id: 55432 }).first(); }); afterAll(async () => { await db('token').where({ user_id: tempUser.id }).del(); @@ -42,7 +42,7 @@ describe('Testing album feature', () => { }); it('Should return an album by id', async () => { const { token } = loginResponse.body; - const album = await request(app).get('/album/1000').set('Authorization', token); + const album = await request(app).get('/album/55432').set('Authorization', token); expect(album.status).toBe(httpStatus.OK); expect(album.body).toBeDefined(); }); @@ -56,12 +56,12 @@ describe('Testing album feature', () => { }); it('Should delete an album', async () => { const { token } = loginResponse.body; - const album = await request(app).delete('/album/1000').set('Authorization', token); + const album = await request(app).delete('/album/55432').set('Authorization', token); expect(album.status).toBe(httpStatus.OK); }); it('Should return a not found if trying to delete an album with non-existent id', async () => { const { token } = loginResponse.body; - const album = await request(app).delete('/album/100000').set('Authorization', token); + const album = await request(app).delete('/album/90908765').set('Authorization', token); expect(album.status).toBe(httpStatus.NOT_FOUND); }); }); diff --git a/tests/integration/comment.test.js b/tests/integration/comment.test.js index 8852adc..d2e620b 100644 --- a/tests/integration/comment.test.js +++ b/tests/integration/comment.test.js @@ -9,12 +9,12 @@ describe('Testing comment feature', () => { let tempPost; let loginResponse; let bodyComment; - let bodyCreateComment; + let createdComment; let token; beforeAll(async () => { await db('user').insert({ - id: 100, + id: 554678, full_name: 'Luiz Cruz', email: 'luizcruzdev@gmail.com', password: '$2b$10$OMDQ.q5dkZAZkQH1g5W6IOP4ZLCwBV4xnTCHDng2pNhlWOpq/n5xO', @@ -22,9 +22,9 @@ describe('Testing comment feature', () => { updated_at: new Date(), is_active: true }); - tempUser = await db('user').where({ id: 100 }).first(); + tempUser = await db('user').where({ id: 554678 }).first(); await db('post').insert({ - id: 1000, + id: 45326, description: "Test Post", user_id: tempUser.id, target_id: targetPublicStatus.PUBLIC, @@ -33,7 +33,7 @@ describe('Testing comment feature', () => { updated_at: new Date(), is_active: true }); - tempPost = await db('post').where({ id: 1000 }).first(); + tempPost = await db('post').where({ id: 45326 }).first(); loginResponse = await request(app).post('/login').send({ email: tempUser.email, password: "1234" }); token = loginResponse.body.token; [bodyComment] = await db('comment').insert( @@ -43,34 +43,34 @@ describe('Testing comment feature', () => { user_id: tempUser.id, post_id: tempPost.id }); - bodyCreateComment = await db('comment').where({ id: 200 }).first(); + createdComment = await db('comment').where({ id: 200 }).first(); }); afterAll(async () => { - await db('token').where({ user_id: 100 }).del(); + await db('token').where({ user_id: 554678 }).del(); await db('comment').where({ id: 200 }).del(); - await db('post').where({ id: 1000 }).del(); - await db('user').where({ id: 100 }).del(); + await db('post').where({ id: 45326 }).del(); + await db('user').where({ id: 554678 }).del(); }); it('Should create a comment when authorized with valid token', async () => { const { token } = loginResponse.body; - const response = await request(app).post('/comment').send(bodyCreateComment).set('Authorization', token); + const response = await request(app).post('/comments').send({post_id: tempPost.id, description: "Woow"}).set('Authorization', token); expect(response.status).toBe(httpStatus.CREATED); expect(response.body.data).toBeDefined(); }); it('Should return a bad request if trying to create a comment with missing fields', async () => { const { token } = loginResponse.body; - const response = await request(app).post('/comment').send({}).set('Authorization', token); + const response = await request(app).post('/comments').send({}).set('Authorization', token); expect(response.status).toBe(httpStatus.BAD_REQUEST); }); it('Should get a comment by id when authorized with valid token', async () => { const { token } = loginResponse.body; - const response = await request(app).get(`/comment/${tempCommentId}`).set('Authorization', token); + const response = await request(app).get(`/comments/${createdComment.id}`).set('Authorization', token); expect(response.status).toBe(httpStatus.OK); expect(response.body).toBeDefined(); }); it('Should get all comments when authorized with valid token', async () => { const { token } = loginResponse.body; - const response = await request(app).get('/comment').set('Authorization', token); + const response = await request(app).get('/comments').set('Authorization', token); expect(response.status).toBe(httpStatus.OK); expect(response.body).toBeDefined(); }); @@ -78,13 +78,13 @@ describe('Testing comment feature', () => { const updatedCommentData = { description: 'This is an updated test comment' }; - const response = await request(app).put(`/comment/${tempCommentId}`).send(updatedCommentData).set('Authorization', token); + const response = await request(app).put(`/comments/${createdComment.id}`).send(updatedCommentData).set('Authorization', token); expect(response.status).toBe(httpStatus.OK); expect(response.body.details).toBe('Comment updated successfully'); }); it('Should delete a comment when authorized with valid token', async () => { const { token } = loginResponse.body; - const response = await request(app).delete(`/comment/${tempCommentId}`).set('Authorization', token); + const response = await request(app).delete(`/comments/${createdComment.id}`).set('Authorization', token); expect(response.status).toBe(httpStatus.OK); expect(response.body.details).toBe('Comment deleted successfully'); }); diff --git a/tests/integration/friendshipRequest.test.js b/tests/integration/friendshipRequest.test.js index 284ff54..2b1d69c 100644 --- a/tests/integration/friendshipRequest.test.js +++ b/tests/integration/friendshipRequest.test.js @@ -7,10 +7,9 @@ describe('Testing FriendshipRequest feature', () => { let loggedUser; let receiverFriendshipRequestUser; let loginResponse; - let tempUser; beforeAll(async () => { await db('user').insert({ - id: 10000, + id: 12345678, full_name: 'Sender', email: 'sender@gmail.com', password: '$2b$10$OMDQ.q5dkZAZkQH1g5W6IOP4ZLCwBV4xnTCHDng2pNhlWOpq/n5xO', @@ -18,7 +17,7 @@ describe('Testing FriendshipRequest feature', () => { updated_at: new Date(), is_active: true }); - loggedUser = await db('user').where({ id: 10000 }).first(); + loggedUser = await db('user').where({ id: 12345678 }).first(); loginResponse = await request(app).post('/login').send({"email": loggedUser.email, "password": "1234"}); await db('user').insert({ id: 20000, @@ -79,7 +78,7 @@ describe('Testing FriendshipRequest feature', () => { const senderUserId = receiverFriendshipRequestUser.id const { token } = loginResponse.body; await db('friendship_request').insert({ - id: 22222, + id: 67893, sender_id: senderUserId, receiver_id: loggedUser.id, request_type_id: 1, @@ -87,7 +86,7 @@ describe('Testing FriendshipRequest feature', () => { updated_at: new Date() }); const response = await request(app) - .delete('/friendship_request/22222') + .delete('/friendship_request/67893') .set('authorization', token); expect(response.status).toBe(httpStatus.OK); expect(response.body).toBeDefined(); diff --git a/tests/integration/reaction.test.js b/tests/integration/reaction.test.js index 5f15760..f243bcc 100644 --- a/tests/integration/reaction.test.js +++ b/tests/integration/reaction.test.js @@ -13,7 +13,7 @@ describe('Testing Reaction feature', () => { beforeAll(async () => { // Criar usuário de teste await db('user').insert({ - id: 10000, + id: 8080, full_name: 'Test User', email: 'testuser@gmail.com', password: '$2b$10$OMDQ.q5dkZAZkQH1g5W6IOP4ZLCwBV4xnTCHDng2pNhlWOpq/n5xO', @@ -21,7 +21,7 @@ describe('Testing Reaction feature', () => { updated_at: new Date(), is_active: true }); - loggedUser = await db('user').where({ id: 10000 }).first(); + loggedUser = await db('user').where({ id: 8080 }).first(); loginResponse = await request(app).post('/login').send({"email": loggedUser.email, "password": "1234"}); await db('user').insert({ id: 99999, diff --git a/tests/integration/user.test.js b/tests/integration/user.test.js index c21ef83..8981da9 100644 --- a/tests/integration/user.test.js +++ b/tests/integration/user.test.js @@ -11,7 +11,7 @@ describe('Testing user feature', () => { await db('user').insert({ id: 10000, full_name: 'Tadeu Smith', - email: 'tadeusmit@gmail.com', + email: 'tads@gmail.com', password: '$2b$10$OMDQ.q5dkZAZkQH1g5W6IOP4ZLCwBV4xnTCHDng2pNhlWOpq/n5xO', created_at: new Date(), updated_at: new Date(), diff --git a/tests/restart.sql b/tests/restart.sql new file mode 100644 index 0000000..710265e --- /dev/null +++ b/tests/restart.sql @@ -0,0 +1,4 @@ +SET FOREIGN_KEY_CHECKS = 0; +DROP DATABASE social_network; +SET FOREIGN_KEY_CHECKS = 1; +CREATE DATABASE IF NOT EXISTS `social_network`; diff --git a/tests/service/commentService.test.js b/tests/service/commentService.test.js index d8f577e..c39a4e3 100644 --- a/tests/service/commentService.test.js +++ b/tests/service/commentService.test.js @@ -80,14 +80,14 @@ describe('CommentsService', () => { }); }); describe('updateComment', () => { - it('should update an existing comment', async () => { + it('should update an existing comment by ID', async () => { const updatedDescription = "Andando por New York"; const updatedUserId = 2; const updatedPostId = 3; mockRepository.getById.mockResolvedValueOnce({ id: commentId }); await commentsService.updateComment(commentId, updatedDescription, updatedUserId, updatedPostId); expect(mockRepository.getById).toHaveBeenCalledWith(commentId); - expect(mockRepository.update).toHaveBeenCalledWith(commentId, updatedDescription, updatedUserId, updatedPostId); + expect(mockRepository.update).toHaveBeenCalledWith(commentId, updatedDescription); }); it('should throw an error when trying to update a non-existing comment', async () => { mockRepository.getById.mockResolvedValueOnce(null); diff --git a/txt.txt b/txt.txt deleted file mode 100644 index ca31140..0000000 --- a/txt.txt +++ /dev/null @@ -1,12 +0,0 @@ -reaction - ok -comment - ok -post - ok -targetPublic - ok -reactionType -ok -fileType - ok -friendshipRequestType - ok -user - ok -albumItem - ok -friendship - ok -friendshipRequest - ok -album - \ No newline at end of file