Skip to content

Commit 7a709a4

Browse files
authored
Merge pull request #57 from F-Code-Project-Mini/dev
Dev
2 parents 6214ee6 + 2b2cb87 commit 7a709a4

9 files changed

Lines changed: 125 additions & 19 deletions

File tree

backend/src/controllers/team.controllers.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,18 @@ export const getTeamByUserId = async (req: Request<{ id: string }>, res: Respons
6161
// }
6262
// };
6363

64-
export const update = async (req: Request<{ id: string }>, res: Response, next: NextFunction) => {
64+
export const update = async (
65+
req: Request<{ id: string }, any, { note: string }>,
66+
res: Response,
67+
next: NextFunction,
68+
) => {
6569
try {
6670
const { id } = req.params;
67-
const { topic_id, mentorship_id } = req.body as {
68-
topic_id?: string;
69-
mentorship_id?: string;
70-
};
71-
const result = await teamService.update(id, { topic_id, mentorship_id });
72-
return res.status(HTTP_STATUS.OK).json(new ResponseClient({ message: "Cập nhật team thành công!", result }));
71+
const { note } = req.body;
72+
const result = await teamService.update(id, { note });
73+
return res
74+
.status(HTTP_STATUS.OK)
75+
.json(new ResponseClient({ message: "Cập nhật thông tin thành công!", result }));
7376
} catch (error) {
7477
return next(error);
7578
}

backend/src/repositories/team.repository.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class TeamRepository {
7777
where: { id },
7878
include,
7979
omit: {
80-
mentorNote: true,
80+
// mentorNote: true,
8181
},
8282
});
8383

@@ -132,13 +132,12 @@ class TeamRepository {
132132
return data;
133133
};
134134

135-
update = async (id: string, data: { name?: string; topicId?: string; mentorshipId?: string }) => {
135+
update = async (id: string, data: { name?: string; note?: string }) => {
136136
return prisma.team.update({
137137
where: { id },
138138
data: {
139-
...(data.topicId ? { topicId: data.topicId } : {}),
140-
...(data.mentorshipId ? { mentorshipId: data.mentorshipId } : {}),
141139
...(data.name ? { name: data.name } : {}),
140+
...(data.note ? { mentorNote: data.note } : {}),
142141
},
143142
});
144143
};

backend/src/routes/team.routes.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import { validate } from "~/utils/validation";
33
import { RoleType } from "~/constants/enums";
44
import * as teamController from "~/controllers/team.controllers";
55
import { auth, isRole } from "~/middlewares/auth.middlewares";
6-
import { changeNameSchema, getAllSchema, idParamSchema, uuidParamsAndBodySchema } from "~/rules/auth/auth.schema";
6+
import {
7+
changeNameSchema,
8+
getAllSchema,
9+
idParamSchema,
10+
noteBodySchema,
11+
uuidParamsAndBodySchema,
12+
} from "~/rules/auth/auth.schema";
713
const teamRouter = Router();
814

915
// teamRouter.get("/", auth, isRole([RoleType.ADMIN, RoleType.MENTOR]), validate(getAllSchema), teamController.getAll);
@@ -22,7 +28,14 @@ teamRouter.patch(
2228
validate(changeNameSchema),
2329
teamController.changeName,
2430
);
25-
teamRouter.patch("/:id", auth, isRole([RoleType.ADMIN]), validate(idParamSchema), teamController.update);
31+
teamRouter.patch(
32+
"/:id",
33+
auth,
34+
isRole([RoleType.MENTOR]),
35+
validate(idParamSchema),
36+
validate(noteBodySchema),
37+
teamController.update,
38+
);
2639
teamRouter.delete("/:id", auth, isRole([RoleType.ADMIN]), validate(idParamSchema), teamController.deleteTeam);
2740

2841
teamRouter.patch(

backend/src/rules/auth/auth.schema.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,9 @@ export const changeNameSchema = z.object({
6464
.max(50, "Tên nhóm không được vượt quá 50 ký tự!"),
6565
}),
6666
});
67+
68+
export const noteBodySchema = z.object({
69+
body: z.object({
70+
note: z.string().trim().nonempty("Ghi chú không được để trống!"),
71+
}),
72+
});

backend/src/services/team.service.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class TeamService {
6767
// return team;
6868
// }
6969

70-
async update(id: string, body: { topic_id?: string; mentorship_id?: string }) {
70+
async update(id: string, body: { note: string }) {
7171
const existed = await teamRepository.findById(id);
7272
if (!existed) {
7373
throw new ErrorWithStatus({
@@ -77,8 +77,7 @@ class TeamService {
7777
}
7878

7979
const updated = await teamRepository.update(id, {
80-
topicId: body.topic_id ?? existed.topicId,
81-
mentorshipId: body.mentorship_id ?? existed.mentorshipId,
80+
note: body.note,
8281
});
8382
return updated;
8483
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class MentorApi {
77
const res = await privateApi.get<ResponseDetailData<BaremResultItem[]>>(`/mentor/get-barem/${candidateId}`);
88
return res.data;
99
}
10-
static async updateNote(candidateId: string, note: string, codeBarem: string) {
11-
const res = await privateApi.patch(`/mentor/candidates/${candidateId}/note`, { note, codeBarem });
10+
static async updateNoteTeam(teamId: string, note: string) {
11+
const res = await privateApi.patch(`/teams/${teamId}`, { note });
1212
return res.data;
1313
}
1414
}

frontend/src/pages/Mentor/Barem/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const MentorBaremPage = () => {
3434
},
3535
enabled: !!params.id,
3636
});
37-
const isLeader = params?.candidateId === candidates?.leader.id;
37+
const isLeader = params?.candidateId === candidates?.leader?.id;
3838
// console.log("isLeader", params?.candidateId, isLeader);
3939

4040
const [candidateActive, setcandidateActive] = useState<CandidateType | undefined>(undefined);

frontend/src/pages/Mentor/Note.tsx

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { useMutation } from "@tanstack/react-query";
2+
import type { AxiosError } from "axios";
3+
import { Check, NotebookPen } from "lucide-react";
4+
import { useState } from "react";
5+
import MentorApi from "~/api-requests/mentor.requests";
6+
7+
import {
8+
AlertDialog,
9+
AlertDialogAction,
10+
AlertDialogCancel,
11+
AlertDialogContent,
12+
AlertDialogFooter,
13+
AlertDialogHeader,
14+
AlertDialogTitle,
15+
AlertDialogTrigger,
16+
} from "~/components/ui/alert-dialog";
17+
18+
import { Textarea } from "~/components/ui/textarea";
19+
import Notification from "~/utils/notification";
20+
type NoteProps = {
21+
note: string;
22+
teamId: string;
23+
};
24+
export function NoteTeam({ note, teamId }: NoteProps) {
25+
const [noteValue, setNoteValue] = useState(note || "");
26+
const noteUpdateMutation = useMutation({
27+
mutationKey: ["update-mentor-note", teamId],
28+
mutationFn: (newNote: string) => MentorApi.updateNoteTeam(teamId, newNote),
29+
onSuccess: () => {
30+
Notification.success({
31+
text: "Thay đổi ghi chú nhóm thành công!",
32+
});
33+
},
34+
onError: (error: AxiosError<{ message?: string }>) => {
35+
Notification.error({
36+
text: error.response?.data?.message || "Thay đổi ghi chú nhóm thất bại!",
37+
});
38+
},
39+
});
40+
return (
41+
<AlertDialog>
42+
<AlertDialogTrigger asChild>
43+
<div className="relative cursor-pointer rounded-xl border-2 px-4 py-2">
44+
<div className="flex items-center gap-1">
45+
{note ? (
46+
<div className="absolute -top-2 -right-2 flex h-3 w-3 items-center justify-center rounded-full bg-green-500 text-white">
47+
<Check />
48+
</div>
49+
) : null}
50+
<span className="text-sm font-semibold">Ghi chú nhóm</span>
51+
<NotebookPen size={20} />
52+
</div>
53+
</div>
54+
</AlertDialogTrigger>
55+
<AlertDialogContent>
56+
<AlertDialogHeader>
57+
<AlertDialogTitle>Ghi chú</AlertDialogTitle>
58+
59+
<Textarea
60+
placeholder="Ghi chú ...."
61+
onChange={(e) => {
62+
setNoteValue(e.target.value);
63+
}}
64+
value={noteValue}
65+
className="min-h-[120px] text-base"
66+
/>
67+
<span className="text-sm italic">
68+
Ghi chú này giúp CLB đánh giá hiệu quả làm việc của nhóm. Các bạn vui lòng nhận xét công tâm để
69+
CLB chọn lọc được những thành viên phù hợp nhất.
70+
</span>
71+
</AlertDialogHeader>
72+
<AlertDialogFooter>
73+
<AlertDialogCancel>Đóng</AlertDialogCancel>
74+
<AlertDialogAction
75+
className="bg-black text-white"
76+
onClick={() => noteUpdateMutation.mutate(noteValue)}
77+
>
78+
Lưu
79+
</AlertDialogAction>
80+
</AlertDialogFooter>
81+
</AlertDialogContent>
82+
</AlertDialog>
83+
);
84+
}

frontend/src/pages/Mentor/Team.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import NotifyNotLeader from "~/components/NotifyNotLeader";
77
import { ShowTopic } from "../Candidate/ShowTopic";
88
import Helper from "~/utils/helper";
99
import BadgeLeader from "~/components/BadgeLeader";
10+
import { NoteTeam } from "./Note";
1011
const Team = ({ team }: { team: TeamType }) => {
1112
return (
1213
<section className="col-span-1 lg:col-span-8" id="members">
@@ -35,6 +36,7 @@ const Team = ({ team }: { team: TeamType }) => {
3536
<div className="flex flex-wrap items-center gap-2">
3637
<ShowTopic urlPdf={team.topic.filePath} name={team.topic.title} />
3738
<ChoiceLeader team={team} />
39+
<NoteTeam note={team.mentorNote || ""} teamId={team.id} />
3840

3941
{/* <Link to={`/mentor/team/${team.id}`}>
4042
<Button

0 commit comments

Comments
 (0)