Skip to content

Commit

Permalink
Getting Based On TestType
Browse files Browse the repository at this point in the history
  • Loading branch information
sheninthjr committed Nov 6, 2023
1 parent 1349932 commit d405d47
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 24 deletions.
3 changes: 1 addition & 2 deletions apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"postcss-cli": "^10.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router": "^6.18.0",
"react-router-dom": "^6.18.0",
"react-router-dom": "^6.15.0",
"ui": "*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion apps/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function App() {
<Route path="/" element={<Landing/>}></Route>
<Route path="/post" element={<PostingQuestion />}></Route>
<Route path="/get" element={<TestType />}></Route>
<Route path="/get/:testtype" element={<GetQuestion />}></Route>
<Route path="/get/:testType" element={<GetQuestion />}></Route>
</Routes>
</Router>
</>
Expand Down
6 changes: 3 additions & 3 deletions apps/client/src/components/GetQuestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useState, useEffect } from "react";
import { useLocation, useParams } from "react-router";

export default function GetQuestion() {
const { type } = useParams();
const { testType } = useParams();
const location = useLocation();
const searchParams = new URLSearchParams(location.search);
const date = searchParams.get("date");
Expand All @@ -15,9 +15,10 @@ export default function GetQuestion() {
const [pdfUrl, setPdfUrl] = useState("");
const [showPdf, setShowPdf] = useState(false);


const fetchPdf = async () => {
try {
const res = await axios.get(`${BASE_URL}/get/${type}?date=${date}&sem=${sem}&year=${year}&setTypeA=${setTypeA}`, {
const res = await axios.get(`${BASE_URL}/get/${testType}?date=${date}&sem=${sem}&year=${year}&setTypeA=${setTypeA}`, {
responseType: "blob",
});
const blob = new Blob([res.data], { type: "application/pdf" });
Expand All @@ -36,7 +37,6 @@ export default function GetQuestion() {
const refreshData = () => {
fetchPdf();
};

return (
<div className="flex flex-col justify-center items-center p-40">
<div className="flex flex-col justify-between rounded-lg space-y-5 p-4 border-4 h-[30vh] bg-white border-white w-80 sm:w-50 md:h-[50vh] w-100 lg:h-[50vh]">
Expand Down
14 changes: 8 additions & 6 deletions apps/client/src/components/TestType.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@

import { TypePost } from "ui";
import { Link } from "react-router-dom";
import { useNavigate } from "react-router-dom";

export default function TestType() {
const navigate = useNavigate()
return (
<>
<TypePost
onClick={async (
date: string,
type: string,
testType: string,
year: string,
sem: string,
setTypeA:string
) => {
const urlData = {
date,
type,
testType,
year,
sem,
setTypeA
};
return (
<Link to={{pathname:`/get/${urlData.type}`,search:`?date=${date}&sem=${sem}&year=${year}&setTypeA=${setTypeA}`}} ></Link>
)
if(urlData.testType){
navigate(`/get/${testType}?date=${date}&sem=${sem}&year=${year}&setTypeA=${setTypeA}`)
}
}}
/>
</>
Expand Down
2 changes: 1 addition & 1 deletion packages/prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@prisma/client": "^5.5.2",
"@prisma/client": "5.5.2",
"@types/cors": "^2.8.15",
"@types/express": "^4.17.20",
"cors": "^2.8.5",
Expand Down
10 changes: 9 additions & 1 deletion packages/prisma/server/routes/QuestionRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,18 @@ router.get("/get/:testtype", async (req, res) => {
const sem = req.query.sem;
const year = req.query.year;
const set = req.query.setTypeA;
function reverseDate(inputDate) {
const dateComponents = inputDate.split('-');
const reversedDate = dateComponents.reverse().join('-');
return reversedDate;
}
const inputDate = date;
const rDate = reverseDate(inputDate);
try {
const browser = await puppeteer.launch();
const page = await browser.newPage();
if (testType === "IA1") {
console.log(testType)
const skipNo = 4;
const partA11Questions = await prisma.unit1.findMany({
skip: Math.floor(Math.random() * skipNo),
Expand Down Expand Up @@ -247,7 +255,7 @@ router.get("/get/:testtype", async (req, res) => {
<h3>Velammal Institute of technology</h3>
</div>
<div>
<h3>Dept of AI&DS/${testType}/${year}/${sem}/${date}/1.45hr/60Marks/${set}</h3>
<h3>Dept of AI&DS/${testType}/${year}/${sem}/${rDate}/1.45hr/60Marks/${set}</h3>
</div>
<div>
<h3>CCS334-BIG DATA ANALYTICS</h3>
Expand Down
14 changes: 7 additions & 7 deletions packages/ui/src/components/TypePost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ export function TypePost(props: {
onClick: (date: string, type: string, year: string, sem: string,setTypeA:string) => void;
}) {
const [date, setDate] = useState("");
const [type, setType] = useState("");
const [year, setYear] = useState("");
const [sem, setSem] = useState("");
const [setTypeA,setSetTypeA] = useState("")
const [testType, setTestType] = useState("IA1");
const [year, setYear] = useState("I Year");
const [sem, setSem] = useState("I Sem");
const [setTypeA,setSetTypeA] = useState("Set A")
return (
<>
<div className="flex flex-col justify-center items-center p-40">
Expand All @@ -24,8 +24,8 @@ export function TypePost(props: {
<select
className="rounded-lg border-2 border-gray-700 h-15 p-4 bg-white"
name="Type of Exam"
value={type}
onChange={(e) => setType(e.target.value)}
value={testType}
onChange={(e) => setTestType(e.target.value)}
>
<option value="IA1">IA1</option>
<option value="IA2">IA2</option>
Expand Down Expand Up @@ -75,7 +75,7 @@ export function TypePost(props: {
<button
className="flex justify-center items-center rounded-lg border-2 border-red-600 h-5 p-4 bg-white"
onClick={async () => {
props.onClick(date, type, year, sem,setTypeA);
props.onClick(date, testType, year, sem,setTypeA);
}}
>
Submit
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@
picocolors "^1.0.0"
tslib "^2.6.0"

"@prisma/client@^5.5.2":
"@prisma/client@5.5.2", "@prisma/client@^5.5.2":
version "5.5.2"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-5.5.2.tgz#ce6389e7ad9e9cf0fc2a7c6a0032ad2e12a9fd61"
integrity sha512-54XkqR8M+fxbzYqe+bIXimYnkkcGqgOh0dn0yWtIk6CQT4IUCAvNFNcQZwk2KqaLU+/1PHTSWrcHtx4XjluR5w==
Expand Down Expand Up @@ -4387,15 +4387,15 @@ react-refresh@^0.14.0:
resolved "https://registry.npmjs.org/react-refresh/-/react-refresh-0.14.0.tgz"
integrity sha512-wViHqhAd8OHeLS/IRMJjTSDHF3U9eWi62F/MledQGPdJGDhodXJ9PBLNGr6WWL7qlH12Mt3TyTpbS+hGXMjCzQ==

react-router-dom@^6.18.0:
react-router-dom@^6.15.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-6.18.0.tgz#0a50c167209d6e7bd2ed9de200a6579ea4fb1dca"
integrity sha512-Ubrue4+Ercc/BoDkFQfc6og5zRQ4A8YxSO3Knsne+eRbZ+IepAsK249XBH/XaFuOYOYr3L3r13CXTLvYt5JDjw==
dependencies:
"@remix-run/router" "1.11.0"
react-router "6.18.0"

[email protected], react-router@^6.18.0:
[email protected]:
version "6.18.0"
resolved "https://registry.yarnpkg.com/react-router/-/react-router-6.18.0.tgz#32e2bedc318e095a48763b5ed7758e54034cd36a"
integrity sha512-vk2y7Dsy8wI02eRRaRmOs9g2o+aE72YCx5q9VasT1N9v+lrdB79tIqrjMfByHiY5+6aYkH2rUa5X839nwWGPDg==
Expand Down

0 comments on commit d405d47

Please sign in to comment.