Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 37 additions & 24 deletions backend/routers/psOne.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
const express = require('express');
const express = require("express");
const router = new express.Router();
const auth = require('../middleware/auth');
const Station = require('../models/station');
const auth = require("../middleware/auth");
const Station = require("../models/station");

// get details of a station for ps1
router.get('/api/1/:station', async (req, res) => {
const station = await Station.findOne({ category: { type: 'ps1' }, slug: req.params.station });
router.get("/api/1/:station", async (req, res) => {
const station = await Station.findOne({
category: { type: "ps1" },
slug: req.params.station,
});

if (!station) {
res.status(404).send();
Expand All @@ -16,26 +19,28 @@ router.get('/api/1/:station', async (req, res) => {
});

// search the stations by name for ps1
router.get('/api/1', async (req, res) => {
router.get("/api/1", async (req, res) => {
const queries = {
category: { type: 'ps1' }
category: { type: "ps1" },
};

if (req.query.name) {
queries.name = { $regex: new RegExp(req.query.name, 'i') };
queries.name = { $regex: new RegExp(req.query.name, "i") };
}

if (req.query.location) {
queries.location = { $regex: new RegExp(req.query.location, 'i') };
queries.location = { $regex: new RegExp(req.query.location, "i") };
}

try {
const stations = await Station.find(queries,
'name category field location cg slug',
const stations = await Station.find(
queries,
"name category field location cg slug",
{
limit: parseInt(req.query.limit),
skip: parseInt(req.query.skip)
});
skip: parseInt(req.query.skip),
}
);

res.send(stations);
} catch (e) {
Expand All @@ -44,18 +49,21 @@ router.get('/api/1', async (req, res) => {
});

// post a new comment on the opportunity for ps1
router.post('/api/1/:station/comment', auth, async (req, res) => {
const station = await Station.findOne({ category: { type: 'ps1' }, slug: req.params.station });
router.post("/api/1/:station/comment", auth, async (req, res) => {
const station = await Station.findOne({
category: { type: "ps1" },
slug: req.params.station,
});

if (!station) {
return res.status(404).send('Station not found');
return res.status(404).send("Station not found");
}

station.discussion.push({
comment: {
user: req.user._id,
data: req.body.data
}
data: req.body.data,
},
});

try {
Expand All @@ -68,23 +76,28 @@ router.post('/api/1/:station/comment', auth, async (req, res) => {
});

// post a new reply on a comment for ps1
router.post('/api/1/:station/:comment/reply', auth, async (req, res) => {
const station = await Station.findOne({ category: { type: 'ps1' }, slug: req.params.station });
router.post("/api/1/:station/:comment/reply", auth, async (req, res) => {
const station = await Station.findOne({
category: { type: "ps1" },
slug: req.params.station,
});

if (!station) {
return res.status(404).send('Station not found');
return res.status(404).send("Station not found");
}

// eslint-disable-next-line eqeqeq
const commentIndex = station.discussion.findIndex((comment) => comment._id == req.params.comment);
const commentIndex = station.discussion.findIndex(
(comment) => comment._id == req.params.comment
);

if (commentIndex === -1) {
return res.status(404).send('Comment not found');
return res.status(404).send("Comment not found");
}

station.discussion[commentIndex].comment.replies.push({
user: req.user._id,
data: req.body.data
data: req.body.data,
});

try {
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>BITSandPSes</title>
</head>
<body class = "bg-pattern">
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
115 changes: 58 additions & 57 deletions frontend/src/containers/Choose/chooseComponent.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,85 @@
import React from 'react';
import './chooser.css';
import { Link, Redirect } from 'react-router-dom';
import React from "react";
import "./chooser.css";
import { Link, Redirect } from "react-router-dom";

//the website should be navigatable through url sharing. All base url cases will
//be diverted to this component.
//website has 3 sub-parts. 1 for ps1, 2 for ps2, 3 for electives. If user has ever visited the
//website has 3 sub-parts. 1 for ps1, 2 for ps2, 3 for electives. If user has ever visited the
//website in past, base url redirects to last used sub-part of the website. Otherwise, chooser helps in selecting them one.
//user's current sub-part is always stored and updated in the localStorage.
function Choose () {
const storedChoice = parseInt(window.localStorage.getItem("stationNo")); //fetch user's last used sub-part of website
if(storedChoice === 1 || storedChoice === 2 || storedChoice === 3 ) { //validation for redirecting to sub-part's home page
return(
<Redirect to = { "/" + storedChoice } />
);
}
else { //if not found in localStorage, render Chooser component
return(
<div className = "bg-pattern">
<div class = "container">
<div class = "row justify-content-center">
<h1 className = "web-name">
<span className = "green">BITS</span>
<span className = "dark-grey">and</span>
<span className = "blue">PS</span>
<span className = "dark-grey">es</span>
//user's current sub-part is always stored and updated in the localStorage.
function Choose() {
const storedChoice = parseInt(window.localStorage.getItem("stationNo")); //fetch user's last used sub-part of website
if (storedChoice === 1 || storedChoice === 2 || storedChoice === 3) {
//validation for redirecting to sub-part's home page
return <Redirect to={"/" + storedChoice} />;
} else {
//if not found in localStorage, render Chooser component
return (
<div className="bg-pattern">
<div class="container">
<div class="row justify-content-center">
<h1 className="web-name">
<span className="green">BITS</span>
<span className="dark-grey">and</span>
<span className="blue">PS</span>
<span className="dark-grey">es</span>
</h1>
</div>
<div class = "row justify-content-center">
<h1 className = "web-subname dark-grey">
might save you from the factories
<div class="row justify-content-center">
<h1 className="web-subname dark-grey">
might save you from the factories
</h1>
</div>
<div className = "chooser-buttons row justify-content-center">
<Link className = "btn green-bg chooser-button align-self-center" to = { '/' + 1 }>
<div className = "d-none d-lg-block align-items-center large-button-cont">
<h3 className = "large-button-title">
PS1
</h3>
<h5 className = "large-button-sub">
if you lost your 60k
</h5>
<div className="chooser-buttons row justify-content-center">
<Link
className="btn green-bg chooser-button align-self-center"
to={"/" + 1}
>
<div className="d-none d-lg-block align-items-center large-button-cont">
<h3 className="large-button-title">PS1</h3>
<h5 className="large-button-sub">if you lost your 60k</h5>
</div>
<h2 className = "d-block d-lg-none small-button-cont">PS1</h2>
<h2 className="d-block d-lg-none small-button-cont">PS1</h2>
</Link>
<div className = "button-gap display-inline"></div>
<Link className = "btn blue-bg chooser-button align-self-center" to = { '/' + 2 }>
<div className = "d-none d-lg-block large-button-cont">
<h3 className = "large-button-title">
PS2
</h3>
<h5 className = "large-button-sub">
<div className="button-gap display-inline"></div>
<Link
className="btn blue-bg chooser-button align-self-center"
to={"/" + 2}
>
<div className="d-none d-lg-block large-button-cont">
<h3 className="large-button-title">PS2</h3>
<h5 className="large-button-sub">
if you want to redeem your 60k
</h5>
</div>
<h2 className = "d-block d-lg-none small-button-cont">PS2</h2>
<h2 className="d-block d-lg-none small-button-cont">PS2</h2>
</Link>
</div>
<div className = "elective-button-row row justify-content-center">
<div className = "col-6 col-md-5 col-lg-4">
<Link className = "btn elective-button align-self-center" to = { '/' + 3 }>
<div className="elective-button-row row justify-content-center">
<div className="col-6 col-md-5 col-lg-4">
<Link
className="btn elective-button align-self-center"
to={"/" + 3}
>
Electives
</Link>
</div>
</div>
<div className = "row justify-content-center">
<h2 className = "col-7 disclaimer d-none d-lg-block">
Made by two lonely guys in their pyjamas, dont shove our throats
if content on this website turns out to be slightly deviating from actual data. Just like with you,
BITS Admin was a jerk to us too.
<div className="row justify-content-center">
<h2 className="col-7 disclaimer d-none d-lg-block">
Made by two lonely guys in their pyjamas, dont shove our throats
if content on this website turns out to be slightly deviating from
actual data. Just like with you, BITS Admin was a jerk to us too.
</h2>
<h2 className = "col-9 disclaimer d-block d-lg-none">
Choose the left one if you were robbed
of 60k. Right one if you are looking
to redeem the 60k.
<h2 className="col-9 disclaimer d-block d-lg-none">
Choose the left one if you were robbed of 60k. Right one if you
are looking to redeem the 60k.
</h2>
</div>
</div>
</div>
);
}
};
}

export default Choose;
export default Choose;
Loading