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

Commit 3bc24e4

Browse files
authored
Merge pull request #1 from OS-Builders/leftcontainer
Bug Fixes UI/UX update
2 parents 110b634 + b3c2828 commit 3bc24e4

28 files changed

Lines changed: 767 additions & 143 deletions

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</head>
99
<body>
1010
<div id="root"></div>
11+
<div id="portal"></div>
1112
<script type="module" src="/src/main.tsx"></script>
1213
</body>
1314
</html>
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import User from '../models/userModel.ts';
2+
import Board from '../models/boardModel.ts';
3+
import { NextFunction, Request, Response } from 'express';
4+
import { BoardListItemState } from '../../src/types.ts';
5+
6+
const boardsController = {
7+
getMyBoards: async (req: Request, res: Response, next: NextFunction) => {
8+
try {
9+
// find all boards beloning to the user, push board names into an array and save on locals
10+
console.log('req.params.userId: ', req.params.userId);
11+
const user = await User.findOne({ _id: req.params.userId }).populate(
12+
'boards'
13+
);
14+
if (!user) {
15+
return next({
16+
log: `boardsController.getMyBoards ERROR: User cannot be found.`,
17+
status: 500,
18+
message: { err: 'Cannot find user.' },
19+
});
20+
}
21+
res.locals.boards = user.boards;
22+
return next();
23+
} catch (err) {
24+
// pass error through to global error handler
25+
return next({
26+
log: `boardssController.getMyBoards ERROR: ${err}`,
27+
status: 500,
28+
message: { err: 'Error getting my boards' },
29+
});
30+
}
31+
},
32+
getBoardNamesAndIds: async (
33+
_req: Request,
34+
res: Response,
35+
next: NextFunction
36+
) => {
37+
try {
38+
console.log('res.locals.boards: ', res.locals.boards);
39+
const namesAndIds: BoardListItemState[] = [];
40+
res.locals.boards.forEach((board: any) => {
41+
console.log('board.name: ', board.name);
42+
namesAndIds.push({
43+
name: board.name,
44+
id: board._id,
45+
});
46+
});
47+
res.locals.namesAndIds = namesAndIds;
48+
console.log('res.locals.namesAndIds: ', res.locals.namesAndIds);
49+
return next();
50+
} catch (err) {
51+
// pass error through to global error handler
52+
return next({
53+
log: `boardssController.getBoardNamesAndIds ERROR: ${err}`,
54+
status: 500,
55+
message: { err: 'Error refining boards down to names and ids' },
56+
});
57+
}
58+
},
59+
createBoard: async (req: Request, res: Response, next: NextFunction) => {
60+
try {
61+
const createdBoard = await Board.create({
62+
name: req.body.boardName,
63+
backlog: [],
64+
inProgress: [],
65+
inReview: [],
66+
completed: [],
67+
boardOwner: req.body.userId,
68+
});
69+
res.locals.createdBoard = createdBoard;
70+
return next();
71+
} catch (err) {
72+
// pass error through to global error handler
73+
return next({
74+
log: `boardssController.createBoard ERROR: ${err}`,
75+
status: 500,
76+
message: { err: 'Error creating new board' },
77+
});
78+
}
79+
},
80+
assignNewBoard: async (req: Request, res: Response, next: NextFunction) => {
81+
try {
82+
await User.updateOne(
83+
{ _id: req.body.userId },
84+
{ $push: { boards: res.locals.createdBoard._id } }
85+
);
86+
return next();
87+
} catch (err) {
88+
// pass error through to global error handler
89+
return next({
90+
log: `boardssController.assignNewBoard ERROR: ${err}`,
91+
status: 500,
92+
message: { err: 'Error assigning board to user' },
93+
});
94+
}
95+
},
96+
getCurrentBoard: async (req: Request, res: Response, next: NextFunction) => {
97+
try {
98+
// find all boards beloning to the user, push board names into an array and save on locals
99+
const board = await User.findOne({ _id: req.params.boardID });
100+
console.log(board);
101+
if (!board) {
102+
return next({
103+
log: `boardsController.getCurrentBoard ERROR: Board cannot be found.`,
104+
status: 500,
105+
message: { err: 'Cannot find board.' },
106+
});
107+
}
108+
res.locals.boardInfo = board;
109+
return next();
110+
} catch (err) {
111+
// pass error through to global error handler
112+
return next({
113+
log: `boardssController.getCurrentBoard ERROR: ${err}`,
114+
status: 500,
115+
message: { err: 'Error getting current board' },
116+
});
117+
}
118+
},
119+
};
120+
121+
export default boardsController;

