Skip to content

Commit

Permalink
collapse semesters columnin user and user_sem_site table
Browse files Browse the repository at this point in the history
  • Loading branch information
sofiarba committed Jan 19, 2022
1 parent c49cb24 commit f19453d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 38 deletions.
15 changes: 3 additions & 12 deletions client/src/components/RosterCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const RosterCard = props => {
editedStudentSemesters.includes(currSemester)
}
onChange={onChangeStudentSemesters}
disabled={isToggleActive() && studentSemesters.length == 1}
/>
</Col>
<Col>
Expand All @@ -166,16 +167,6 @@ const RosterCard = props => {

const renderDescription = () => {
let description;
if (!mentorCard && !studentSemesters) {
fetch(`/api/v1/roster/getUserSemester?uid=${id}`)
.then(res => res.json())
.then(userSemester => {
const semesters = userSemester[0].semester ? userSemester[0].semester.split(',') : userSemester[0].semester;
setEditedStudentSemesters(semesters);
setStudentSemesters(semesters);
});
}

if (mentorCard) {
description = (
<div>
Expand Down Expand Up @@ -304,7 +295,7 @@ const RosterCard = props => {
const description = renderDescription();
const maybeEditButton = renderEditButton();

const maybeCard = (
const userCard = (
<div>
<Card
style={{ borderRadius: '20px' }}
Expand All @@ -317,7 +308,7 @@ const RosterCard = props => {
);

if (description) {
return maybeCard;
return userCard;
} else {
return null;
}
Expand Down
12 changes: 8 additions & 4 deletions client/src/components/SignUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ const SignUp = () => {
};

const addUserSite = async payload => {
const semester = getCurrentSemester();
// const semester = getCurrentSemester();
try {
await fetch('/api/v1/site/addUserSemSite', {
await fetch('/api/v1/site/addUserSite', {
method: 'POST',
body: JSON.stringify({
user_id: payload.id,
semester,
// semester,
site_id: siteId,
}),
headers: new Headers({
Expand All @@ -98,7 +98,7 @@ const SignUp = () => {
}
};

const _submit = event => {
const _submit = async event => {
const googleToken = getGoogleToken();

if (!googleToken) {
Expand Down Expand Up @@ -139,10 +139,14 @@ const SignUp = () => {

event.preventDefault();

const semesters = [];
semesters.push(await getCurrentSemester());

axios
.post('/api/v1/auth/signup', {
googleToken,
role,
semesters,
})
.then(data => {
localStorage.setItem('anovaToken', data.data.token);
Expand Down
3 changes: 2 additions & 1 deletion controllers/auth_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const login = (req, res, next) => {
};

const signup = (req, res, next) => {
const { googleToken, role } = req.body;
const { googleToken, role, semesters } = req.body;

const client = new OAuth2Client(process.env.CLIENT_ID);

Expand All @@ -113,6 +113,7 @@ const signup = (req, res, next) => {
name: name.trim(),
email: email.trim(),
role: role,
studentSemesters: JSON.stringify(semesters),
};
User.create(newUser).then(retUser => {
const payload = {
Expand Down
14 changes: 0 additions & 14 deletions controllers/rosters_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,6 @@ const getUsersBySite = async (req, res) => {
}
};

const getUserSemester = async (req, res) => {
const userid = req.query.uid;
try {
const data = await knex
.select('semester')
.from('user_semester_site')
.where('user_id', userid);
res.status(200).send(data);
} catch (error) {
res.status(500).json({ error });
}
};

/* Update a specific student profile */
const update = async (req, res) => {
try {
Expand All @@ -63,6 +50,5 @@ const update = async (req, res) => {

module.exports = {
getUsersBySite: getUsersBySite,
getUserSemester: getUserSemester,
update: update,
};
11 changes: 6 additions & 5 deletions controllers/sites_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@ const getCurrentUserSite = async (req, res, next) => {
.first();
return res.send(data);
} catch (error) {
console.log(error);
return res.status(500).json({ error });
}
};
/* Add user to a site + semester. */
const addUserToSemSite = async (req, res, next) => {
/* Add user to a site. */
const addUserToSite = async (req, res, next) => {
try {
await knex('user_semester_site').insert({
user_id: req.body.user_id,
semester: req.body.semester,
// semester: req.body.semester,
site_id: req.body.site_id,
});
return res.status(201).json({
user_id: req.body.user_id,
semester: req.body.semester,
// semester: req.body.semester,
site_id: req.body.site_id,
});
} catch (error) {
Expand All @@ -49,5 +50,5 @@ const addUserToSemSite = async (req, res, next) => {
module.exports = {
index: index,
getCurrentUserSite: getCurrentUserSite,
addUserToSemSite: addUserToSemSite,
addUserToSite: addUserToSite,
};
3 changes: 1 addition & 2 deletions routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = app => {
//Site
app.get('/api/v1/site/allSites', SitesController.index);
app.get('/api/v1/site/current', SitesController.getCurrentUserSite);
app.post('/api/v1/site/addUserSemSite', SitesController.addUserToSemSite);
app.post('/api/v1/site/addUserSite', SitesController.addUserToSite);

//Lessons
app.get('/api/v1/lessons/all', LessonsController.index);
Expand All @@ -44,6 +44,5 @@ module.exports = app => {

//Roster
app.get('/api/v1/roster', RostersController.getUsersBySite);
app.get('/api/v1/roster/getUserSemester', RostersController.getUserSemester);
app.post('/api/v1/roster/update', RostersController.update);
};

0 comments on commit f19453d

Please sign in to comment.