From 5c35493281cffc699930308df95bd4302913ef8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patr=C3=ADcia=20Dias?= Date: Tue, 7 Mar 2023 17:56:42 +0000 Subject: [PATCH 1/5] feat: started repositories --- .../repositories/comment-board.repository.interface.ts | 4 ++++ .../modules/comments/repositories/comment-board.repository.ts | 0 2 files changed, 4 insertions(+) create mode 100644 backend/src/modules/comments/repositories/comment-board.repository.interface.ts create mode 100644 backend/src/modules/comments/repositories/comment-board.repository.ts diff --git a/backend/src/modules/comments/repositories/comment-board.repository.interface.ts b/backend/src/modules/comments/repositories/comment-board.repository.interface.ts new file mode 100644 index 000000000..0c3e6aa29 --- /dev/null +++ b/backend/src/modules/comments/repositories/comment-board.repository.interface.ts @@ -0,0 +1,4 @@ +import { BaseInterfaceRepository } from 'src/libs/repositories/interfaces/base.repository.interface'; +import Board from 'src/modules/boards/entities/board.schema'; + +export interface VoteBoardUserRepositoryInterface extends BaseInterfaceRepository {} diff --git a/backend/src/modules/comments/repositories/comment-board.repository.ts b/backend/src/modules/comments/repositories/comment-board.repository.ts new file mode 100644 index 000000000..e69de29bb From 4f661482858270d1567dee93bad042190e4b4199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patr=C3=ADcia=20Dias?= Date: Tue, 7 Mar 2023 18:02:17 +0000 Subject: [PATCH 2/5] feat: started comment repository --- .../comment-board.repository.interface.ts | 2 +- .../repositories/comment-board.repository.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/backend/src/modules/comments/repositories/comment-board.repository.interface.ts b/backend/src/modules/comments/repositories/comment-board.repository.interface.ts index 0c3e6aa29..cc4364ac5 100644 --- a/backend/src/modules/comments/repositories/comment-board.repository.interface.ts +++ b/backend/src/modules/comments/repositories/comment-board.repository.interface.ts @@ -1,4 +1,4 @@ import { BaseInterfaceRepository } from 'src/libs/repositories/interfaces/base.repository.interface'; import Board from 'src/modules/boards/entities/board.schema'; -export interface VoteBoardUserRepositoryInterface extends BaseInterfaceRepository {} +export interface CommentBoardRepositoryInterface extends BaseInterfaceRepository {} diff --git a/backend/src/modules/comments/repositories/comment-board.repository.ts b/backend/src/modules/comments/repositories/comment-board.repository.ts index e69de29bb..d728a87cb 100644 --- a/backend/src/modules/comments/repositories/comment-board.repository.ts +++ b/backend/src/modules/comments/repositories/comment-board.repository.ts @@ -0,0 +1,16 @@ +import { CommentBoardRepositoryInterface } from './comment-board.repository.interface'; +import { Injectable } from '@nestjs/common'; +import { InjectModel } from '@nestjs/mongoose'; +import { Model } from 'mongoose'; +import { MongoGenericRepository } from 'src/libs/repositories/mongo/mongo-generic.repository'; +import Board, { BoardDocument } from 'src/modules/boards/entities/board.schema'; + +@Injectable() +export class VoteBoardRepository + extends MongoGenericRepository + implements CommentBoardRepositoryInterface +{ + constructor(@InjectModel(Board.name) private model: Model) { + super(model); + } +} From 0fcd56ae2b0a10465cb8f2bf24a029ca2c52fb29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patr=C3=ADcia=20Dias?= Date: Wed, 8 Mar 2023 10:11:16 +0000 Subject: [PATCH 3/5] fix: repository name --- .../modules/comments/repositories/comment-board.repository.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/modules/comments/repositories/comment-board.repository.ts b/backend/src/modules/comments/repositories/comment-board.repository.ts index d728a87cb..6021e8c22 100644 --- a/backend/src/modules/comments/repositories/comment-board.repository.ts +++ b/backend/src/modules/comments/repositories/comment-board.repository.ts @@ -6,7 +6,7 @@ import { MongoGenericRepository } from 'src/libs/repositories/mongo/mongo-generi import Board, { BoardDocument } from 'src/modules/boards/entities/board.schema'; @Injectable() -export class VoteBoardRepository +export class CommentRepository extends MongoGenericRepository implements CommentBoardRepositoryInterface { From 716c0ebfeb694229996ed30f465072095532b90f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patr=C3=ADcia=20Dias?= Date: Wed, 8 Mar 2023 17:17:17 +0000 Subject: [PATCH 4/5] feat: renamed classes and interfaces + injected comment repo on service --- .../create.comment.application.ts | 4 +-- .../delete.comment.application.ts | 4 +-- .../update.comment.application.ts | 9 ++++-- .../src/modules/comments/comment.providers.ts | 30 +++++++++++-------- .../controller/comments.controller.ts | 12 ++++---- .../create.comment.application.interface.ts | 4 +-- .../delete.comment.application.interface.ts | 2 +- .../update.comment.application.interface.ts | 2 +- .../comment-board.repository.interface.ts | 2 +- .../src/modules/comments/interfaces/types.ts | 3 ++ .../repositories/comment-board.repository.ts | 2 +- .../services/create.comment.service.ts | 2 +- .../services/delete.comment.service.ts | 2 +- .../services/update.comment.service.ts | 2 +- 14 files changed, 46 insertions(+), 34 deletions(-) rename backend/src/modules/comments/{ => interfaces}/repositories/comment-board.repository.interface.ts (64%) diff --git a/backend/src/modules/comments/applications/create.comment.application.ts b/backend/src/modules/comments/applications/create.comment.application.ts index 89de3c8f9..0f64512f4 100644 --- a/backend/src/modules/comments/applications/create.comment.application.ts +++ b/backend/src/modules/comments/applications/create.comment.application.ts @@ -1,10 +1,10 @@ import { Inject, Injectable } from '@nestjs/common'; -import { CreateCommentApplication } from '../interfaces/applications/create.comment.application.interface'; +import { CreateCommentApplicationInterface } from '../interfaces/applications/create.comment.application.interface'; import { CreateCommentServiceInterface } from '../interfaces/services/create.comment.service.interface'; import { TYPES } from '../interfaces/types'; @Injectable() -export class CreateCommentApplicationImpl implements CreateCommentApplication { +export class CreateCommentApplicationInterfaceImpl implements CreateCommentApplicationInterface { constructor( @Inject(TYPES.services.CreateCommentService) private createCommentService: CreateCommentServiceInterface diff --git a/backend/src/modules/comments/applications/delete.comment.application.ts b/backend/src/modules/comments/applications/delete.comment.application.ts index fbca26aeb..4b4564100 100644 --- a/backend/src/modules/comments/applications/delete.comment.application.ts +++ b/backend/src/modules/comments/applications/delete.comment.application.ts @@ -1,10 +1,10 @@ import { Inject, Injectable } from '@nestjs/common'; -import { DeleteCommentApplication } from '../interfaces/applications/delete.comment.application.interface'; +import { DeleteCommentApplicationInterface } from '../interfaces/applications/delete.comment.application.interface'; import { DeleteCommentService } from '../interfaces/services/delete.comment.service.interface'; import { TYPES } from '../interfaces/types'; @Injectable() -export class DeleteCommentApplicationImpl implements DeleteCommentApplication { +export class DeleteCommentApplicationInterfaceImpl implements DeleteCommentApplicationInterface { constructor( @Inject(TYPES.services.DeleteCommentService) private deleteCommentService: DeleteCommentService diff --git a/backend/src/modules/comments/applications/update.comment.application.ts b/backend/src/modules/comments/applications/update.comment.application.ts index ade51a846..88c0d970d 100644 --- a/backend/src/modules/comments/applications/update.comment.application.ts +++ b/backend/src/modules/comments/applications/update.comment.application.ts @@ -1,13 +1,16 @@ +import { CommentRepositoryInterface } from './../interfaces/repositories/comment-board.repository.interface'; import { Inject, Injectable } from '@nestjs/common'; -import { UpdateCommentApplication } from '../interfaces/applications/update.comment.application.interface'; +import { UpdateCommentApplicationInterface } from '../interfaces/applications/update.comment.application.interface'; import { UpdateCommentService } from '../interfaces/services/update.comment.service.interface'; import { TYPES } from '../interfaces/types'; @Injectable() -export class UpdateCommentApplicationImpl implements UpdateCommentApplication { +export class UpdateCommentApplication implements UpdateCommentApplicationInterface { constructor( @Inject(TYPES.services.UpdateCommentService) - private updateCommentService: UpdateCommentService + private updateCommentService: UpdateCommentService, + @Inject(TYPES.repositories.CommentRepository) + private commentRepository: CommentRepositoryInterface ) {} updateItemComment( diff --git a/backend/src/modules/comments/comment.providers.ts b/backend/src/modules/comments/comment.providers.ts index e28ed1ea3..14ad973fe 100644 --- a/backend/src/modules/comments/comment.providers.ts +++ b/backend/src/modules/comments/comment.providers.ts @@ -1,37 +1,43 @@ -import { CreateCommentApplicationImpl } from './applications/create.comment.application'; -import { DeleteCommentApplicationImpl } from './applications/delete.comment.application'; -import { UpdateCommentApplicationImpl } from './applications/update.comment.application'; +import { CreateCommentApplicationInterfaceImpl } from './applications/create.comment.application'; +import { DeleteCommentApplicationInterfaceImpl } from './applications/delete.comment.application'; +import { UpdateCommentApplication } from './applications/update.comment.application'; import { TYPES } from './interfaces/types'; -import CreateCommentServiceImpl from './services/create.comment.service'; -import DeleteCommentServiceImpl from './services/delete.comment.service'; -import UpdateCommentServiceImpl from './services/update.comment.service'; +import { CommentRepository } from './repositories/comment-board.repository'; +import CreateCommentService from './services/create.comment.service'; +import DeleteCommentService from './services/delete.comment.service'; +import UpdateCommentService from './services/update.comment.service'; export const createCommentService = { provide: TYPES.services.CreateCommentService, - useClass: CreateCommentServiceImpl + useClass: CreateCommentService }; export const updateCommentService = { provide: TYPES.services.UpdateCommentService, - useClass: UpdateCommentServiceImpl + useClass: UpdateCommentService }; export const deleteCommentService = { provide: TYPES.services.DeleteCommentService, - useClass: DeleteCommentServiceImpl + useClass: DeleteCommentService }; export const createCommentApplication = { provide: TYPES.applications.CreateCommentApplication, - useClass: CreateCommentApplicationImpl + useClass: CreateCommentApplicationInterfaceImpl }; export const updateCommentApplication = { provide: TYPES.applications.UpdateCommentApplication, - useClass: UpdateCommentApplicationImpl + useClass: UpdateCommentApplication }; export const deleteCommentApplication = { provide: TYPES.applications.DeleteCommentApplication, - useClass: DeleteCommentApplicationImpl + useClass: DeleteCommentApplicationInterfaceImpl +}; + +export const commentRepository = { + provide: TYPES.repositories.CommentRepository, + useClass: CommentRepository }; diff --git a/backend/src/modules/comments/controller/comments.controller.ts b/backend/src/modules/comments/controller/comments.controller.ts index 00bac0e20..d1e836ae5 100644 --- a/backend/src/modules/comments/controller/comments.controller.ts +++ b/backend/src/modules/comments/controller/comments.controller.ts @@ -42,9 +42,9 @@ import { UserDocument } from 'src/modules/users/entities/user.schema'; import CreateCommentDto from '../dto/create.comment.dto'; import DeleteCommentDto from '../dto/delete.comment.dto'; import UpdateCardCommentDto from '../dto/update.comment.dto'; -import { CreateCommentApplication } from '../interfaces/applications/create.comment.application.interface'; -import { DeleteCommentApplication } from '../interfaces/applications/delete.comment.application.interface'; -import { UpdateCommentApplication } from '../interfaces/applications/update.comment.application.interface'; +import { CreateCommentApplicationInterface } from '../interfaces/applications/create.comment.application.interface'; +import { DeleteCommentApplicationInterface } from '../interfaces/applications/delete.comment.application.interface'; +import { UpdateCommentApplicationInterface } from '../interfaces/applications/update.comment.application.interface'; import { TYPES } from '../interfaces/types'; @ApiBearerAuth('access-token') @@ -54,11 +54,11 @@ import { TYPES } from '../interfaces/types'; export default class CommentsController { constructor( @Inject(TYPES.services.CreateCommentService) - private createCommentApp: CreateCommentApplication, + private createCommentApp: CreateCommentApplicationInterface, @Inject(TYPES.services.UpdateCommentService) - private updateCommentApp: UpdateCommentApplication, + private updateCommentApp: UpdateCommentApplicationInterface, @Inject(TYPES.services.DeleteCommentService) - private deleteCommentApp: DeleteCommentApplication, + private deleteCommentApp: DeleteCommentApplicationInterface, private socketService: SocketGateway ) {} diff --git a/backend/src/modules/comments/interfaces/applications/create.comment.application.interface.ts b/backend/src/modules/comments/interfaces/applications/create.comment.application.interface.ts index b3981ffc5..fd724b9dc 100644 --- a/backend/src/modules/comments/interfaces/applications/create.comment.application.interface.ts +++ b/backend/src/modules/comments/interfaces/applications/create.comment.application.interface.ts @@ -1,6 +1,6 @@ -import Comment from '../../schemas/comment.schema'; +import Comment from 'src/modules/comments/schemas/comment.schema'; -export interface CreateCommentApplication { +export interface CreateCommentApplicationInterface { createItemComment( boardId: string, cardId: string, diff --git a/backend/src/modules/comments/interfaces/applications/delete.comment.application.interface.ts b/backend/src/modules/comments/interfaces/applications/delete.comment.application.interface.ts index b75883023..4c5a72581 100644 --- a/backend/src/modules/comments/interfaces/applications/delete.comment.application.interface.ts +++ b/backend/src/modules/comments/interfaces/applications/delete.comment.application.interface.ts @@ -1,7 +1,7 @@ import { LeanDocument } from 'mongoose'; import { BoardDocument } from 'src/modules/boards/entities/board.schema'; -export interface DeleteCommentApplication { +export interface DeleteCommentApplicationInterface { deleteItemComment( boardId: string, commentId: string, diff --git a/backend/src/modules/comments/interfaces/applications/update.comment.application.interface.ts b/backend/src/modules/comments/interfaces/applications/update.comment.application.interface.ts index ca0d6fc7f..e5762f83d 100644 --- a/backend/src/modules/comments/interfaces/applications/update.comment.application.interface.ts +++ b/backend/src/modules/comments/interfaces/applications/update.comment.application.interface.ts @@ -1,7 +1,7 @@ import { LeanDocument } from 'mongoose'; import { BoardDocument } from 'src/modules/boards/entities/board.schema'; -export interface UpdateCommentApplication { +export interface UpdateCommentApplicationInterface { updateItemComment( boardId: string, cardId: string, diff --git a/backend/src/modules/comments/repositories/comment-board.repository.interface.ts b/backend/src/modules/comments/interfaces/repositories/comment-board.repository.interface.ts similarity index 64% rename from backend/src/modules/comments/repositories/comment-board.repository.interface.ts rename to backend/src/modules/comments/interfaces/repositories/comment-board.repository.interface.ts index cc4364ac5..e4a60c168 100644 --- a/backend/src/modules/comments/repositories/comment-board.repository.interface.ts +++ b/backend/src/modules/comments/interfaces/repositories/comment-board.repository.interface.ts @@ -1,4 +1,4 @@ import { BaseInterfaceRepository } from 'src/libs/repositories/interfaces/base.repository.interface'; import Board from 'src/modules/boards/entities/board.schema'; -export interface CommentBoardRepositoryInterface extends BaseInterfaceRepository {} +export interface CommentRepositoryInterface extends BaseInterfaceRepository {} diff --git a/backend/src/modules/comments/interfaces/types.ts b/backend/src/modules/comments/interfaces/types.ts index 48634c7ed..063c329ab 100644 --- a/backend/src/modules/comments/interfaces/types.ts +++ b/backend/src/modules/comments/interfaces/types.ts @@ -8,5 +8,8 @@ export const TYPES = { CreateCommentApplication: 'CreateCommentApplication', DeleteCommentApplication: 'DeleteCommentApplication', UpdateCommentApplication: 'UpdateCommentApplication' + }, + repositories: { + CommentRepository: 'CommentRepository' } }; diff --git a/backend/src/modules/comments/repositories/comment-board.repository.ts b/backend/src/modules/comments/repositories/comment-board.repository.ts index 6021e8c22..f0c75fcc1 100644 --- a/backend/src/modules/comments/repositories/comment-board.repository.ts +++ b/backend/src/modules/comments/repositories/comment-board.repository.ts @@ -1,4 +1,4 @@ -import { CommentBoardRepositoryInterface } from './comment-board.repository.interface'; +import { CommentBoardRepositoryInterface } from '../interfaces/repositories/comment-board.repository.interface'; import { Injectable } from '@nestjs/common'; import { InjectModel } from '@nestjs/mongoose'; import { Model } from 'mongoose'; diff --git a/backend/src/modules/comments/services/create.comment.service.ts b/backend/src/modules/comments/services/create.comment.service.ts index b1a05491c..e72cd6673 100644 --- a/backend/src/modules/comments/services/create.comment.service.ts +++ b/backend/src/modules/comments/services/create.comment.service.ts @@ -7,7 +7,7 @@ import { BoardDataPopulate } from 'src/modules/boards/utils/populate-board'; import { CreateCommentServiceInterface } from '../interfaces/services/create.comment.service.interface'; @Injectable() -export default class CreateCommentServiceImpl implements CreateCommentServiceInterface { +export default class CreateCommentService implements CreateCommentServiceInterface { constructor(@InjectModel(Board.name) private boardModel: Model) {} async createItemComment( diff --git a/backend/src/modules/comments/services/delete.comment.service.ts b/backend/src/modules/comments/services/delete.comment.service.ts index eacbbe0d8..aae91178a 100644 --- a/backend/src/modules/comments/services/delete.comment.service.ts +++ b/backend/src/modules/comments/services/delete.comment.service.ts @@ -6,7 +6,7 @@ import { BoardDataPopulate } from 'src/modules/boards/utils/populate-board'; import { DeleteCommentService } from '../interfaces/services/delete.comment.service.interface'; @Injectable() -export default class DeleteCommentServiceImpl implements DeleteCommentService { +export default class DeleteCommentService implements DeleteCommentService { constructor(@InjectModel(Board.name) private boardModel: Model) {} deleteItemComment(boardId: string, commentId: string, userId: string) { diff --git a/backend/src/modules/comments/services/update.comment.service.ts b/backend/src/modules/comments/services/update.comment.service.ts index d05d2c12d..10a21e9ad 100644 --- a/backend/src/modules/comments/services/update.comment.service.ts +++ b/backend/src/modules/comments/services/update.comment.service.ts @@ -6,7 +6,7 @@ import { BoardDataPopulate } from 'src/modules/boards/utils/populate-board'; import { UpdateCommentService } from '../interfaces/services/update.comment.service.interface'; @Injectable() -export default class UpdateCommentServiceImpl implements UpdateCommentService { +export default class UpdateCommentService implements UpdateCommentService { constructor(@InjectModel(Board.name) private boardModel: Model) {} updateItemComment( From 4411094cabfd4cdd76c2361cac1c4f94d4dcb72f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patr=C3=ADcia=20Dias?= Date: Thu, 9 Mar 2023 10:37:13 +0000 Subject: [PATCH 5/5] feat: comment repository --- .../create.comment.application.ts | 2 +- .../delete.comment.application.ts | 4 +- .../update.comment.application.ts | 11 +- .../src/modules/comments/comment.providers.ts | 10 +- .../src/modules/comments/comments.module.ts | 4 +- .../controller/comments.controller.ts | 2 - .../update.comment.application.interface.ts | 2 - .../comment-board.repository.interface.ts | 4 - .../comment.repository.interface.ts | 45 +++++ .../delete.comment.service.interface.ts | 17 +- .../update.comment.service.interface.ts | 11 +- .../repositories/comment-board.repository.ts | 16 -- .../repositories/comment.repository.ts | 176 ++++++++++++++++++ .../services/create.comment.service.ts | 106 ++++------- .../services/delete.comment.service.ts | 63 ++----- .../services/update.comment.service.ts | 74 +++----- 16 files changed, 319 insertions(+), 228 deletions(-) delete mode 100644 backend/src/modules/comments/interfaces/repositories/comment-board.repository.interface.ts create mode 100644 backend/src/modules/comments/interfaces/repositories/comment.repository.interface.ts delete mode 100644 backend/src/modules/comments/repositories/comment-board.repository.ts create mode 100644 backend/src/modules/comments/repositories/comment.repository.ts diff --git a/backend/src/modules/comments/applications/create.comment.application.ts b/backend/src/modules/comments/applications/create.comment.application.ts index 0f64512f4..bf002c48b 100644 --- a/backend/src/modules/comments/applications/create.comment.application.ts +++ b/backend/src/modules/comments/applications/create.comment.application.ts @@ -4,7 +4,7 @@ import { CreateCommentServiceInterface } from '../interfaces/services/create.com import { TYPES } from '../interfaces/types'; @Injectable() -export class CreateCommentApplicationInterfaceImpl implements CreateCommentApplicationInterface { +export class CreateCommentApplication implements CreateCommentApplicationInterface { constructor( @Inject(TYPES.services.CreateCommentService) private createCommentService: CreateCommentServiceInterface diff --git a/backend/src/modules/comments/applications/delete.comment.application.ts b/backend/src/modules/comments/applications/delete.comment.application.ts index 4b4564100..e09fdc167 100644 --- a/backend/src/modules/comments/applications/delete.comment.application.ts +++ b/backend/src/modules/comments/applications/delete.comment.application.ts @@ -1,10 +1,10 @@ import { Inject, Injectable } from '@nestjs/common'; import { DeleteCommentApplicationInterface } from '../interfaces/applications/delete.comment.application.interface'; -import { DeleteCommentService } from '../interfaces/services/delete.comment.service.interface'; import { TYPES } from '../interfaces/types'; +import DeleteCommentService from '../services/delete.comment.service'; @Injectable() -export class DeleteCommentApplicationInterfaceImpl implements DeleteCommentApplicationInterface { +export class DeleteCommentApplication implements DeleteCommentApplicationInterface { constructor( @Inject(TYPES.services.DeleteCommentService) private deleteCommentService: DeleteCommentService diff --git a/backend/src/modules/comments/applications/update.comment.application.ts b/backend/src/modules/comments/applications/update.comment.application.ts index 88c0d970d..17f97666a 100644 --- a/backend/src/modules/comments/applications/update.comment.application.ts +++ b/backend/src/modules/comments/applications/update.comment.application.ts @@ -1,16 +1,13 @@ -import { CommentRepositoryInterface } from './../interfaces/repositories/comment-board.repository.interface'; import { Inject, Injectable } from '@nestjs/common'; import { UpdateCommentApplicationInterface } from '../interfaces/applications/update.comment.application.interface'; -import { UpdateCommentService } from '../interfaces/services/update.comment.service.interface'; +import { UpdateCommentServiceInterface } from '../interfaces/services/update.comment.service.interface'; import { TYPES } from '../interfaces/types'; @Injectable() export class UpdateCommentApplication implements UpdateCommentApplicationInterface { constructor( @Inject(TYPES.services.UpdateCommentService) - private updateCommentService: UpdateCommentService, - @Inject(TYPES.repositories.CommentRepository) - private commentRepository: CommentRepositoryInterface + private updateCommentService: UpdateCommentServiceInterface ) {} updateItemComment( @@ -18,7 +15,6 @@ export class UpdateCommentApplication implements UpdateCommentApplicationInterfa cardId: string, cardItemId: string, commentId: string, - userId: string, text: string, anonymous: boolean ) { @@ -27,7 +23,6 @@ export class UpdateCommentApplication implements UpdateCommentApplicationInterfa cardId, cardItemId, commentId, - userId, text, anonymous ); @@ -37,7 +32,6 @@ export class UpdateCommentApplication implements UpdateCommentApplicationInterfa boardId: string, cardId: string, commentId: string, - userId: string, text: string, anonymous: boolean ) { @@ -45,7 +39,6 @@ export class UpdateCommentApplication implements UpdateCommentApplicationInterfa boardId, cardId, commentId, - userId, text, anonymous ); diff --git a/backend/src/modules/comments/comment.providers.ts b/backend/src/modules/comments/comment.providers.ts index 14ad973fe..1f442f8fa 100644 --- a/backend/src/modules/comments/comment.providers.ts +++ b/backend/src/modules/comments/comment.providers.ts @@ -1,8 +1,8 @@ -import { CreateCommentApplicationInterfaceImpl } from './applications/create.comment.application'; -import { DeleteCommentApplicationInterfaceImpl } from './applications/delete.comment.application'; +import { DeleteCommentApplication } from './applications/delete.comment.application'; +import { CreateCommentApplication } from './applications/create.comment.application'; import { UpdateCommentApplication } from './applications/update.comment.application'; import { TYPES } from './interfaces/types'; -import { CommentRepository } from './repositories/comment-board.repository'; +import { CommentRepository } from './repositories/comment.repository'; import CreateCommentService from './services/create.comment.service'; import DeleteCommentService from './services/delete.comment.service'; import UpdateCommentService from './services/update.comment.service'; @@ -24,7 +24,7 @@ export const deleteCommentService = { export const createCommentApplication = { provide: TYPES.applications.CreateCommentApplication, - useClass: CreateCommentApplicationInterfaceImpl + useClass: CreateCommentApplication }; export const updateCommentApplication = { @@ -34,7 +34,7 @@ export const updateCommentApplication = { export const deleteCommentApplication = { provide: TYPES.applications.DeleteCommentApplication, - useClass: DeleteCommentApplicationInterfaceImpl + useClass: DeleteCommentApplication }; export const commentRepository = { diff --git a/backend/src/modules/comments/comments.module.ts b/backend/src/modules/comments/comments.module.ts index 0b57887ba..93e387767 100644 --- a/backend/src/modules/comments/comments.module.ts +++ b/backend/src/modules/comments/comments.module.ts @@ -3,6 +3,7 @@ import { mongooseBoardModule } from 'src/infrastructure/database/mongoose.module import SocketModule from 'src/modules/socket/socket.module'; import { CardsModule } from '../cards/cards.module'; import { + commentRepository, createCommentApplication, createCommentService, deleteCommentApplication, @@ -21,7 +22,8 @@ import CommentsController from './controller/comments.controller'; updateCommentService, updateCommentApplication, deleteCommentApplication, - deleteCommentService + deleteCommentService, + commentRepository ], exports: [] }) diff --git a/backend/src/modules/comments/controller/comments.controller.ts b/backend/src/modules/comments/controller/comments.controller.ts index d1e836ae5..0b4fbe34c 100644 --- a/backend/src/modules/comments/controller/comments.controller.ts +++ b/backend/src/modules/comments/controller/comments.controller.ts @@ -205,7 +205,6 @@ export default class CommentsController { cardId, itemId, commentId, - request.user._id, text, anonymous ); @@ -252,7 +251,6 @@ export default class CommentsController { boardId, cardId, commentId, - request.user._id, text, anonymous ); diff --git a/backend/src/modules/comments/interfaces/applications/update.comment.application.interface.ts b/backend/src/modules/comments/interfaces/applications/update.comment.application.interface.ts index e5762f83d..3ea515df4 100644 --- a/backend/src/modules/comments/interfaces/applications/update.comment.application.interface.ts +++ b/backend/src/modules/comments/interfaces/applications/update.comment.application.interface.ts @@ -7,7 +7,6 @@ export interface UpdateCommentApplicationInterface { cardId: string, cardItemId: string, commentId: string, - userId: string, text: string, anonymous: boolean ): Promise | null>; @@ -16,7 +15,6 @@ export interface UpdateCommentApplicationInterface { boardId: string, cardId: string, commentId: string, - userId: string, text: string, anonymous: boolean ): Promise | null>; diff --git a/backend/src/modules/comments/interfaces/repositories/comment-board.repository.interface.ts b/backend/src/modules/comments/interfaces/repositories/comment-board.repository.interface.ts deleted file mode 100644 index e4a60c168..000000000 --- a/backend/src/modules/comments/interfaces/repositories/comment-board.repository.interface.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { BaseInterfaceRepository } from 'src/libs/repositories/interfaces/base.repository.interface'; -import Board from 'src/modules/boards/entities/board.schema'; - -export interface CommentRepositoryInterface extends BaseInterfaceRepository {} diff --git a/backend/src/modules/comments/interfaces/repositories/comment.repository.interface.ts b/backend/src/modules/comments/interfaces/repositories/comment.repository.interface.ts new file mode 100644 index 000000000..544ebd6e0 --- /dev/null +++ b/backend/src/modules/comments/interfaces/repositories/comment.repository.interface.ts @@ -0,0 +1,45 @@ +import { BaseInterfaceRepository } from 'src/libs/repositories/interfaces/base.repository.interface'; +import Board from 'src/modules/boards/entities/board.schema'; + +export interface CommentRepositoryInterface extends BaseInterfaceRepository { + // CREATE COMMENTS + insertItemComment( + boardId: string, + cardId: string, + itemId: string, + userId: string, + text: string, + anonymous: boolean + ): Promise; + + insertCardGroupComment( + boardId: string, + cardId: string, + userId: string, + text: string, + anonymous: boolean + ): Promise; + + // UPDATE COMMENTS + updateItemComment( + boardId: string, + cardId: string, + cardItemId: string, + commentId: string, + text: string, + anonymous: boolean + ): Promise; + + updateCardGroupComment( + boardId: string, + cardId: string, + commentId: string, + text: string, + anonymous: boolean + ): Promise; + + // DELETE COMMENTS + deleteItemComment(boardId: string, commentId: string, userId: string): Promise; + + deleteCardGroupComment(boardId: string, commentId: string, userId: string): Promise; +} diff --git a/backend/src/modules/comments/interfaces/services/delete.comment.service.interface.ts b/backend/src/modules/comments/interfaces/services/delete.comment.service.interface.ts index 2f8e62bbc..7790c1c59 100644 --- a/backend/src/modules/comments/interfaces/services/delete.comment.service.interface.ts +++ b/backend/src/modules/comments/interfaces/services/delete.comment.service.interface.ts @@ -1,16 +1,7 @@ -import { LeanDocument } from 'mongoose'; -import { BoardDocument } from 'src/modules/boards/entities/board.schema'; +import Board from 'src/modules/boards/entities/board.schema'; -export interface DeleteCommentService { - deleteItemComment( - boardId: string, - commentId: string, - userId: string - ): Promise>; +export interface DeleteCommentServiceInterface { + deleteItemComment(boardId: string, commentId: string, userId: string): Promise; - deleteCardGroupComment( - boardId: string, - commentId: string, - userId: string - ): Promise>; + deleteCardGroupComment(boardId: string, commentId: string, userId: string): Promise; } diff --git a/backend/src/modules/comments/interfaces/services/update.comment.service.interface.ts b/backend/src/modules/comments/interfaces/services/update.comment.service.interface.ts index 3dd1ce0a9..b492dd244 100644 --- a/backend/src/modules/comments/interfaces/services/update.comment.service.interface.ts +++ b/backend/src/modules/comments/interfaces/services/update.comment.service.interface.ts @@ -1,23 +1,20 @@ -import { LeanDocument } from 'mongoose'; -import { BoardDocument } from 'src/modules/boards/entities/board.schema'; +import Board from 'src/modules/boards/entities/board.schema'; -export interface UpdateCommentService { +export interface UpdateCommentServiceInterface { updateItemComment( boardId: string, cardId: string, cardItemId: string, commentId: string, - userId: string, text: string, anonymous: boolean - ): Promise | null>; + ): Promise; updateCardGroupComment( boardId: string, cardId: string, commentId: string, - userId: string, text: string, anonymous: boolean - ): Promise | null>; + ): Promise; } diff --git a/backend/src/modules/comments/repositories/comment-board.repository.ts b/backend/src/modules/comments/repositories/comment-board.repository.ts deleted file mode 100644 index f0c75fcc1..000000000 --- a/backend/src/modules/comments/repositories/comment-board.repository.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { CommentBoardRepositoryInterface } from '../interfaces/repositories/comment-board.repository.interface'; -import { Injectable } from '@nestjs/common'; -import { InjectModel } from '@nestjs/mongoose'; -import { Model } from 'mongoose'; -import { MongoGenericRepository } from 'src/libs/repositories/mongo/mongo-generic.repository'; -import Board, { BoardDocument } from 'src/modules/boards/entities/board.schema'; - -@Injectable() -export class CommentRepository - extends MongoGenericRepository - implements CommentBoardRepositoryInterface -{ - constructor(@InjectModel(Board.name) private model: Model) { - super(model); - } -} diff --git a/backend/src/modules/comments/repositories/comment.repository.ts b/backend/src/modules/comments/repositories/comment.repository.ts new file mode 100644 index 000000000..489dadd5a --- /dev/null +++ b/backend/src/modules/comments/repositories/comment.repository.ts @@ -0,0 +1,176 @@ +import { CommentRepositoryInterface } from '../interfaces/repositories/comment.repository.interface'; +import { Injectable } from '@nestjs/common'; +import { InjectModel } from '@nestjs/mongoose'; +import { Model } from 'mongoose'; +import { MongoGenericRepository } from 'src/libs/repositories/mongo/mongo-generic.repository'; +import Board, { BoardDocument } from 'src/modules/boards/entities/board.schema'; +import { BoardDataPopulate } from 'src/modules/boards/utils/populate-board'; + +@Injectable() +export class CommentRepository + extends MongoGenericRepository + implements CommentRepositoryInterface +{ + constructor(@InjectModel(Board.name) private model: Model) { + super(model); + } + + /* CREATE COMMENTS*/ + + insertItemComment( + boardId: string, + cardId: string, + itemId: string, + userId: string, + text: string, + anonymous: boolean + ): Promise { + return this.findOneByFieldAndUpdate( + { + _id: boardId, + 'columns.cards.items._id': itemId + }, + { + $push: { + 'columns.$.cards.$[c].items.$[i].comments': { + text, + createdBy: userId, + anonymous, + createdAt: new Date() + } + } + }, + { + arrayFilters: [{ 'c._id': cardId }, { 'i._id': itemId }], + new: true + }, + BoardDataPopulate + ); + } + + insertCardGroupComment( + boardId: string, + cardId: string, + userId: string, + text: string, + anonymous: boolean + ): Promise { + return this.findOneByFieldAndUpdate( + { + _id: boardId, + 'columns.cards._id': cardId + }, + { + $push: { + 'columns.$.cards.$[c].comments': { + text, + createdBy: userId, + anonymous, + createdAt: new Date() + } + } + }, + { + arrayFilters: [{ 'c._id': cardId }], + new: true + }, + BoardDataPopulate + ); + } + + /* UPDATE COMMENTS */ + + updateItemComment( + boardId: string, + cardId: string, + cardItemId: string, + commentId: string, + text: string, + anonymous: boolean + ): Promise { + return this.findOneByFieldAndUpdate( + { + _id: boardId, + 'columns.cards.items.comments._id': commentId + }, + { + $set: { + 'columns.$.cards.$[c].items.$[i].comments.$[com].text': text, + 'columns.$.cards.$[c].items.$[i].comments.$[com].anonymous': anonymous + } + }, + { + arrayFilters: [{ 'c._id': cardId }, { 'i._id': cardItemId }, { 'com._id': commentId }], + new: true + }, + BoardDataPopulate + ); + } + + updateCardGroupComment( + boardId: string, + cardId: string, + commentId: string, + text: string, + anonymous: boolean + ): Promise { + return this.findOneByFieldAndUpdate( + { + _id: boardId, + 'columns.cards.comments._id': commentId + }, + { + $set: { + 'columns.$.cards.$[c].comments.$[com].text': text, + 'columns.$.cards.$[c].comments.$[com].anonymous': anonymous + } + }, + { + arrayFilters: [{ 'c._id': cardId }, { 'com._id': commentId }], + new: true + }, + BoardDataPopulate + ); + } + + /* DELETE COMMENTS */ + + deleteItemComment(boardId: string, commentId: string, userId: string): Promise { + return this.findOneByFieldAndUpdate( + { + _id: boardId, + 'columns.cards.items.comments._id': commentId, + 'columns.cards.items.comments.createdBy': userId + }, + { + $pull: { + 'columns.$[].cards.$[].items.$[].comments': { + _id: commentId, + createdBy: userId + } + } + }, + { new: true }, + BoardDataPopulate + ); + } + + deleteCardGroupComment(boardId: string, commentId: string, userId: string): Promise { + return this.findOneByFieldAndUpdate( + { + _id: boardId, + 'columns.cards.comments._id': commentId + }, + { + $pull: { + 'columns.$[].cards.$[].comments': { + _id: commentId, + createdBy: userId + } + } + }, + { new: true }, + BoardDataPopulate + ); + } +} diff --git a/backend/src/modules/comments/services/create.comment.service.ts b/backend/src/modules/comments/services/create.comment.service.ts index e72cd6673..cb8512828 100644 --- a/backend/src/modules/comments/services/create.comment.service.ts +++ b/backend/src/modules/comments/services/create.comment.service.ts @@ -1,14 +1,15 @@ -import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; -import { InjectModel } from '@nestjs/mongoose'; -import { Model } from 'mongoose'; +import { CommentRepositoryInterface } from '../interfaces/repositories/comment.repository.interface'; +import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common'; import { INSERT_FAILED } from 'src/libs/exceptions/messages'; -import Board, { BoardDocument } from 'src/modules/boards/entities/board.schema'; -import { BoardDataPopulate } from 'src/modules/boards/utils/populate-board'; import { CreateCommentServiceInterface } from '../interfaces/services/create.comment.service.interface'; +import { TYPES } from '../interfaces/types'; @Injectable() export default class CreateCommentService implements CreateCommentServiceInterface { - constructor(@InjectModel(Board.name) private boardModel: Model) {} + constructor( + @Inject(TYPES.repositories.CommentRepository) + private commentRepository: CommentRepositoryInterface + ) {} async createItemComment( boardId: string, @@ -19,45 +20,31 @@ export default class CreateCommentService implements CreateCommentServiceInterfa anonymous: boolean, columnId: string ) { - const board = await this.boardModel - .findOneAndUpdate( - { - _id: boardId, - 'columns.cards.items._id': itemId - }, - { - $push: { - 'columns.$.cards.$[c].items.$[i].comments': { - text, - createdBy: userId, - anonymous, - createdAt: new Date() - } - } - }, - { - arrayFilters: [{ 'c._id': cardId }, { 'i._id': itemId }], - new: true - } - ) - .populate(BoardDataPopulate) - .lean() - .exec(); + const updatedBoard = await this.commentRepository.insertItemComment( + boardId, + cardId, + itemId, + userId, + text, + anonymous + ); - if (!board) throw new HttpException(INSERT_FAILED, HttpStatus.BAD_REQUEST); + if (!updatedBoard) throw new HttpException(INSERT_FAILED, HttpStatus.BAD_REQUEST); - const colIdx = board.columns.findIndex((col) => col._id.toString() === columnId); - const cardIdx = board.columns[colIdx].cards.findIndex((card) => card._id.toString() === cardId); - const cardItemIdx = board.columns[colIdx].cards[cardIdx].items.findIndex( + const colIdx = updatedBoard.columns.findIndex((col) => col._id.toString() === columnId); + const cardIdx = updatedBoard.columns[colIdx].cards.findIndex( + (card) => card._id.toString() === cardId + ); + const cardItemIdx = updatedBoard.columns[colIdx].cards[cardIdx].items.findIndex( (item) => item._id.toString() === itemId ); return { newComment: - board.columns[colIdx].cards[cardIdx].items[cardItemIdx].comments[ - board.columns[colIdx].cards[cardIdx].items[cardItemIdx].comments.length - 1 + updatedBoard.columns[colIdx].cards[cardIdx].items[cardItemIdx].comments[ + updatedBoard.columns[colIdx].cards[cardIdx].items[cardItemIdx].comments.length - 1 ], - hideCards: board.hideCards + hideCards: updatedBoard.hideCards }; } @@ -69,42 +56,27 @@ export default class CreateCommentService implements CreateCommentServiceInterfa anonymous: boolean, columnId: string ) { - const board = await this.boardModel - .findOneAndUpdate( - { - _id: boardId, - 'columns.cards._id': cardId - }, - { - $push: { - 'columns.$.cards.$[c].comments': { - text, - createdBy: userId, - anonymous, - createdAt: new Date() - } - } - }, - { - arrayFilters: [{ 'c._id': cardId }], - new: true - } - ) - .populate(BoardDataPopulate) - .lean() - .exec(); + const updatedBoard = await this.commentRepository.insertCardGroupComment( + boardId, + cardId, + userId, + text, + anonymous + ); - if (!board) throw new HttpException(INSERT_FAILED, HttpStatus.BAD_REQUEST); + if (!updatedBoard) throw new HttpException(INSERT_FAILED, HttpStatus.BAD_REQUEST); - const colIdx = board.columns.findIndex((col) => col._id.toString() === columnId); - const cardIdx = board.columns[colIdx].cards.findIndex((card) => card._id.toString() === cardId); + const colIdx = updatedBoard.columns.findIndex((col) => col._id.toString() === columnId); + const cardIdx = updatedBoard.columns[colIdx].cards.findIndex( + (card) => card._id.toString() === cardId + ); return { newComment: - board.columns[colIdx].cards[cardIdx].comments[ - board.columns[colIdx].cards[cardIdx].comments.length - 1 + updatedBoard.columns[colIdx].cards[cardIdx].comments[ + updatedBoard.columns[colIdx].cards[cardIdx].comments.length - 1 ], - hideCards: board.hideCards + hideCards: updatedBoard.hideCards }; } } diff --git a/backend/src/modules/comments/services/delete.comment.service.ts b/backend/src/modules/comments/services/delete.comment.service.ts index aae91178a..6f082c437 100644 --- a/backend/src/modules/comments/services/delete.comment.service.ts +++ b/backend/src/modules/comments/services/delete.comment.service.ts @@ -1,56 +1,21 @@ -import { Injectable } from '@nestjs/common'; -import { InjectModel } from '@nestjs/mongoose'; -import { Model } from 'mongoose'; -import Board, { BoardDocument } from 'src/modules/boards/entities/board.schema'; -import { BoardDataPopulate } from 'src/modules/boards/utils/populate-board'; -import { DeleteCommentService } from '../interfaces/services/delete.comment.service.interface'; +import { Inject, Injectable } from '@nestjs/common'; +import { DeleteCommentServiceInterface } from '../interfaces/services/delete.comment.service.interface'; +import { CommentRepositoryInterface } from '../interfaces/repositories/comment.repository.interface'; +import { TYPES } from '../interfaces/types'; +import Board from 'src/modules/boards/entities/board.schema'; @Injectable() -export default class DeleteCommentService implements DeleteCommentService { - constructor(@InjectModel(Board.name) private boardModel: Model) {} +export default class DeleteCommentService implements DeleteCommentServiceInterface { + constructor( + @Inject(TYPES.repositories.CommentRepository) + private commentRepository: CommentRepositoryInterface + ) {} - deleteItemComment(boardId: string, commentId: string, userId: string) { - return this.boardModel - .findOneAndUpdate( - { - _id: boardId, - 'columns.cards.items.comments._id': commentId, - 'columns.cards.items.comments.createdBy': userId - }, - { - $pull: { - 'columns.$[].cards.$[].items.$[].comments': { - _id: commentId, - createdBy: userId - } - } - }, - { new: true } - ) - .populate(BoardDataPopulate) - .lean() - .exec(); + deleteItemComment(boardId: string, commentId: string, userId: string): Promise { + return this.commentRepository.deleteItemComment(boardId, commentId, userId); } - deleteCardGroupComment(boardId: string, commentId: string, userId: string) { - return this.boardModel - .findOneAndUpdate( - { - _id: boardId, - 'columns.cards.comments._id': commentId - }, - { - $pull: { - 'columns.$[].cards.$[].comments': { - _id: commentId, - createdBy: userId - } - } - }, - { new: true } - ) - .populate(BoardDataPopulate) - .lean() - .exec(); + deleteCardGroupComment(boardId: string, commentId: string, userId: string): Promise { + return this.commentRepository.deleteItemComment(boardId, commentId, userId); } } diff --git a/backend/src/modules/comments/services/update.comment.service.ts b/backend/src/modules/comments/services/update.comment.service.ts index 10a21e9ad..5a6678c77 100644 --- a/backend/src/modules/comments/services/update.comment.service.ts +++ b/backend/src/modules/comments/services/update.comment.service.ts @@ -1,72 +1,46 @@ -import { Injectable } from '@nestjs/common'; -import { InjectModel } from '@nestjs/mongoose'; -import { Model } from 'mongoose'; -import Board, { BoardDocument } from 'src/modules/boards/entities/board.schema'; -import { BoardDataPopulate } from 'src/modules/boards/utils/populate-board'; -import { UpdateCommentService } from '../interfaces/services/update.comment.service.interface'; +import { UpdateCommentServiceInterface } from './../interfaces/services/update.comment.service.interface'; +import { Inject, Injectable } from '@nestjs/common'; +import { CommentRepositoryInterface } from '../interfaces/repositories/comment.repository.interface'; +import { TYPES } from '../interfaces/types'; @Injectable() -export default class UpdateCommentService implements UpdateCommentService { - constructor(@InjectModel(Board.name) private boardModel: Model) {} +export default class UpdateCommentService implements UpdateCommentServiceInterface { + constructor( + @Inject(TYPES.repositories.CommentRepository) + private commentRepository: CommentRepositoryInterface + ) {} updateItemComment( boardId: string, cardId: string, cardItemId: string, commentId: string, - userId: string, text: string, anonymous: boolean ) { - return this.boardModel - .findOneAndUpdate( - { - _id: boardId, - 'columns.cards.items.comments._id': commentId - }, - { - $set: { - 'columns.$.cards.$[c].items.$[i].comments.$[com].text': text, - 'columns.$.cards.$[c].items.$[i].comments.$[com].anonymous': anonymous - } - }, - { - arrayFilters: [{ 'c._id': cardId }, { 'i._id': cardItemId }, { 'com._id': commentId }], - new: true - } - ) - .populate(BoardDataPopulate) - .lean() - .exec(); + return this.commentRepository.updateItemComment( + boardId, + cardId, + cardItemId, + commentId, + text, + anonymous + ); } updateCardGroupComment( boardId: string, cardId: string, commentId: string, - userId: string, text: string, anonymous: boolean ) { - return this.boardModel - .findOneAndUpdate( - { - _id: boardId, - 'columns.cards.comments._id': commentId - }, - { - $set: { - 'columns.$.cards.$[c].comments.$[com].text': text, - 'columns.$.cards.$[c].comments.$[com].anonymous': anonymous - } - }, - { - arrayFilters: [{ 'c._id': cardId }, { 'com._id': commentId }], - new: true - } - ) - .populate(BoardDataPopulate) - .lean() - .exec(); + return this.commentRepository.updateCardGroupComment( + boardId, + cardId, + commentId, + text, + anonymous + ); } }