server/controllers/userController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const userController = {
2626
password: hashedPassword,
2727
});
2828
// store the username on res.locals to send back to frontend
29-
res.locals.username = user.username;
29+
res.locals.user = { id: user._id, name: user.username };
3030
return next();
3131
} catch (err) {
3232
// send any errors to global error handler
@@ -72,7 +72,7 @@ const userController = {
7272
});
7373
}
7474
// passwords do match, store username in res.locals to send back to frontend
75-
res.locals.username = username;
75+
res.locals.user = { id: user._id, name: user.username };
7676
return next();
7777
}
7878
} catch (err) {

server/models/boardModel.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import mongoose from "mongoose";
2-
import { InferSchemaType } from "mongoose";
1+
import mongoose from 'mongoose';
2+
import { InferSchemaType } from 'mongoose';
33

44
const Schema = mongoose.Schema;
55

66
const boardSchema = new Schema({
7-
name: { type: String, required: true, unique: true },
8-
backlog: [{ type: Schema.Types.ObjectId, ref: "card" }],
9-
inProgress: [{ type: Schema.Types.ObjectId, ref: "card" }],
10-
inReview: [{ type: Schema.Types.ObjectId, ref: "card" }],
11-
completed: [{ type: Schema.Types.ObjectId, ref: "card" }],
12-
// boardOwner: [{ type: Schema.Types.ObjectId, required: true, ref: "User" }],
7+
name: { type: String, required: true },
8+
backlog: [{ type: Schema.Types.ObjectId, ref: 'Card' }],
9+
inProgress: [{ type: Schema.Types.ObjectId, ref: 'Card' }],
10+
inReview: [{ type: Schema.Types.ObjectId, ref: 'Card' }],
11+
completed: [{ type: Schema.Types.ObjectId, ref: 'Card' }],
12+
boardOwner: { type: Schema.Types.ObjectId, ref: 'User' },
1313
});
1414

1515
type Board = InferSchemaType<typeof boardSchema>;
1616

17-
export default mongoose.model<Board>("Board", boardSchema);
17+
export default mongoose.model<Board>('Board', boardSchema);

server/models/cardModel.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import mongoose from "mongoose";
2-
import { InferSchemaType } from "mongoose";
1+
import mongoose from 'mongoose';
2+
import { InferSchemaType } from 'mongoose';
33

44
const Schema = mongoose.Schema;
55

@@ -12,4 +12,4 @@ const cardSchema = new Schema({
1212

1313
type Card = InferSchemaType<typeof cardSchema>;
1414

15-
export default mongoose.model<Card>("Card", cardSchema);
15+
export default mongoose.model<Card>('Card', cardSchema);

server/models/userModel.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import mongoose from "mongoose";
2-
import { InferSchemaType } from "mongoose";
1+
import mongoose from 'mongoose';
2+
import { InferSchemaType } from 'mongoose';
33

44
const Schema = mongoose.Schema;
55

66
const userSchema = new Schema({
77
username: { type: String, required: true, unique: true },
88
email: { type: String, required: true, unique: true },
9-
password: { type: String, required: true, unique: true },
10-
boards: [{ type: Schema.Types.ObjectId, ref: "board" }],
9+
password: { type: String, required: true },
10+
boards: [{ type: Schema.Types.ObjectId, ref: 'Board' }],
1111
});
1212

1313
type User = InferSchemaType<typeof userSchema>;
1414

15-
export default mongoose.model<User>("User", userSchema);
15+
export default mongoose.model<User>('User', userSchema);

server/routes/boardsRouter.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import express, { Request, Response } from 'express';
2+
3+
const router = express.Router();
4+
5+
// import controllers
6+
import boardsController from '../controllers/boardsController.ts';
7+
8+
// define routes
9+
10+
// route for getting board names
11+
router.get(
12+
'/:userId',
13+
boardsController.getMyBoards,
14+
boardsController.getBoardNamesAndIds,
15+
(_req: Request, res: Response) => {
16+
return res.status(200).json(res.locals.namesAndIds);
17+
}
18+
);
19+
20+
router.get(
21+
'/:boardID',
22+
boardsController.getCurrentBoard,
23+
(_req: Request, res: Response) => {
24+
return res.status(200).json(res.locals.boardInfo);
25+
}
26+
);
27+
28+
router.post(
29+
'/create',
30+
boardsController.createBoard,
31+
boardsController.assignNewBoard,
32+
(_req: Request, res: Response) => {
33+
return res.status(200).json(res.locals.createdBoard); //may need the board just created data to render into the main container
34+
}
35+
);
36+
37+
export default router;

server/routes/userRouter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ router.post(
1212
"/signup",
1313
userController.createUser,
1414
(_req: Request, res: Response) => {
15-
return res.status(200).json(res.locals.username);
15+
return res.status(200).json(res.locals.user);
1616
}
1717
);
1818

@@ -21,7 +21,7 @@ router.post(
2121
"/login",
2222
userController.verifyUser,
2323
(_req: Request, res: Response) => {
24-
return res.status(200).json(res.locals.username);
24+
return res.status(200).json(res.locals.user);
2525
}
2626
);
2727

server/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { join, dirname } from "path";
44
import { fileURLToPath } from "url";
55
import mongoose from "mongoose";
66
import userRouter from "./routes/userRouter.ts";
7+
import boardsRouter from "./routes/boardsRouter.ts";
78

89
// start the DB
910
const mongoUri = process.env.MONGO_URI;
@@ -28,6 +29,7 @@ app.use(express.static(join(__dirname, "../dist")));
2829

2930
// route handlers
3031
app.use("/user", userRouter);
32+
app.use("/boards", boardsRouter);
3133

3234
// serve the built index.html
3335
app.use("/", (_req: Request, res: Response) => {

src/App.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
import { Route, Routes } from "react-router";
2-
import Authentication from "./routes/Authentication.tsx";
3-
import Dashboard from "./routes/Dashboard.tsx";
4-
import { useState } from "react";
1+
import { Route, Routes } from 'react-router';
2+
import Authentication from './routes/Authentication.tsx';
3+
import Dashboard from './routes/Dashboard.tsx';
4+
import { useState } from 'react';
5+
import { UserState } from './types.ts';
56

67
function App() {
78
// track the username in state
8-
const [username, setUsername] = useState<string>("");
9-
9+
const [user, setUser] = useState<UserState>({
10+
name: '',
11+
id: '',
12+
});
1013
return (
1114
<Routes>
12-
<Route path="/" element={<Authentication setUsername={setUsername} />} />
13-
<Route path="/dashboard" element={<Dashboard username={username} />} />
15+
<Route path='/' element={<Authentication setUser={setUser} />} />
16+
<Route path='/dashboard' element={<Dashboard user={user} />} />
1417
</Routes>
1518
);
1619
}

0 commit comments

Comments
 (0)