Skip to content

Commit ad4e022

Browse files
committed
feat: add submission retrieval for teams; implement API and UI updates for submission handling
1 parent 4be221f commit ad4e022

7 files changed

Lines changed: 65 additions & 9 deletions

File tree

backend/src/controllers/team.controllers.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,21 @@ export const getSchedulePresentation = async (
5959
return next(error);
6060
}
6161
};
62-
62+
export const getSubmissionInTeam = async (
63+
req: Request<ParamsDictionary, {}, { teamId: string }>,
64+
res: Response,
65+
next: NextFunction,
66+
) => {
67+
try {
68+
const userId = req.userId!;
69+
const { teamId } = req.params;
70+
console.log("teamId", userId, teamId);
71+
const result = await teamService.getSubmissionInTeam(userId, teamId);
72+
return res.status(HTTP_STATUS.OK).json(new ResponseClient({ result }));
73+
} catch (error) {
74+
return next(error);
75+
}
76+
};
6377
export const createSubmission = async (
6478
req: Request<ParamsDictionary, {}, SubmissionType>,
6579
res: Response,

backend/src/repositories/team.repository.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ class TeamRepository {
274274
findAllPresentationSchedules = async () => {
275275
return prisma.schedulePresent.findMany();
276276
};
277+
findSubmissionByTeamId = async (teamId: string) => {
278+
return prisma.submission.findMany({
279+
where: {
280+
teamId,
281+
},
282+
});
283+
};
277284
createSubmission = async (userId: string, data: SubmissionType) => {
278285
return prisma.submission.create({
279286
data: new Submission({

backend/src/routes/team.routes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const teamRouter = Router();
1616
teamRouter.get("/", auth, validate(getAllSchema), teamController.getAll);
1717
teamRouter.post("/present", auth, teamController.createSchedulePresentation);
1818

19+
teamRouter.get("/:teamId/submissions", auth, teamController.getSubmissionInTeam);
1920
teamRouter.post("/:teamId/submissions", auth, teamController.createSubmission);
2021

2122
// get các lịch đã có thể đăng ký

backend/src/services/team.service.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,24 @@ class TeamService {
251251
};
252252
}
253253

254+
getSubmissionInTeam = async (userId: string, teamId: string) => {
255+
const isMember = await teamRepository.isMember(teamId, userId);
256+
if (!isMember) {
257+
throw new ErrorWithStatus({
258+
status: HTTP_STATUS.FORBIDDEN,
259+
message: "Bạn không có quyền xem submission của nhóm này.",
260+
});
261+
}
262+
const submission = await teamRepository.findSubmissionByTeamId(teamId);
263+
if (!submission) {
264+
throw new ErrorWithStatus({
265+
status: HTTP_STATUS.NOT_FOUND,
266+
message: "Submission của nhóm không tồn tại.",
267+
});
268+
}
269+
return submission;
270+
};
271+
254272
createSubmission = async ({
255273
userId,
256274
teamId,

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {
33
ResponseDetailData,
44
ScheduleDateType,
55
SchedulePresentType,
6+
SubmissionType,
67
TeamType,
78
} from "~/types/team.types";
89
import { privateApi } from "~/utils/axiosInstance";
@@ -60,9 +61,17 @@ class TeamApi {
6061
return res.data;
6162
}
6263

63-
static async submissions(teamId: string) {
64+
static async getSubmissionInTeam(teamId: string) {
6465
const res = await privateApi.get<ResponseDetailData<{ submissionUrl: string }>>(`/teams/${teamId}/submissions`);
6566
return res.data;
6667
}
68+
69+
static async submissions(teamId: string, data: SubmissionType) {
70+
const res = await privateApi.post<ResponseDetailData<{ submissionUrl: string }>>(
71+
`/teams/${teamId}/submissions`,
72+
data,
73+
);
74+
return res.data;
75+
}
6776
}
6877
export default TeamApi;

frontend/src/pages/Submissions/FormSubmit.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ const FormSubmit = () => {
2121
<form onSubmit={handleSubmit} className="space-y-6 p-5 sm:p-6">
2222
{/* Product Link */}
2323
<div className="space-y-2">
24-
<label htmlFor="productLink" className="flex items-center gap-2 text-sm font-medium text-gray-700">
24+
<label
25+
htmlFor="presentationLink"
26+
className="flex items-center gap-2 text-sm font-medium text-gray-700"
27+
>
2528
<Link2 className="h-4 w-4 text-gray-400" />
2629
Link sản phẩm (Bao gồm slide .pptx, Sheet phân công .xlsx)
2730
<span className="text-red-500">*</span>
2831
</label>
2932
<Input
30-
id="productLink"
33+
id="presentationLink"
3134
type="url"
3235
placeholder="https://drive.google.com/..."
3336
className="focus:ring-primary/20 transition-all focus:ring-2"
@@ -41,12 +44,12 @@ const FormSubmit = () => {
4144

4245
{/* Code Link */}
4346
<div className="space-y-2">
44-
<label htmlFor="codeLink" className="flex items-center gap-2 text-sm font-medium text-gray-700">
47+
<label htmlFor="productLink" className="flex items-center gap-2 text-sm font-medium text-gray-700">
4548
<Github className="h-4 w-4 text-gray-400" />
4649
Link source/Figma (Nếu đề tài yêu cầu sản phẩm)
4750
</label>
4851
<Input
49-
id="codeLink"
52+
id="productLink"
5053
type="url"
5154
placeholder="GitHub, GitLab, Figma..."
5255
className="focus:ring-primary/20 transition-all focus:ring-2"
@@ -55,12 +58,12 @@ const FormSubmit = () => {
5558

5659
{/* Description */}
5760
<div className="space-y-2">
58-
<label htmlFor="description" className="flex items-center gap-2 text-sm font-medium text-gray-700">
61+
<label htmlFor="note" className="flex items-center gap-2 text-sm font-medium text-gray-700">
5962
<FileText className="h-4 w-4 text-gray-400" />
6063
Ghi chú
6164
</label>
6265
<Textarea
63-
id="description"
66+
id="note"
6467
placeholder="Mô tả ngắn về sản phẩm, tính năng nổi bật, công nghệ sử dụng..."
6568
className="focus:ring-primary/20 min-h-[120px] resize-none transition-all focus:ring-2"
6669
// rows={5}

frontend/src/types/team.types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export type ScheduleDateType = {
8585
slots: TimeSlotType[];
8686
};
8787

88-
8988
export type OfficialTimeSlotType = {
9089
time: string;
9190
};
@@ -95,3 +94,8 @@ export type OfficialScheduleDateType = {
9594
slots: OfficialTimeSlotType[];
9695
};
9796

97+
export type SubmissionType = {
98+
presentationLink: string;
99+
productLink: string;
100+
note: string;
101+
};

0 commit comments

Comments
 (0)