Skip to content

Commit 1f3786a

Browse files
logout works
1 parent 840c85f commit 1f3786a

File tree

6 files changed

+47
-49
lines changed

6 files changed

+47
-49
lines changed

app/auth/auth.router.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,11 @@ authRouter.post('/refresh', jwtPassportMiddleware, (request, response) => {
4949
});
5050
});
5151

52-
authRouter.get('/logout', localPassportMiddleware, (req, res) => {
52+
authRouter.post('/logout', (req, res) => {
5353
console.log("logging out")
5454
res.header('Cache-Control', 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0');
5555
res.json({
56-
jwtToken,
57-
user
56+
5857
})
5958
});
6059
module.exports = {

app/exercise/exercise.model.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ const mongoose = require("mongoose");
88
const Joi = require("joi");
99

1010
const exerciseSchema = new mongoose.Schema({
11-
// user: {
12-
// type: mongoose.Schema.Types.ObjectId,
13-
// ref: "user"
14-
// },
1511
exercise: {
1612
type: String,
1713
required: true
@@ -24,18 +20,13 @@ const exerciseSchema = new mongoose.Schema({
2420
type: String,
2521
enum: ["cardiovascular", "strength training"]
2622
}
23+
2724
});
2825

2926
exerciseSchema.methods.serialize = function() {
30-
// let user;
31-
// if (typeof this.user.serialize === "function") {
32-
// user = this.user.serialize();
33-
// } else {
34-
// user = this.user;
35-
// }
27+
3628
return {
3729
id: this._id,
38-
// user: user,
3930
exercise: this.exercise,
4031
bodypart: this.bodypart,
4132
ex_type: this.ex_type
@@ -56,5 +47,6 @@ const ExerciseJoiSchema = Joi.object().keys({
5647
});
5748

5849
module.exports = {
59-
Exercise
50+
Exercise,
51+
ExerciseJoiSchema
6052
};

app/workout/workout.model.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,27 @@ const workoutSchema = new mongoose.Schema({
1515
type: mongoose.Schema.Types.ObjectId,
1616
ref: "user"
1717
},
18-
exercise: {
19-
type: String,
20-
required: true
18+
date: {
19+
type: Date,
20+
default: Date.now
2121
},
22-
set: {
23-
type: Number,
24-
25-
},
26-
reps: {
27-
type: Number,
28-
29-
},
30-
weight: {
31-
type: Number
32-
}
33-
// date: {
34-
// type: Date
35-
// }
22+
sets: [{
23+
exercise: {
24+
type: String,
25+
required: true
26+
},
27+
set: {
28+
type: Number,
29+
required: true
30+
},
31+
reps: {
32+
type: Number,
33+
required: true
34+
},
35+
weight: {
36+
type: Number
37+
}
38+
}]
3639
});
3740

3841
workoutSchema.methods.serialize = function() {

public/auth.page.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,11 @@ function onLoginSubmit(event) {
6060
}
6161

6262
function onLogoutSubmit(event) {
63-
console.log("Logging out")
6463
event.preventDefault();
6564
HTTP.logoutUser({
66-
6765
onSuccess: response => {
68-
const authenticatedUser = response.user;
69-
console.log(authenticatedUser);
70-
authenticatedUser.jwtToken = response.jwtToken;
71-
CACHE.deleteAuthenticatedUserFromCache(authenticatedUser);
72-
alert('Please come again');
66+
CACHE.deleteAuthenticatedUserFromCache();
67+
7368
window.open('/', '_self');
7469
}
7570
})

public/search.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,13 @@ function exerciseLoop(res) {
5050
function clearInput() {
5151
$('input').val("")
5252
}
53-
54-
55-
5653
// Save exercise set to workout
5754
// capture name of exercise
5855
function selectExercise() {
5956
$('.search-btn').on('click', function() {
60-
let searchVal = $('.search-ex').val();
57+
let searchVal = $('.search-ex')[1].value;
6158
console.log(searchVal)
62-
// $('.exerciseName').append(`${searchVal}`);
59+
$('.exerciseName').append(`${searchVal}`);
6360
});
6461

6562
}
@@ -68,7 +65,22 @@ function showSetAdd() {
6865

6966
}
7067

68+
function saveSet() {
69+
let reps;
70+
let sets;
71+
let weight;
72+
$('button').on('click', '.save-set'function() {
73+
reps = $('#POST-reps').value()
74+
console.log(reps);
75+
weight = $('#POST-weight').value();
76+
console.log(weight);
77+
});
78+
79+
}
80+
81+
function updateWorkout(reps, weight) {
7182

83+
}
7284

7385

7486
function onPageLoad() {

public/utilities/http.module.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ function loginUser(options) {
5555
}
5656
});
5757
}
58-
// app.get('/logout', function(req, res) {
59-
// req.logout();
60-
// res.redirect('/');
61-
// });
58+
6259

6360
function logoutUser(options) {
6461
console.log("logout user called")
@@ -120,7 +117,7 @@ function getWorkoutById(options) {
120117
function createWorkout(options) {
121118
const {
122119
jwtToken,
123-
newworkout,
120+
newWorkout,
124121
onSuccess,
125122
onError
126123
} = options;

0 commit comments

Comments
 (0)