Skip to content
This repository was archived by the owner on Mar 21, 2026. It is now read-only.

Commit 3517725

Browse files
committed
finishes board delete and edit
1 parent ed7daa9 commit 3517725

6 files changed

Lines changed: 64 additions & 4 deletions

File tree

server/controllers/boardsController.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ const boardsController = {
144144
await Board.findOneAndDelete({
145145
_id: req.params.boardId,
146146
});
147+
console.log("board deleted");
147148
return next();
148149
} catch (err) {
149150
// pass error through to global error handler
@@ -154,6 +155,43 @@ const boardsController = {
154155
});
155156
}
156157
},
158+
editBoard: async (req: Request, res: Response, next: NextFunction) => {
159+
try {
160+
const editedBoard = await Board.findByIdAndUpdate(
161+
req.body.id,
162+
{
163+
name: req.body.name,
164+
},
165+
{ new: true }
166+
);
167+
console.log("editedBoard: ", editedBoard);
168+
res.locals.board = editedBoard;
169+
return next();
170+
} catch (err) {
171+
// pass error through to global error handler
172+
return next({
173+
log: `tasksController.editBoard ERROR: ${err}`,
174+
status: 500,
175+
message: { err: "Error editing Board" },
176+
});
177+
}
178+
},
179+
pullBoard: async (req: Request, res: Response, next: NextFunction) => {
180+
try {
181+
await User.updateOne(
182+
{ _id: res.locals.board.boardOwner },
183+
{ $pull: { boards: req.params.boardId } }
184+
);
185+
return next();
186+
} catch (err) {
187+
// pass error through to global error handler
188+
return next({
189+
log: `tasksController.pullTask ERROR: ${err}`,
190+
status: 500,
191+
message: { err: "Error pulling Task" },
192+
});
193+
}
194+
},
157195
};
158196

159197
export default boardsController;

server/routes/boardsRouter.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,25 @@ router.post(
3636
}
3737
);
3838

39-
// route for deleting a task card
39+
// route for deleting a boardd
4040
router.delete(
4141
"/delete/:boardId",
4242
boardsController.getBoardFromId,
4343
tasksController.clearTask,
4444
boardsController.deleteBoard,
45+
boardsController.pullBoard,
4546
(_req: Request, res: Response) => {
4647
return res.status(200).json();
4748
}
4849
);
4950

51+
// route for editing a board
52+
router.put(
53+
"/edit",
54+
boardsController.editBoard,
55+
(_req: Request, res: Response) => {
56+
return res.status(200).json(res.locals.board);
57+
}
58+
);
59+
5060
export default router;

src/components/CreateBoardModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const CreateBoardModal = ({
8686
</button>
8787
<button
8888
className="modal-cancel"
89+
type="button"
8990
onClick={() => {
9091
setCreatingBoard(false);
9192
}}

src/components/EditBoardModal.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const EditBoardModal = ({
1919
e.preventDefault();
2020
// send put request to /boards/edit with new boardName and id in body
2121
const body = {
22-
boardName: boardName,
22+
name: boardName,
2323
id: currentBoard.id,
2424
};
2525
const response: Response = await fetch("/boards/edit", {
@@ -83,13 +83,18 @@ const EditBoardModal = ({
8383
</button>
8484
<button
8585
className="modal-cancel"
86+
type="button"
8687
onClick={() => {
8788
setEditingBoard(false);
8889
}}
8990
>
9091
Cancel
9192
</button>
92-
<button className="modal-delete" onClick={handleDeleteBoard}>
93+
<button
94+
className="modal-delete"
95+
onClick={handleDeleteBoard}
96+
type="button"
97+
>
9398
Delete
9499
</button>
95100
</div>

src/components/EditTaskModal.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,18 @@ const EditTaskModal = ({
169169
</button>
170170
<button
171171
className="modal-cancel"
172+
type="button"
172173
onClick={() => {
173174
setEditingTask(null);
174175
}}
175176
>
176177
Cancel
177178
</button>
178-
<button className="modal-delete" onClick={handleDeleteTask}>
179+
<button
180+
className="modal-delete"
181+
type="button"
182+
onClick={handleDeleteTask}
183+
>
179184
Delete
180185
</button>
181186
</div>

src/components/NewTaskModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ const NewTaskModal = ({
123123
</button>
124124
<button
125125
className="modal-cancel"
126+
type="button"
126127
onClick={() => {
127128
setAddingTask(false);
128129
}}

0 commit comments

Comments
 (0)