Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update text, comment and vote actions in the card group #99

Merged
merged 6 commits into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions backend/src/libs/dto/param/vote.group.params.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { IsMongoId, IsString } from 'class-validator';
import { CardGroupParams } from './card.group.params';

export class VoteGroupParams extends CardGroupParams {
@IsMongoId()
@IsString()
userId!: string;
}
export class VoteGroupParams extends CardGroupParams {}
2 changes: 2 additions & 0 deletions backend/src/libs/utils/arrayIdToString.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const arrayIdToString = (array: string[]) =>
array.map((item) => item.toString());
14 changes: 14 additions & 0 deletions backend/src/modules/cards/applications/update.card.application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,18 @@ export class UpdateCardApplicationImpl implements UpdateCardApplication {
text,
);
}

updateCardGroupText(
boardId: string,
cardId: string,
userId: string,
text: string,
) {
return this.updateCardService.updateCardGroupText(
boardId,
cardId,
userId,
text,
);
}
}
38 changes: 30 additions & 8 deletions backend/src/modules/cards/controller/cards.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ import JwtAuthenticationGuard from '../../../libs/guards/jwtAuth.guard';
import SocketGateway from '../../socket/gateway/socket.gateway';
import { CreateCardDto } from '../dto/create.card.dto';
import DeleteCardDto from '../dto/delete.card.dto';
import { CreateCardParams } from '../dto/params/create.card.params';
import { DeleteCardParams } from '../dto/params/delete.card.params';
import { UpdateCardParams } from '../dto/params/update-position.card.params';
import { UpdatePositionCardParams } from '../dto/params/update-text.card.params copy';
import UpdateCardDto from '../dto/update.card.dto';
import { UpdateCardPositionDto } from '../dto/update-position.card..dto';
import { CreateCardApplication } from '../interfaces/applications/create.card.application.interface';
Expand All @@ -35,6 +31,9 @@ import { BaseDto } from '../../../libs/dto/base.dto';
import { MergeCardsParams } from '../../../libs/dto/param/merge.cards.params';
import { UnmergeCardsParams } from '../../../libs/dto/param/unmerge.cards.params';
import UnmergeCardsDto from '../dto/unmerge.dto';
import { BaseParam } from '../../../libs/dto/param/base.param';
import { CardGroupParams } from '../../../libs/dto/param/card.group.params';
import { CardItemParams } from '../../../libs/dto/param/card.item.params';

@Controller('boards')
export default class CardsController {
Expand All @@ -57,7 +56,7 @@ export default class CardsController {
async addCard(
@Req() request,
@Param()
params: CreateCardParams,
params: BaseParam,
@Body() createCardDto: CreateCardDto,
) {
const {
Expand All @@ -81,7 +80,7 @@ export default class CardsController {
async deleteCard(
@Req() request,
@Param()
params: DeleteCardParams,
params: CardGroupParams,
@Body() deleteCardDto: DeleteCardDto,
) {
const {
Expand All @@ -99,7 +98,7 @@ export default class CardsController {
async updateCardText(
@Req() request,
@Param()
params: UpdateCardParams,
params: CardItemParams,
@Body() updateCardDto: UpdateCardDto,
) {
const {
Expand All @@ -119,11 +118,34 @@ export default class CardsController {
return board;
}

@UseGuards(JwtAuthenticationGuard)
@Put(':boardId/card/:cardId')
async updateCardGroupText(
@Req() request,
@Param() params: CardGroupParams,
@Body() updateCardDto: UpdateCardDto,
) {
const { boardId, cardId } = params;
const {
user: { _id: userId },
} = request;
const { text } = updateCardDto;
const board = await this.updateCardApp.updateCardGroupText(
boardId,
cardId,
userId,
text,
);
if (!board) throw new BadRequestException(UPDATE_FAILED);
this.socketService.sendUpdatedBoard(board, updateCardDto.socketId);
return board;
}

@Put(':boardId/card/:cardId/updateCardPosition')
async updateCardPosition(
@Req() request,
@Param()
params: UpdatePositionCardParams,
params: CardGroupParams,
@Body() boardData: UpdateCardPositionDto,
) {
const { boardId, cardId } = params;
Expand Down
3 changes: 0 additions & 3 deletions backend/src/modules/cards/dto/params/create.card.params.ts

This file was deleted.

7 changes: 0 additions & 7 deletions backend/src/modules/cards/dto/params/delete.card.params.ts

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ export interface UpdateCardApplication {
userId: string,
text: string,
): Promise<LeanDocument<BoardDocument> | null>;
updateCardGroupText(
boardId: string,
cardId: string,
userId: string,
text: string,
): Promise<LeanDocument<BoardDocument> | null>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ export interface UpdateCardService {
userId: string,
text: string,
): Promise<LeanDocument<BoardDocument> | null>;
updateCardGroupText(
boardId: string,
cardId: string,
userId: string,
text: string,
): Promise<LeanDocument<BoardDocument> | null>;
}
14 changes: 8 additions & 6 deletions backend/src/modules/cards/services/unmerge.card.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ export class UnmergeCardServiceImpl implements UnmergeCardService {
);
if (!cardGroup) throw Error(CARD_NOT_FOUND);

const { text, comments, votes: itemVotes } = cardGroup.items[0];
const newComments = cardGroup.comments.concat(comments);
const newVotes = (cardGroup.votes as unknown as string[]).concat(
itemVotes as unknown as string[],
const items = cardGroup.items.filter(
(item) => item._id.toString() !== draggedCardId,
);

if (cardGroup.items.length === 1) {
if (items.length === 1) {
const [{ text, comments, votes: itemVotes }] = items;
const newComments = cardGroup.comments.concat(comments);
const newVotes = (cardGroup.votes as unknown as string[]).concat(
itemVotes as unknown as string[],
);
const updateResult = await this.boardModel
.updateOne(
{
Expand Down
26 changes: 26 additions & 0 deletions backend/src/modules/cards/services/update.card.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,30 @@ export default class UpdateCardServiceImpl implements UpdateCardService {
.lean()
.exec();
}

updateCardGroupText(
boardId: string,
cardId: string,
userId: string,
text: string,
) {
return this.boardModel
.findOneAndUpdate(
{
_id: boardId,
'columns.cards._id': cardId,
},
{
$set: {
'columns.$.cards.$[c].text': text,
},
},
{
arrayFilters: [{ 'c._id': cardId, 'c.createdBy': userId }],
new: true,
},
)
.lean()
.exec();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,18 @@ export class CreateCommentApplicationImpl implements CreateCommentApplication {
text,
);
}

createCardGroupComment(
boardId: string,
cardId: string,
userId: string,
text: string,
) {
return this.createCommentService.createCardGroupComment(
boardId,
cardId,
userId,
text,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ export class DeleteCommentApplicationImpl implements DeleteCommentApplication {
userId,
);
}

deleteCardGroupComment(boardId: string, commentId: string, userId: string) {
return this.deleteCommentService.deleteCardGroupComment(
boardId,
commentId,
userId,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,20 @@ export class UpdateCommentApplicationImpl implements UpdateCommentApplication {
text,
);
}

updateCardGroupComment(
boardId: string,
cardId: string,
commentId: string,
userId: string,
text: string,
) {
return this.updateCommentService.updateCardGroupComment(
boardId,
cardId,
commentId,
userId,
text,
);
}
}
Loading