Skip to content

Commit 4be221f

Browse files
committed
feat: update submission handling to include teamId in route and enhance submission schema; add API request for fetching submissions
1 parent 035b178 commit 4be221f

6 files changed

Lines changed: 34 additions & 9 deletions

File tree

backend/src/controllers/team.controllers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ export const createSubmission = async (
6767
) => {
6868
try {
6969
const userId = req.userId!;
70-
const { teamId, presentationLink, productLink, note } = req.body;
70+
const { presentationLink, productLink, note } = req.body;
71+
const { teamId } = req.params;
7172
console.log("teamId, presentationLink, productLink, note", teamId, presentationLink, productLink, note);
7273
const result = await teamService.createSubmission({
7374
userId,
@@ -78,7 +79,7 @@ export const createSubmission = async (
7879
});
7980
return res
8081
.status(HTTP_STATUS.CREATED)
81-
.json(new ResponseClient({ message: "Tạo submission thành công!", result }));
82+
.json(new ResponseClient({ message: "Đã gửi yêu cầu nộp sản phẩm thành công!", result }));
8283
} catch (error) {
8384
return next(error);
8485
}

backend/src/repositories/team.repository.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import userRespository from "./user.repository";
44
import { RoleType } from "~/constants/enums";
55
import Present from "~/schemas/schedule-present.schema";
66
import SchedulePresent from "~/schemas/schedule-present.schema";
7+
import Submission from "~/schemas/submission.schema";
8+
import { SubmissionType } from "~/rules/requests/team.request";
79

810
class TeamRepository {
911
findWithPagination = async () => {
@@ -272,6 +274,17 @@ class TeamRepository {
272274
findAllPresentationSchedules = async () => {
273275
return prisma.schedulePresent.findMany();
274276
};
277+
createSubmission = async (userId: string, data: SubmissionType) => {
278+
return prisma.submission.create({
279+
data: new Submission({
280+
teamId: data.teamId,
281+
userId,
282+
presentationLink: data.presentationLink,
283+
productLink: data.productLink,
284+
note: data.note,
285+
}),
286+
});
287+
};
275288
}
276289

277290
const teamRepository = new TeamRepository();

backend/src/routes/team.routes.ts

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

19-
teamRouter.post("/submissions", auth, teamController.createSubmission);
19+
teamRouter.post("/:teamId/submissions", auth, teamController.createSubmission);
2020

2121
// get các lịch đã có thể đăng ký
2222
teamRouter.get("/get-schedule-all", auth, teamController.getSchedulePresentation);

backend/src/schemas/submission.schema.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,29 @@ interface SubmissionType {
44
id?: string;
55
teamId: string;
66
userId: string;
7-
filePath: string;
8-
submittedAt: Date;
7+
presentationLink: string;
8+
productLink: string;
9+
note?: string;
10+
submittedAt?: Date;
911
}
1012

1113
class Submission {
1214
id: string;
1315
teamId: string;
1416
userId: string;
15-
filePath: string;
17+
presentationLink: string;
18+
productLink: string;
19+
note: string;
1620
submittedAt: Date;
1721

1822
constructor(submission: SubmissionType) {
1923
this.id = submission.id || uuidv4();
2024
this.teamId = submission.teamId;
2125
this.userId = submission.userId;
22-
this.filePath = submission.filePath;
23-
this.submittedAt = submission.submittedAt;
26+
this.presentationLink = submission.presentationLink;
27+
this.productLink = submission.productLink;
28+
this.note = submission.note || "";
29+
this.submittedAt = submission.submittedAt || new Date();
2430
}
2531
}
2632

backend/src/services/team.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class TeamService {
271271
message: "Bạn không có quyền tạo submission cho nhóm này.",
272272
});
273273
}
274-
const created = await teamRepository.createSubmission({
274+
const created = await teamRepository.createSubmission(userId, {
275275
teamId,
276276
presentationLink,
277277
productLink,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,10 @@ class TeamApi {
5959
const res = await privateApi.get<ResponseDetailData<SchedulePresentType>>(`/teams/get-schedule/${teamId}`);
6060
return res.data;
6161
}
62+
63+
static async submissions(teamId: string) {
64+
const res = await privateApi.get<ResponseDetailData<{ submissionUrl: string }>>(`/teams/${teamId}/submissions`);
65+
return res.data;
66+
}
6267
}
6368
export default TeamApi;

0 commit comments

Comments
 (0)