Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .env.example
Empty file.
12 changes: 11 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
22 changes: 11 additions & 11 deletions src/controller/albumController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
});
Expand Down
13 changes: 7 additions & 6 deletions src/controller/albumItemController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,28 @@ 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
});
}
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;
30 changes: 15 additions & 15 deletions src/controller/commentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion src/controller/friendshipRequestController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/controller/friendshipRequestTypeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/controller/postController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/controller/reactionController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
});
Expand Down
2 changes: 1 addition & 1 deletion src/controller/targetPublicController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 7 additions & 7 deletions src/controller/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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"
});
Expand Down
6 changes: 3 additions & 3 deletions src/features/albumContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/features/albumItemContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/features/commentContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/features/fileTypeContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/features/friendshipContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/features/friendshipRequestContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/features/friendshipRequestTypeContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading