Skip to content

Commit efc1b9d

Browse files
authored
Merge pull request #59 from F-Code-Project-Mini/chore/change-logic
Chore/change logic
2 parents 2b2cb87 + 0eaa1cf commit efc1b9d

13 files changed

Lines changed: 629 additions & 41 deletions

File tree

backend/src/controllers/team.controllers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const getAll = async (req: Request, res: Response, next: NextFunction) =>
2626

2727
export const getDetail = async (req: Request<{ id: string }>, res: Response, next: NextFunction) => {
2828
try {
29-
const result = await teamService.getDetail(req.params.id);
29+
const result = await teamService.getDetail(req.params.id, req.role as RoleType);
3030
return res.status(HTTP_STATUS.OK).json(new ResponseClient({ result }));
3131
} catch (error) {
3232
return next(error);
@@ -117,7 +117,6 @@ export const getTeamsByMentor = async (req: Request, res: Response, next: NextFu
117117
}
118118
};
119119
export const changeName = async (req: Request<{ id: string }>, res: Response, next: NextFunction) => {
120-
console.log("req.body", "Đã ghi nhanan n");
121120
const { name } = req.body;
122121
const { userId } = req;
123122
try {

backend/src/repositories/team.repository.ts

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
import prisma from "~/configs/prisma";
22
import { paginate } from "~/utils/pagination";
33
import userRespository from "./user.repository";
4+
import { RoleType } from "~/constants/enums";
45

56
class TeamRepository {
6-
findWithPagination = async ({ page, limit, mentorId }: { page?: number; limit?: number; mentorId?: string }) => {
7+
findWithPagination = async () => {
78
const includeUser = {
89
omit: {
910
password: true,
1011
candidateId: true,
12+
email: true,
13+
role: true,
14+
createdAt: true,
15+
updatedAt: true,
1116
},
1217
};
1318
const include = {
1419
candidates: {
1520
include: {
1621
user: includeUser,
1722
},
23+
omit: {
24+
phone: true,
25+
// major: true,
26+
semester: true,
27+
mentorNote: true,
28+
createdAt: true,
29+
updatedAt: true,
30+
teamId: true,
31+
},
1832
},
1933
mentorship: {
2034
select: {
@@ -31,17 +45,27 @@ class TeamRepository {
3145
topic: true,
3246
};
3347

34-
const { data, meta } = await paginate<any>(prisma.team, {
35-
page,
36-
limit,
37-
orderBy: { id: "desc" },
48+
// const { data, meta } = await paginate<any>(prisma.team, {
49+
// page,
50+
// limit,
51+
// orderBy: { id: "desc" },
52+
// include,
53+
// omit: {
54+
// mentorNote: true,
55+
// },
56+
// });
57+
const data = prisma.team.findMany({
58+
orderBy: { group: "asc" },
3859
include,
60+
omit: {
61+
mentorNote: true,
62+
},
3963
});
4064

41-
return { teams: data, meta };
65+
return data;
4266
};
4367

44-
findByIdWithMembers = async (id: string, displayScore: boolean = false) => {
68+
findByIdWithMembers = async (id: string, displayScore: boolean = false, role: RoleType) => {
4569
const include = {
4670
candidates: {
4771
omit: {
@@ -72,12 +96,13 @@ class TeamRepository {
7296
},
7397
topic: true,
7498
};
99+
console.log("role", role);
75100

76101
let team = await prisma.team.findUnique({
77102
where: { id },
78103
include,
79104
omit: {
80-
// mentorNote: true,
105+
...([RoleType.MENTOR, RoleType.ADMIN].includes(role) ? {} : { mentorNote: true }),
81106
},
82107
});
83108

@@ -127,7 +152,7 @@ class TeamRepository {
127152
const data = [];
128153
console.log("mentorTeams", mentorTeams);
129154
for (const t of mentorTeams) {
130-
data.push(await this.findByIdWithMembers(t.id, displayScore));
155+
data.push(await this.findByIdWithMembers(t.id, displayScore, RoleType.MENTOR));
131156
}
132157
return data;
133158
};

backend/src/services/team.service.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,13 @@ class TeamService {
2121
const safeLimit = Number.isFinite(limitNum) && limitNum > 0 ? limitNum : 10;
2222

2323
const mentorId = role === RoleType.MENTOR ? userId : undefined;
24-
const { teams, meta } = await teamRepository.findWithPagination({
25-
page: safePage,
26-
limit: safeLimit,
27-
mentorId,
28-
});
24+
const data = await teamRepository.findWithPagination();
2925

30-
return {
31-
data: teams,
32-
pagination: {
33-
total: meta.total,
34-
page: meta.page,
35-
limit: meta.limit,
36-
},
37-
};
26+
return data;
3827
}
3928

40-
async getDetail(id: string) {
41-
const team = await teamRepository.findByIdWithMembers(id);
29+
async getDetail(id: string, role: RoleType) {
30+
const team = await teamRepository.findByIdWithMembers(id, false, role);
4231
if (!team) {
4332
throw new ErrorWithStatus({
4433
status: HTTP_STATUS.NOT_FOUND,

frontend/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ import MentorBaremPage from "./pages/Mentor/Barem";
1515
import AdminPage from "./pages/Admin";
1616
import ReportsPage from "./pages/Admin/Reports";
1717
import CandidatePages from "./pages/Admin/Candidates";
18+
import TeamPage from "./pages/Teams";
1819
const App = () => {
1920
return (
2021
<BrowserRouter>
2122
<Routes>
2223
<Route path="/" element={<MainLayout />}>
2324
<Route index element={<IndexPage />} />
2425
<Route path="login" element={<LoginPage />} />
26+
<Route path="teams" element={<TeamPage />} />
2527
<Route path="active/token/:token" element={<ActivePage />} />
2628
<Route path="submissions" element={<SubmissionsPage />} />
2729

frontend/src/api-requests/team.requests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { ResponseDetailData, ResponsePaginate, TeamType } from "~/types/team.types";
1+
import type { ResponseDetailData, TeamType } from "~/types/team.types";
22
import { privateApi } from "~/utils/axiosInstance";
33

44
class TeamApi {
55
static async getAllTeams() {
6-
const res = await privateApi.get<ResponsePaginate<TeamType[]>>("/teams");
6+
const res = await privateApi.get<ResponseDetailData<TeamType[]>>("/teams");
77
return res.data;
88
}
99

frontend/src/components/Header/Candidate.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
11
import { NavLink } from "./NavLink";
22
import { ServerCrash } from "lucide-react";
3-
// import { useLocation } from "react-router";
4-
// import Helper from "~/utils/helper";
53

64
const CandidateHeader = () => {
75
// const location = useLocation();
86
return (
97
<>
10-
{/* <li id="submissions">
11-
<NavLink
12-
url="/submissions"
13-
name="Nộp đề tài"
14-
Icon={Send}
15-
active={Helper.isActive(location.pathname, "/submissions")}
16-
/>
17-
</li> */}
18-
198
<li>
209
<NavLink url="https://discord.gg/WvudrJaYD" name="Hỗ trợ" Icon={ServerCrash} target="_blank" />
2110
</li>

frontend/src/components/Header/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BadgeQuestionMark, ChevronDown, House, Menu, X } from "lucide-react";
1+
import { BadgeQuestionMark, ChevronDown, House, Menu, Users, X } from "lucide-react";
22
import { Link, useLocation } from "react-router";
33
import useAuth from "~/hooks/useAuth";
44
import { useState, useRef, useEffect } from "react";
@@ -61,6 +61,14 @@ const Header = () => {
6161
active={Helper.isActive(location.pathname, "/")}
6262
/>
6363
</li>
64+
<li id="submissions">
65+
<NavLink
66+
url="/teams"
67+
name="Danh sách nhóm"
68+
Icon={Users}
69+
active={Helper.isActive(location.pathname, "/teams")}
70+
/>
71+
</li>
6472
{isLogin && user.role === USER_ROLE.CANDIDATE && <CandidateHeader />}
6573
{isLogin && user.role === USER_ROLE.ADMIN && <AdminHeader />}
6674
</ul>

0 commit comments

Comments
 (0)