Skip to content

Commit 035b178

Browse files
committed
feat: enhance submission model and add createSubmission endpoint; update UI components for submissions
1 parent 0fa118f commit 035b178

11 files changed

Lines changed: 73 additions & 351 deletions

File tree

backend/prisma/schema.prisma

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,13 @@ model Topic {
9494
}
9595

9696
model Submission {
97-
id String @id @default(uuid()) @db.VarChar(36)
98-
teamId String @map("team_id") @db.VarChar(36)
99-
userId String @map("user_id") @db.VarChar(36)
100-
filePath String @map("file_path") @db.VarChar(255)
101-
submittedAt DateTime @map("submitted_at")
97+
id String @id @default(uuid()) @db.VarChar(36)
98+
teamId String @map("team_id") @db.VarChar(36)
99+
userId String @map("user_id") @db.VarChar(36)
100+
presentationLink String @map("presentation_link") @db.VarChar(255)
101+
productLink String @map("product_link") @db.VarChar(255)
102+
note String? @db.Text
103+
submittedAt DateTime @map("submitted_at")
102104
103105
team Team @relation(fields: [teamId], references: [id])
104106
user User @relation(fields: [userId], references: [id])

backend/src/controllers/team.controllers.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { RoleType } from "~/constants/enums";
44
import { HTTP_STATUS } from "~/constants/httpStatus";
55
import { ResponseClient } from "~/rules/response";
66
import teamService from "~/services/team.service";
7-
import { CreateSchedulePresent } from "~/rules/requests/team.request";
7+
import { CreateSchedulePresent, SubmissionType } from "~/rules/requests/team.request";
88

99
export const getAll = async (req: Request, res: Response, next: NextFunction) => {
1010
try {
@@ -59,6 +59,30 @@ export const getSchedulePresentation = async (
5959
return next(error);
6060
}
6161
};
62+
63+
export const createSubmission = async (
64+
req: Request<ParamsDictionary, {}, SubmissionType>,
65+
res: Response,
66+
next: NextFunction,
67+
) => {
68+
try {
69+
const userId = req.userId!;
70+
const { teamId, presentationLink, productLink, note } = req.body;
71+
console.log("teamId, presentationLink, productLink, note", teamId, presentationLink, productLink, note);
72+
const result = await teamService.createSubmission({
73+
userId,
74+
teamId,
75+
presentationLink,
76+
productLink,
77+
note,
78+
});
79+
return res
80+
.status(HTTP_STATUS.CREATED)
81+
.json(new ResponseClient({ message: "Tạo submission thành công!", result }));
82+
} catch (error) {
83+
return next(error);
84+
}
85+
};
6286
export const getSchedulePresentationInTeam = async (
6387
req: Request<ParamsDictionary, {}, { teamId: string }>,
6488
res: Response,

backend/src/routes/team.routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ 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);
20+
1921
// get các lịch đã có thể đăng ký
2022
teamRouter.get("/get-schedule-all", auth, teamController.getSchedulePresentation);
2123

backend/src/rules/requests/team.request.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ export interface CreateSchedulePresent {
33
trialDate: string;
44
officialDate: string[];
55
}
6+
export interface SubmissionType {
7+
teamId: string;
8+
presentationLink: string;
9+
productLink: string;
10+
note: string;
11+
}

backend/src/services/team.service.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,35 @@ class TeamService {
250250
officialSchedules: availableOfficialSchedules,
251251
};
252252
}
253+
254+
createSubmission = async ({
255+
userId,
256+
teamId,
257+
presentationLink,
258+
productLink,
259+
note,
260+
}: {
261+
userId: string;
262+
teamId: string;
263+
presentationLink: string;
264+
productLink: string;
265+
note: string;
266+
}) => {
267+
const isMember = await teamRepository.isMember(teamId, userId);
268+
if (!isMember) {
269+
throw new ErrorWithStatus({
270+
status: HTTP_STATUS.FORBIDDEN,
271+
message: "Bạn không có quyền tạo submission cho nhóm này.",
272+
});
273+
}
274+
const created = await teamRepository.createSubmission({
275+
teamId,
276+
presentationLink,
277+
productLink,
278+
note,
279+
});
280+
return created;
281+
};
253282
}
254283

255284
const teamService = new TeamService();

frontend/src/components/Header/Candidate.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Helper from "~/utils/helper";
22
import { NavLink } from "./NavLink";
3-
import { Presentation } from "lucide-react";
3+
import { Presentation, Send } from "lucide-react";
44
import { useLocation } from "react-router";
55

66
const CandidateHeader = () => {
@@ -15,14 +15,14 @@ const CandidateHeader = () => {
1515
active={Helper.isActive(location.pathname, "/presents")}
1616
/>
1717
</li>
18-
{/* <li id="submissions">
18+
<li id="submissions">
1919
<NavLink
2020
url="/submissions"
2121
name="Nộp sản phẩm"
2222
Icon={Send}
2323
active={Helper.isActive(location.pathname, "/submissions")}
2424
/>
25-
</li> */}
25+
</li>
2626
</>
2727
);
2828
};

frontend/src/pages/Submissions copy/FormSubmit.tsx

Lines changed: 0 additions & 90 deletions
This file was deleted.

frontend/src/pages/Submissions copy/HistorySubmit.tsx

Lines changed: 0 additions & 162 deletions
This file was deleted.

0 commit comments

Comments
 (0)