From e1a790a87f2188931fe84f59c948d2273ca13513 Mon Sep 17 00:00:00 2001 From: Luiz Cruz Date: Thu, 20 Jun 2024 23:44:49 -0300 Subject: [PATCH 01/13] refactor targetID variable --- src/controller/albumController.js | 4 ++-- src/repositories/albumRepository.js | 4 ++-- .../implementation/albumRepositoryImplementation.js | 8 ++++---- src/services/albumService.js | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/controller/albumController.js b/src/controller/albumController.js index f137c6d..7ad5c00 100644 --- a/src/controller/albumController.js +++ b/src/controller/albumController.js @@ -6,8 +6,8 @@ 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 diff --git a/src/repositories/albumRepository.js b/src/repositories/albumRepository.js index 4032076..5927343 100644 --- a/src/repositories/albumRepository.js +++ b/src/repositories/albumRepository.js @@ -5,8 +5,8 @@ class AlbumRepository { assertIsInstanceOfContract(repository, contract); this.repository = repository; } - async create(description, target_id) { - return this.repository.create(description, target_id); + async create(description, targetId) { + return this.repository.create(description, targetId); }; async getById(id){ return this.repository.getById(id); diff --git a/src/repositories/implementation/albumRepositoryImplementation.js b/src/repositories/implementation/albumRepositoryImplementation.js index 906cbdc..0ba2834 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 diff --git a/src/services/albumService.js b/src/services/albumService.js index b9feda2..6bfc461 100644 --- a/src/services/albumService.js +++ b/src/services/albumService.js @@ -5,8 +5,8 @@ class AlbumService { constructor(albumRepository) { this.albumRepository = albumRepository; } - async createAlbum(description, target_id) { - return this.albumRepository.create(description, target_id); + createAlbum(description, targetId) { + return this.albumRepository.create(description, targetId); }; async getAlbumById(id) { const album = await this.albumRepository.getById(id); From 07136e5831570d6442ef31e9cddd7282cfada43f Mon Sep 17 00:00:00 2001 From: Luiz Cruz Date: Thu, 20 Jun 2024 23:49:04 -0300 Subject: [PATCH 02/13] refactor albumId variable --- src/controller/albumController.js | 4 ++-- src/middlewares/albumValidation.js | 8 ++++---- .../implementation/albumItemRepositoryImplementation.js | 4 ++-- src/services/albumService.js | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/controller/albumController.js b/src/controller/albumController.js index 7ad5c00..0ce4a70 100644 --- a/src/controller/albumController.js +++ b/src/controller/albumController.js @@ -14,10 +14,10 @@ class AlbumController { }); } async getAlbumById(req, res) { - const { id } = req.params; + const { 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) { diff --git a/src/middlewares/albumValidation.js b/src/middlewares/albumValidation.js index 947066d..0414334 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 { albumId } = req.params; await schema.validate({ - id, + albumId, authorization, description, - target_id + targetId }) next(); } catch (error) { diff --git a/src/repositories/implementation/albumItemRepositoryImplementation.js b/src/repositories/implementation/albumItemRepositoryImplementation.js index 455bca6..7193d28 100644 --- a/src/repositories/implementation/albumItemRepositoryImplementation.js +++ b/src/repositories/implementation/albumItemRepositoryImplementation.js @@ -23,9 +23,9 @@ class AlbumItemRepositoryImplementation extends IAlbumItemRepository { } } - async getById(id) { + getById(albumId) { return db('Album_Item') - .where({ id: id }) + .where({ id: albumId }) .select(['id', 'post_id', 'album_id', 'is_active']) .first(); } diff --git a/src/services/albumService.js b/src/services/albumService.js index 6bfc461..16fa6cf 100644 --- a/src/services/albumService.js +++ b/src/services/albumService.js @@ -8,8 +8,8 @@ class AlbumService { createAlbum(description, targetId) { return this.albumRepository.create(description, targetId); }; - async getAlbumById(id) { - const album = await this.albumRepository.getById(id); + async getAlbumById(albumId) { + const album = await this.albumRepository.getById(albumId); if (!album) throw new ApiError(httpStatus.NOT_FOUND, 'Album not found!'); return album; }; From 8965c137f64c7c046bb42fbfba53c99bdc812bc7 Mon Sep 17 00:00:00 2001 From: Luiz Cruz Date: Thu, 20 Jun 2024 23:51:40 -0300 Subject: [PATCH 03/13] refactor albumId, targetId of middleware schema and validation --- src/schemas/albumSchema.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/schemas/albumSchema.js b/src/schemas/albumSchema.js index de283e2..553a8a8 100644 --- a/src/schemas/albumSchema.js +++ b/src/schemas/albumSchema.js @@ -2,17 +2,17 @@ const yup = require('yup'); const createAlbumSchema = yup.object({ description: yup.string().required(), - target_id: yup.number().integer().required() + targetId: yup.number().integer().required() }); const updateAlbumSchema = yup.object({ - id: yup.number().integer().required(), + albumId: yup.number().integer().required(), description: yup.string().required(), - target_id: yup.number().integer().required() + targetId: yup.number().integer().required() }); const getByIdSchema = yup.object({ - id: yup.number().integer().required() + albumId: yup.number().integer().required() }); const authorizationSchema = yup.object().shape({ From 73e2697fa8884011a7467620a5f95a316ea02c6d Mon Sep 17 00:00:00 2001 From: Luiz Cruz Date: Thu, 20 Jun 2024 23:53:34 -0300 Subject: [PATCH 04/13] refactor function definitions --- .../implementation/albumRepositoryImplementation.js | 4 ++-- src/services/albumService.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/repositories/implementation/albumRepositoryImplementation.js b/src/repositories/implementation/albumRepositoryImplementation.js index 0ba2834..5f633ac 100644 --- a/src/repositories/implementation/albumRepositoryImplementation.js +++ b/src/repositories/implementation/albumRepositoryImplementation.js @@ -18,13 +18,13 @@ class AlbumRepositoryImplementation extends IAlbumRepository{ throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR,'Error while creating a new album'); } }; - async getById(id){ + getById(id){ return db('album') .where({ id }) .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'); diff --git a/src/services/albumService.js b/src/services/albumService.js index 16fa6cf..8a2026f 100644 --- a/src/services/albumService.js +++ b/src/services/albumService.js @@ -13,7 +13,7 @@ class AlbumService { 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) { From 066e6185e37652a3aae49887f3a68b17e28bcf96 Mon Sep 17 00:00:00 2001 From: Luiz Cruz Date: Thu, 20 Jun 2024 23:54:45 -0300 Subject: [PATCH 05/13] refactor id and targetID variable --- .../implementation/albumRepositoryImplementation.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/repositories/implementation/albumRepositoryImplementation.js b/src/repositories/implementation/albumRepositoryImplementation.js index 5f633ac..7a6a1e8 100644 --- a/src/repositories/implementation/albumRepositoryImplementation.js +++ b/src/repositories/implementation/albumRepositoryImplementation.js @@ -29,13 +29,13 @@ class AlbumRepositoryImplementation extends IAlbumRepository{ .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); }); From da4d9ee50acbba50a2e879d6ca35a89ef61fefae Mon Sep 17 00:00:00 2001 From: Luiz Cruz Date: Thu, 20 Jun 2024 23:56:13 -0300 Subject: [PATCH 06/13] refactor id and targetID variable --- .../implementation/albumRepositoryImplementation.js | 8 ++++---- src/services/albumService.js | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/repositories/implementation/albumRepositoryImplementation.js b/src/repositories/implementation/albumRepositoryImplementation.js index 7a6a1e8..8f07cc4 100644 --- a/src/repositories/implementation/albumRepositoryImplementation.js +++ b/src/repositories/implementation/albumRepositoryImplementation.js @@ -18,9 +18,9 @@ class AlbumRepositoryImplementation extends IAlbumRepository{ throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR,'Error while creating a new album'); } }; - getById(id){ + getById(albumId){ return db('album') - .where({ id }) + .where({ id: albumId }) .select('id', 'description', 'target_id', 'is_active') .first(); }; @@ -43,11 +43,11 @@ 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/services/albumService.js b/src/services/albumService.js index 8a2026f..2dffe26 100644 --- a/src/services/albumService.js +++ b/src/services/albumService.js @@ -21,10 +21,10 @@ class AlbumService { if (!album) throw new ApiError(httpStatus.NOT_FOUND, 'Album not found!'); await this.albumRepository.update(id, description, target_id); }; - 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); }; } From d47c5fa00abcc0f8d0c7d4771539be5e6a46ac44 Mon Sep 17 00:00:00 2001 From: Luiz Cruz Date: Thu, 20 Jun 2024 23:56:54 -0300 Subject: [PATCH 07/13] refactor id and targetID variable --- src/repositories/albumRepository.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/repositories/albumRepository.js b/src/repositories/albumRepository.js index 5927343..a5cbb6c 100644 --- a/src/repositories/albumRepository.js +++ b/src/repositories/albumRepository.js @@ -8,17 +8,17 @@ class AlbumRepository { async create(description, targetId) { return this.repository.create(description, targetId); }; - async getById(id){ - return this.repository.getById(id); + async getById(albumId){ + return this.repository.getById(albumId); }; async getAll(albumId){ return this.repository.getAll(albumId); }; - async update(id, description, target_id) { - this.repository.update(id, description, target_id); + async update(albumId, description, targetId) { + this.repository.update(albumId, description, targetId); }; - async delete (id) { - this.repository.delete(id); + async delete (albumId) { + this.repository.delete(albumId); }; } From 14bb1cd766f7fb2b1fcaf8cf1b42e3c9d8d216b5 Mon Sep 17 00:00:00 2001 From: Luiz Cruz Date: Fri, 21 Jun 2024 00:00:06 -0300 Subject: [PATCH 08/13] refactor id and albumItemId declarations --- src/controller/albumItemController.js | 4 ++-- src/repositories/albumItemRepository.js | 16 ++++++++-------- .../albumItemRepositoryImplementation.js | 12 ++++++------ src/services/albumItemService.js | 14 +++++++------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/controller/albumItemController.js b/src/controller/albumItemController.js index 7fc3898..70cc85b 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: albumId } = req.body; + const albumItem = await this.albumItemService.createAlbumItem(postId, albumId); return res.status(httpStatus.CREATED).json({ message: 'Album item created successfully!', data: albumItem diff --git a/src/repositories/albumItemRepository.js b/src/repositories/albumItemRepository.js index 751764a..d9ddf0d 100644 --- a/src/repositories/albumItemRepository.js +++ b/src/repositories/albumItemRepository.js @@ -5,17 +5,17 @@ class AlbumItemRepository { assertIsInstanceOfContract(repository, contract); this.repository = repository; } - async create(post_id, album_id) { - return this.repository.create(post_id, album_id); + async create(postId, albumItemId) { + return this.repository.create(postId, albumItemId); }; - async getById(id){ - return this.repository.getById(id); + async getById(albumItemId){ + return this.repository.getById(albumItemId); }; - async getAll(AlbumId){ - return this.repository.getAll(AlbumId); + async getAll(albumItemId){ + return this.repository.getAll(albumItemId); }; - async delete (id) { - this.repository.delete(id); + async delete (albumItemId) { + this.repository.delete(albumItemId); }; } diff --git a/src/repositories/implementation/albumItemRepositoryImplementation.js b/src/repositories/implementation/albumItemRepositoryImplementation.js index 7193d28..151405e 100644 --- a/src/repositories/implementation/albumItemRepositoryImplementation.js +++ b/src/repositories/implementation/albumItemRepositoryImplementation.js @@ -23,25 +23,25 @@ class AlbumItemRepositoryImplementation extends IAlbumItemRepository { } } - getById(albumId) { + getById(albumItemId) { return db('Album_Item') - .where({ id: albumId }) + .where({ id: albumItemId }) .select(['id', 'post_id', 'album_id', 'is_active']) .first(); } - 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/services/albumItemService.js b/src/services/albumItemService.js index 66dcf50..f6b46c3 100644 --- a/src/services/albumItemService.js +++ b/src/services/albumItemService.js @@ -5,16 +5,16 @@ class AlbumItemService { constructor(albumItemRepository) { this.albumItemRepository = albumItemRepository; } - async createAlbumItem(post_id, album_id) { - return this.albumItemRepository.create(post_id, album_id); + async createAlbumItem(postId, albumItemId) { + return this.albumItemRepository.create(postId, albumItemId); }; - async getAllAlbumItem(albumId) { - return this.albumItemRepository.getAll(albumId); + async getAllAlbumItem(albumItemId) { + return this.albumItemRepository.getAll(albumItemId); }; - async deleteAlbumItem(id) { - const albumItem = await this.albumItemRepository.getById(id); + async deleteAlbumItem(albumItemId) { + const albumItem = await this.albumItemRepository.getById(albumId); if (!albumItem) throw new ApiError(httpStatus.NOT_FOUND, 'Album item not found'); - await this.albumItemRepository.delete(id); + await this.albumItemRepository.delete(albumItemId); }; } From 1f6bfb13f251733379c40db740eafad5f0aeed3d Mon Sep 17 00:00:00 2001 From: Luiz Cruz Date: Fri, 21 Jun 2024 00:00:23 -0300 Subject: [PATCH 09/13] refactor id and albumItemId declarations --- .../implementation/albumItemRepositoryImplementation.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/repositories/implementation/albumItemRepositoryImplementation.js b/src/repositories/implementation/albumItemRepositoryImplementation.js index 151405e..79973d8 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); From 357f14d1f21dc9363777c8c4a08f5dd5b47f3468 Mon Sep 17 00:00:00 2001 From: Luiz Cruz Date: Tue, 23 Jul 2024 22:08:04 -0300 Subject: [PATCH 10/13] Enhance code style, parameters and arguments --- .env.example | 0 package-lock.json | 12 ++++- package.json | 5 +- src/controller/albumController.js | 4 +- src/controller/albumItemController.js | 13 ++--- src/controller/commentController.js | 8 +-- src/controller/postController.js | 4 +- src/controller/reactionController.js | 8 +-- src/controller/targetPublicController.js | 2 +- src/controller/userController.js | 8 +-- src/features/albumContainer.js | 6 +-- src/features/albumItemContainer.js | 4 +- src/features/commentContainer.js | 4 +- src/features/fileTypeContainer.js | 2 +- src/features/friendshipContainer.js | 4 +- src/features/friendshipRequestContainer.js | 6 +-- .../friendshipRequestTypeContainer.js | 2 +- src/features/postContainer.js | 4 +- src/features/reactionContainer.js | 4 +- src/features/reactionTypeContainer.js | 4 +- src/features/targetPublicContainer.js | 4 +- src/features/userContainer.js | 4 +- src/middlewares/albumItemValidation.js | 6 +-- src/middlewares/commentsValidation.js | 4 +- src/middlewares/error.js | 1 + src/middlewares/fileTypeValidation.js | 1 + .../friendshipRequestTypeValidation.js | 2 +- .../friendshipRequestValidation.js | 6 +-- src/middlewares/postValidation.js | 6 +-- src/middlewares/reactionValidation.js | 6 +-- src/middlewares/userValidation.js | 4 +- src/repositories/albumItemRepository.js | 10 ++-- src/repositories/albumRepository.js | 12 ++--- src/repositories/commentRepository.js | 20 ++++---- src/repositories/fileTypeRepository.js | 16 +++--- src/repositories/friendshipRepository.js | 16 +++--- .../friendshipRequestRepository.js | 32 ++++++------ .../friendshipRequestTypeRepository.js | 24 ++++----- .../albumRepositoryImplementation.js | 4 ++ .../commentRepositoryImplementation.js | 8 +-- .../fileTypeRepositoryImplementation.js | 14 ++--- .../friendshipRepositoryImplementation.js | 6 +-- .../friendshipRequestRepository.js | 18 +++---- .../friendshipRequestTypeRepository.js | 33 ++++++------ .../postRepositoryImplementation.js | 22 ++++---- .../reactionRepositoryImplementation.js | 8 +-- .../reactionTypeRepositoryImplementation.js | 6 +-- .../targetPublicRepositoryImplementation.js | 12 ++--- .../tokenRepositoryImplementation.js | 51 ++++++++++--------- .../userRepositoryImplementation.js | 51 +++++++++---------- src/repositories/postRepository.js | 20 ++++---- src/repositories/reactionRepository.js | 18 +++---- src/repositories/reactionTypeRepository.js | 14 ++--- src/repositories/targetPublicRepository.js | 12 ++--- src/repositories/tokenRepository.js | 18 +++---- src/repositories/userRepository.js | 22 ++++---- src/routes/targetPublicRoutes.js | 2 +- src/schemas/commentsSchema.js | 2 +- src/schemas/fileTypeSchema.js | 1 - src/schemas/friendshipSchema.js | 2 +- src/schemas/idSchema.js | 1 + src/schemas/postSchema.js | 2 +- src/schemas/reactionsSchema.js | 1 + src/schemas/userSchema.js | 3 +- src/services/albumItemService.js | 8 +-- src/services/albumService.js | 8 +-- src/services/authService.js | 2 +- src/services/commentService.js | 24 ++++----- src/services/cryptoService.js | 7 ++- src/services/fileTypeService.js | 10 ++-- src/services/friendshipRequestService.js | 18 +++---- src/services/friendshipRequestTypeService.js | 29 ++++++----- src/services/friendshipServices.js | 19 +++---- src/services/postService.js | 18 +++---- src/services/reactionService.js | 18 +++---- src/services/reactionTypeService.js | 10 ++-- src/services/targetPublicService.js | 19 +++---- src/services/tokenService.js | 2 +- src/services/userServices.js | 6 +-- txt.txt | 12 ----- 80 files changed, 423 insertions(+), 416 deletions(-) create mode 100644 .env.example delete mode 100644 txt.txt 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..09676fc 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "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 0ce4a70..8ac2a24 100644 --- a/src/controller/albumController.js +++ b/src/controller/albumController.js @@ -30,8 +30,8 @@ class AlbumController { const { id } = 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(id, description, targetId); return res.status(httpStatus.OK).json({ details: "Album updated successfully" }); diff --git a/src/controller/albumItemController.js b/src/controller/albumItemController.js index 70cc85b..345c027 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: postId, album_id: albumId } = req.body; - const albumItem = await this.albumItemService.createAlbumItem(postId, albumId); + 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 { album_item_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..cce48d5 100644 --- a/src/controller/commentController.js +++ b/src/controller/commentController.js @@ -8,8 +8,8 @@ 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 { description, user_id: userId, 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 @@ -32,8 +32,8 @@ class CommentController { 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 { description, user_id: userId, post_id: postId } = req.body; + await this.commentService.updateComment(id, description, userId, postId); return res.status(httpStatus.OK).json({ details: "Comment updated successfully" }); 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..d60afc7 100644 --- a/src/controller/userController.js +++ b/src/controller/userController.js @@ -8,8 +8,8 @@ class UserController { 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 @@ -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..f524ea4 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 + postId, + albumId }) next(); } catch (error) { diff --git a/src/middlewares/commentsValidation.js b/src/middlewares/commentsValidation.js index ce67a17..3df59da 100644 --- a/src/middlewares/commentsValidation.js +++ b/src/middlewares/commentsValidation.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, user_id, post_id } = req.body; + const { description, user_id: userId, post_id: postId } = req.body; const { id } = req.params; const { authorization } = req.headers; await schema.validate({ id, authorization, description, - user_id, + userId, post_id }) next(); 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..e29b579 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 + senderId, + receiverId }) next(); } catch (error) { diff --git a/src/middlewares/postValidation.js b/src/middlewares/postValidation.js index 48bb9c4..c8a336b 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 + targetId, + typeId }) next(); } catch (error) { diff --git a/src/middlewares/reactionValidation.js b/src/middlewares/reactionValidation.js index 5f2f18b..b991fb5 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 + reactionTypeId, + 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 d9ddf0d..354efbe 100644 --- a/src/repositories/albumItemRepository.js +++ b/src/repositories/albumItemRepository.js @@ -4,17 +4,17 @@ class AlbumItemRepository { constructor(repository, contract) { assertIsInstanceOfContract(repository, contract); this.repository = repository; - } - async create(postId, albumItemId) { + }; + create(postId, albumItemId) { return this.repository.create(postId, albumItemId); }; - async getById(albumItemId){ + getById(albumItemId){ return this.repository.getById(albumItemId); }; - async getAll(albumItemId){ + getAll(albumItemId){ return this.repository.getAll(albumItemId); }; - async delete (albumItemId) { + delete (albumItemId) { this.repository.delete(albumItemId); }; } diff --git a/src/repositories/albumRepository.js b/src/repositories/albumRepository.js index a5cbb6c..a896778 100644 --- a/src/repositories/albumRepository.js +++ b/src/repositories/albumRepository.js @@ -4,20 +4,20 @@ class AlbumRepository { constructor(repository, contract) { assertIsInstanceOfContract(repository, contract); this.repository = repository; - } - async create(description, targetId) { + }; + create(description, targetId) { return this.repository.create(description, targetId); }; - async getById(albumId){ + getById(albumId){ return this.repository.getById(albumId); }; - async getAll(albumId){ + getAll(albumId){ return this.repository.getAll(albumId); }; - async update(albumId, description, targetId) { + update(albumId, description, targetId) { this.repository.update(albumId, description, targetId); }; - async delete (albumId) { + 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..f6bfb42 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/albumRepositoryImplementation.js b/src/repositories/implementation/albumRepositoryImplementation.js index 8f07cc4..0b1999f 100644 --- a/src/repositories/implementation/albumRepositoryImplementation.js +++ b/src/repositories/implementation/albumRepositoryImplementation.js @@ -18,17 +18,20 @@ class AlbumRepositoryImplementation extends IAlbumRepository{ throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR,'Error while creating a new album'); } }; + getById(albumId){ return db('album') .where({ id: albumId }) .select('id', 'description', 'target_id', 'is_active') .first(); }; + getAll(albumId){ return db('album') .where({ id: albumId }) .select('id', 'description', 'target_id', 'is_active'); }; + async update(albumId, description, targetId) { try { await db.transaction(async (trx) => { @@ -43,6 +46,7 @@ class AlbumRepositoryImplementation extends IAlbumRepository{ throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR,'Error while updating album'); } }; + async delete (albumId) { try { await db.transaction(async (trx) => { diff --git a/src/repositories/implementation/commentRepositoryImplementation.js b/src/repositories/implementation/commentRepositoryImplementation.js index 835ac20..a056858 100644 --- a/src/repositories/implementation/commentRepositoryImplementation.js +++ b/src/repositories/implementation/commentRepositoryImplementation.js @@ -38,14 +38,14 @@ class CommentRepositoryImplementation extends ICommentRepository{ } } - async update(id, description, user_id, post_id) { + async update(id, description, userId, post_id) { try { const [comment] = await db('comment') .where({ id }) .update({ - description, - user_id, - post_id, + description: description, + user_id: userId, + post_id: post_id, updated_at: new Date() }) .returning('*'); 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..96882bb 100644 --- a/src/repositories/implementation/friendshipRequestRepository.js +++ b/src/repositories/implementation/friendshipRequestRepository.js @@ -5,11 +5,11 @@ 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) { @@ -17,9 +17,9 @@ class FriendshipRequestRepositoryImplementation extends IFriendshipRequestReposi } } - async getAll(userId) { + getAll(userId) { try { - return await db("friendship_request") + return db("friendship_request") .where("sender_id", userId) .orWhere("receiver_id", userId) .select("*"); @@ -28,9 +28,9 @@ class FriendshipRequestRepositoryImplementation extends IFriendshipRequestReposi } } - async accept(requestId) { + accept(requestId) { try { - await db("friendship_request") + db("friendship_request") .where({ id: requestId }) .update({ request_type_id: friendshipRequestTypeStatus.ACCEPTED, @@ -41,9 +41,9 @@ class FriendshipRequestRepositoryImplementation extends IFriendshipRequestReposi } } - async delete(requestId) { + delete(requestId) { try { - await db("friendship_request") + db("friendship_request") .where({ id: requestId }) .del(); } catch (error) { 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..b8c739c 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(), @@ -20,9 +19,10 @@ class UserRepositoryImplementation extends IUserRepository{ 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) { @@ -30,34 +30,34 @@ class UserRepositoryImplementation extends IUserRepository{ } }; - 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) { @@ -65,19 +65,19 @@ class UserRepositoryImplementation extends IUserRepository{ } }; - 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 +132,16 @@ 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 +202,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/commentsSchema.js b/src/schemas/commentsSchema.js index cb6bdcf..7c83d08 100644 --- a/src/schemas/commentsSchema.js +++ b/src/schemas/commentsSchema.js @@ -27,4 +27,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 f6b46c3..9e0e585 100644 --- a/src/services/albumItemService.js +++ b/src/services/albumItemService.js @@ -4,15 +4,15 @@ const httpStatus = require("../utils/statusCodes"); class AlbumItemService { constructor(albumItemRepository) { this.albumItemRepository = albumItemRepository; - } - async createAlbumItem(postId, albumItemId) { + }; + createAlbumItem(postId, albumItemId) { return this.albumItemRepository.create(postId, albumItemId); }; - async getAllAlbumItem(albumItemId) { + getAllAlbumItem(albumItemId) { return this.albumItemRepository.getAll(albumItemId); }; async deleteAlbumItem(albumItemId) { - const albumItem = await this.albumItemRepository.getById(albumId); + const albumItem = await this.albumItemRepository.getById(albumItemId); if (!albumItem) throw new ApiError(httpStatus.NOT_FOUND, 'Album item not found'); await this.albumItemRepository.delete(albumItemId); }; diff --git a/src/services/albumService.js b/src/services/albumService.js index 2dffe26..ede4af6 100644 --- a/src/services/albumService.js +++ b/src/services/albumService.js @@ -4,7 +4,7 @@ const ApiError = require("../utils/ApiError"); class AlbumService { constructor(albumRepository) { this.albumRepository = albumRepository; - } + }; createAlbum(description, targetId) { return this.albumRepository.create(description, targetId); }; @@ -16,10 +16,10 @@ class AlbumService { 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(albumId) { const album = await this.albumRepository.getById(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..1bfc9f1 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, userId, postId) { + const comment = await this.commentRepository.getById(userId); 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, userId, postId); }; - 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..2e4ca8d 100644 --- a/src/services/fileTypeService.js +++ b/src/services/fileTypeService.js @@ -4,16 +4,16 @@ const httpStatus = require("../utils/statusCodes"); class FileTypeService { constructor(fileTypeRepository) { this.fileTypeRepository = fileTypeRepository; - } - async createFileType(type) { + }; + createFileType(type) { return this.fileTypeRepository.create(type) }; - async getById(id){ - const fileType = await this.fileTypeRepository.getById(id); + 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) { 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..37f146c 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); + this.userRepository.create(fullName, email, hashedPassword); }; async getUserById(id) { const user = await this.userRepository.getById(id); 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 From 568738aaec4cd9bd471caa8cf92a0db78c934d6e Mon Sep 17 00:00:00 2001 From: Luiz Cruz Date: Tue, 23 Jul 2024 22:23:45 -0300 Subject: [PATCH 11/13] Fix service tests --- src/services/commentService.js | 2 +- src/services/userServices.js | 2 +- tests/service/commentService.test.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/commentService.js b/src/services/commentService.js index 1bfc9f1..48d885a 100644 --- a/src/services/commentService.js +++ b/src/services/commentService.js @@ -17,7 +17,7 @@ class CommentService { return this.commentRepository.getAll(commentId); }; async updateComment(commentId, description, userId, postId) { - const comment = await this.commentRepository.getById(userId); + const comment = await this.commentRepository.getById(commentId); if (!comment) throw new ApiError(httpStatus.NOT_FOUND, 'Comment not found'); await this.commentRepository.update(commentId, description, userId, postId); }; diff --git a/src/services/userServices.js b/src/services/userServices.js index 37f146c..ec1f265 100644 --- a/src/services/userServices.js +++ b/src/services/userServices.js @@ -10,7 +10,7 @@ class UserService { 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(fullName, email, hashedPassword); + return this.userRepository.create(fullName, email, hashedPassword); }; async getUserById(id) { const user = await this.userRepository.getById(id); diff --git a/tests/service/commentService.test.js b/tests/service/commentService.test.js index d8f577e..5f9c5b6 100644 --- a/tests/service/commentService.test.js +++ b/tests/service/commentService.test.js @@ -80,7 +80,7 @@ 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; From e87a2a836a5b487bd561e2c2d060413e816b1798 Mon Sep 17 00:00:00 2001 From: Luiz Cruz Date: Tue, 23 Jul 2024 23:49:56 -0300 Subject: [PATCH 12/13] Fix integration tests --- src/middlewares/friendshipRequestValidation.js | 4 ++-- src/repositories/friendshipRepository.js | 2 +- .../implementation/friendshipRequestRepository.js | 11 ++++------- src/services/fileTypeService.js | 11 ++++++----- tests/integration/friendshipRequest.test.js | 1 - 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/middlewares/friendshipRequestValidation.js b/src/middlewares/friendshipRequestValidation.js index e29b579..06e9f3c 100644 --- a/src/middlewares/friendshipRequestValidation.js +++ b/src/middlewares/friendshipRequestValidation.js @@ -9,8 +9,8 @@ const validateSchema = (schema) => async (req, res, next) => { await schema.validate({ authorization, id, - senderId, - receiverId + sender_id: senderId, + receiver_id: receiverId }) next(); } catch (error) { diff --git a/src/repositories/friendshipRepository.js b/src/repositories/friendshipRepository.js index f6bfb42..1d560bb 100644 --- a/src/repositories/friendshipRepository.js +++ b/src/repositories/friendshipRepository.js @@ -5,7 +5,7 @@ class FriendshipRepository { assertIsInstanceOfContract(repository, contract); this.repository = repository; }; - create({principalUserId, friendId}) { + create(principalUserId, friendId) { return this.repository.create(principalUserId, friendId); }; getAll(userId){ diff --git a/src/repositories/implementation/friendshipRequestRepository.js b/src/repositories/implementation/friendshipRequestRepository.js index 96882bb..3ddca2f 100644 --- a/src/repositories/implementation/friendshipRequestRepository.js +++ b/src/repositories/implementation/friendshipRequestRepository.js @@ -15,8 +15,7 @@ class FriendshipRequestRepositoryImplementation extends IFriendshipRequestReposi } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while creating friendship request'); } - } - + }; getAll(userId) { try { return db("friendship_request") @@ -26,8 +25,7 @@ class FriendshipRequestRepositoryImplementation extends IFriendshipRequestReposi } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while getting all friendship requests'); } - } - + }; accept(requestId) { try { db("friendship_request") @@ -39,8 +37,7 @@ class FriendshipRequestRepositoryImplementation extends IFriendshipRequestReposi } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while accepting friendship request'); } - } - + }; delete(requestId) { try { db("friendship_request") @@ -49,7 +46,7 @@ class FriendshipRequestRepositoryImplementation extends IFriendshipRequestReposi } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while deleting friendship request'); } - } + }; } module.exports = FriendshipRequestRepositoryImplementation; diff --git a/src/services/fileTypeService.js b/src/services/fileTypeService.js index 2e4ca8d..77c1425 100644 --- a/src/services/fileTypeService.js +++ b/src/services/fileTypeService.js @@ -5,8 +5,8 @@ class FileTypeService { constructor(fileTypeRepository) { this.fileTypeRepository = fileTypeRepository; }; - createFileType(type) { - return this.fileTypeRepository.create(type) + createFileType(newFileType) { + return this.fileTypeRepository.create(newFileType) }; async getById(fileTypeId){ const fileType = await this.fileTypeRepository.getById(fileTypeId); @@ -16,9 +16,10 @@ class FileTypeService { 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/tests/integration/friendshipRequest.test.js b/tests/integration/friendshipRequest.test.js index 284ff54..6afffc1 100644 --- a/tests/integration/friendshipRequest.test.js +++ b/tests/integration/friendshipRequest.test.js @@ -7,7 +7,6 @@ describe('Testing FriendshipRequest feature', () => { let loggedUser; let receiverFriendshipRequestUser; let loginResponse; - let tempUser; beforeAll(async () => { await db('user').insert({ id: 10000, From bd3979c796a37dc37039811d6082388f3ac78e2c Mon Sep 17 00:00:00 2001 From: Luiz Cruz Date: Wed, 24 Jul 2024 02:16:43 -0300 Subject: [PATCH 13/13] Fix integration tests --- package.json | 4 +- src/controller/albumController.js | 14 +++---- src/controller/albumItemController.js | 2 +- src/controller/commentController.js | 28 +++++++------- src/controller/friendshipRequestController.js | 2 +- .../friendshipRequestTypeController.js | 2 +- src/controller/userController.js | 6 +-- src/middlewares/albumItemValidation.js | 8 ++-- src/middlewares/albumValidation.js | 10 ++--- src/middlewares/commentsValidation.js | 12 +++--- src/middlewares/postValidation.js | 10 ++--- src/middlewares/reactionValidation.js | 8 ++-- .../albumItemRepositoryImplementation.js | 12 ++++-- .../albumRepositoryImplementation.js | 2 - .../commentRepositoryImplementation.js | 37 ++++++++----------- .../userRepositoryImplementation.js | 9 +---- src/schemas/albumSchema.js | 8 ++-- src/schemas/commentsSchema.js | 7 +--- src/services/commentService.js | 4 +- src/utils/targetPublicStatus.js | 7 ++++ tests/integration/album.test.js | 16 ++++---- tests/integration/comment.test.js | 30 +++++++-------- tests/integration/friendshipRequest.test.js | 8 ++-- tests/integration/reaction.test.js | 4 +- tests/integration/user.test.js | 2 +- tests/restart.sql | 4 ++ tests/service/commentService.test.js | 2 +- 27 files changed, 128 insertions(+), 130 deletions(-) create mode 100644 src/utils/targetPublicStatus.js create mode 100644 tests/restart.sql diff --git a/package.json b/package.json index 09676fc..31df441 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "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", diff --git a/src/controller/albumController.js b/src/controller/albumController.js index 8ac2a24..df8df76 100644 --- a/src/controller/albumController.js +++ b/src/controller/albumController.js @@ -14,7 +14,7 @@ class AlbumController { }); } async getAlbumById(req, res) { - const { albumId } = req.params; + const { id: albumId } = req.params; const { authorization: token } = req.headers; await this.tokenService.verifyToken(token); const album = await this.albumService.getAlbumById(albumId); @@ -22,25 +22,25 @@ class AlbumController { } 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: targetId } = req.body; - await this.albumService.updateAlbum(id, description, targetId); + 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 345c027..43a4c6a 100644 --- a/src/controller/albumItemController.js +++ b/src/controller/albumItemController.js @@ -22,7 +22,7 @@ class AlbumItemController { return res.status(httpStatus.OK).json(albumItem); } async deleteAlbumItem(req, res) { - const { album_item_id: albumItemId } = req.params; + const { id: albumItemId } = req.params; const { authorization: token } = req.headers; await this.tokenService.verifyToken(token); await this.albumItemService.deleteAlbumItem(albumItemId); diff --git a/src/controller/commentController.js b/src/controller/commentController.js index cce48d5..f52f0fd 100644 --- a/src/controller/commentController.js +++ b/src/controller/commentController.js @@ -7,8 +7,8 @@ class CommentController { } async create(req, res) { const { authorization: token } = req.headers; - await this.tokenService.verifyToken(token); - const { description, user_id: userId, post_id: postId } = req.body; + 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!', @@ -16,37 +16,37 @@ class CommentController { }); } 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: userId, post_id: postId } = req.body; - await this.commentService.updateComment(id, description, userId, postId); + 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/userController.js b/src/controller/userController.js index d60afc7..6af3421 100644 --- a/src/controller/userController.js +++ b/src/controller/userController.js @@ -6,7 +6,7 @@ class UserController { this.userService = userService; this.authenticateService = authenticateService; this.tokenService = tokenService; - } + }; async create(req, res) { const { full_name: fullName, email, password } = req.body; const user = await this.userService.create(fullName, email, password); @@ -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) { diff --git a/src/middlewares/albumItemValidation.js b/src/middlewares/albumItemValidation.js index f524ea4..f33cd88 100644 --- a/src/middlewares/albumItemValidation.js +++ b/src/middlewares/albumItemValidation.js @@ -6,10 +6,10 @@ const validateSchema = (schema) => async (req, res, next) => { const { authorization } = req.headers; const { id } = req.params; await schema.validate({ - id, - authorization, - postId, - albumId + 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 0414334..cfe782c 100644 --- a/src/middlewares/albumValidation.js +++ b/src/middlewares/albumValidation.js @@ -4,12 +4,12 @@ const validateSchema = (schema) => async (req, res, next) => { try { const { description, target_id: targetId } = req.body; const { authorization } = req.headers; - const { albumId } = req.params; + const { id: albumId } = req.params; await schema.validate({ - albumId, - authorization, - description, - targetId + 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 3df59da..24549a0 100644 --- a/src/middlewares/commentsValidation.js +++ b/src/middlewares/commentsValidation.js @@ -3,14 +3,14 @@ const httpStatus = require("../utils/statusCodes"); const validateSchema = (schema) => async (req, res, next) => { try { const { description, user_id: userId, post_id: postId } = req.body; - const { id } = req.params; + const { id: commentId } = req.params; const { authorization } = req.headers; await schema.validate({ - id, - authorization, - description, - userId, - post_id + id: commentId, + authorization: authorization, + description: description, + user_id: userId, + post_id: postId }) next(); } catch (error) { diff --git a/src/middlewares/postValidation.js b/src/middlewares/postValidation.js index c8a336b..d135ea0 100644 --- a/src/middlewares/postValidation.js +++ b/src/middlewares/postValidation.js @@ -6,11 +6,11 @@ const validateSchema = (schema) => async (req, res, next) => { const { id } = req.params; const { authorization } = req.headers; await schema.validate({ - id, - authorization, - description, - targetId, - typeId + 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 b991fb5..c02a3b6 100644 --- a/src/middlewares/reactionValidation.js +++ b/src/middlewares/reactionValidation.js @@ -6,10 +6,10 @@ const validateSchema = (schema) => async (req, res, next) => { const { authorization } = req.headers; const { id } = req.params; await schema.validate({ - id, - authorization, - reactionTypeId, - postId + id: id, + authorization: authorization, + reaction_type_id: reactionTypeId, + post_id: postId }) next(); } catch (error) { diff --git a/src/repositories/implementation/albumItemRepositoryImplementation.js b/src/repositories/implementation/albumItemRepositoryImplementation.js index 79973d8..cd03b68 100644 --- a/src/repositories/implementation/albumItemRepositoryImplementation.js +++ b/src/repositories/implementation/albumItemRepositoryImplementation.js @@ -24,10 +24,14 @@ class AlbumItemRepositoryImplementation extends IAlbumItemRepository { } getById(albumItemId) { - return db('Album_Item') - .where({ id: albumItemId }) - .select(['id', 'post_id', 'album_id', 'is_active']) - .first(); + try { + return db('Album_Item') + .where({ id: albumItemId }) + .select(['id', 'post_id', 'album_id', 'is_active']) + .first(); + } catch (err){ + console.error(err); + } } getAll(albumItemId) { diff --git a/src/repositories/implementation/albumRepositoryImplementation.js b/src/repositories/implementation/albumRepositoryImplementation.js index 0b1999f..990fa3f 100644 --- a/src/repositories/implementation/albumRepositoryImplementation.js +++ b/src/repositories/implementation/albumRepositoryImplementation.js @@ -18,14 +18,12 @@ class AlbumRepositoryImplementation extends IAlbumRepository{ throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR,'Error while creating a new album'); } }; - getById(albumId){ return db('album') .where({ id: albumId }) .select('id', 'description', 'target_id', 'is_active') .first(); }; - getAll(albumId){ return db('album') .where({ id: albumId }) diff --git a/src/repositories/implementation/commentRepositoryImplementation.js b/src/repositories/implementation/commentRepositoryImplementation.js index a056858..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, userId, post_id) { + }; + async update(commentId, description) { try { - const [comment] = await db('comment') - .where({ id }) - .update({ - description: description, - user_id: userId, - post_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/userRepositoryImplementation.js b/src/repositories/implementation/userRepositoryImplementation.js index b8c739c..8464357 100644 --- a/src/repositories/implementation/userRepositoryImplementation.js +++ b/src/repositories/implementation/userRepositoryImplementation.js @@ -18,8 +18,7 @@ class UserRepositoryImplementation extends IUserRepository{ } catch (error) { throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR,'Error while creating user'); } - } - + }; getByEmail(email) { try { return db('user') @@ -29,7 +28,6 @@ class UserRepositoryImplementation extends IUserRepository{ throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while getting a email by id'); } }; - getById(userId){ try { return db('user') @@ -40,7 +38,6 @@ class UserRepositoryImplementation extends IUserRepository{ throw new ApiError(httpStatus.NOT_FOUND, 'Error while getting user by id'); } }; - getAll(){ try { return db('user') @@ -50,7 +47,6 @@ class UserRepositoryImplementation extends IUserRepository{ throw new Error('Error while getting all users'); } }; - update(userId, fullName, email) { try { db('user') @@ -64,7 +60,6 @@ class UserRepositoryImplementation extends IUserRepository{ throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR,'Error while updating user'); } }; - delete (userId) { try { db('user') @@ -74,7 +69,6 @@ class UserRepositoryImplementation extends IUserRepository{ throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR,'Error while deleting user'); } }; - getFeedNews(userId) { try { return db.raw(` @@ -138,7 +132,6 @@ class UserRepositoryImplementation extends IUserRepository{ throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Error while getting a feed'); } }; - getPostStatistics() { try { return db.raw(` diff --git a/src/schemas/albumSchema.js b/src/schemas/albumSchema.js index 553a8a8..66e62d5 100644 --- a/src/schemas/albumSchema.js +++ b/src/schemas/albumSchema.js @@ -2,17 +2,17 @@ const yup = require('yup'); const createAlbumSchema = yup.object({ description: yup.string().required(), - targetId: yup.number().integer().required() + target_id: yup.number().integer().required() }); const updateAlbumSchema = yup.object({ - albumId: yup.number().integer().required(), + album_id: yup.number().integer().required(), description: yup.string().required(), - targetId: yup.number().integer().required() + target_id: yup.number().integer().required() }); const getByIdSchema = yup.object({ - albumId: 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 7c83d08..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({ diff --git a/src/services/commentService.js b/src/services/commentService.js index 48d885a..45bf95c 100644 --- a/src/services/commentService.js +++ b/src/services/commentService.js @@ -16,10 +16,10 @@ class CommentService { getAllComments(commentId) { return this.commentRepository.getAll(commentId); }; - async updateComment(commentId, description, userId, postId) { + 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(commentId, description, userId, postId); + await this.commentRepository.update(commentId, description); }; async deleteComment(commentId) { const comment = await this.commentRepository.getById(commentId); 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 6afffc1..2b1d69c 100644 --- a/tests/integration/friendshipRequest.test.js +++ b/tests/integration/friendshipRequest.test.js @@ -9,7 +9,7 @@ describe('Testing FriendshipRequest feature', () => { let loginResponse; beforeAll(async () => { await db('user').insert({ - id: 10000, + id: 12345678, full_name: 'Sender', email: 'sender@gmail.com', password: '$2b$10$OMDQ.q5dkZAZkQH1g5W6IOP4ZLCwBV4xnTCHDng2pNhlWOpq/n5xO', @@ -17,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, @@ -78,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, @@ -86,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 5f9c5b6..c39a4e3 100644 --- a/tests/service/commentService.test.js +++ b/tests/service/commentService.test.js @@ -87,7 +87,7 @@ describe('CommentsService', () => { 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);