Skip to content

Commit 853d366

Browse files
workout model updated
1 parent 13fca1b commit 853d366

File tree

2 files changed

+35
-49
lines changed

2 files changed

+35
-49
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: node_js
2+
node_js:
3+
- "iojs"
4+
- "7"

app/workout/workout.model.js

Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,48 @@
55
// 4. at least one set entered
66
//5. a note that can be left blank
77
//6. the amount of weight used in the set
8-
8+
// https://en.wikipedia.org/wiki/List_of_weight_training_exercises
99
const mongoose = require("mongoose");
1010
const Joi = require("joi");
1111

1212
const workoutSchema = new mongoose.Schema({
13-
user: {
14-
type: mongoose.Schema.Types.ObjectId,
15-
ref: "user"
16-
},
17-
exercise: {
18-
type: String,
19-
required: true
20-
},
21-
set: {
22-
type: Number,
23-
required: true
24-
},
25-
reps: {
26-
type: Number,
27-
required: true
28-
},
29-
weight: {
30-
type: Number
31-
},
32-
date: {
33-
type: Date
34-
}
13+
user: { type: mongoose.Schema.Types.ObjectId, ref: "user" },
14+
exercise: { type: String, required: true },
15+
set: { type: Number, required: true },
16+
reps: { type: Number, required: true },
17+
weight: { type: Number },
18+
date: { type: Date }
3519
});
3620

3721
workoutSchema.methods.serialize = function() {
38-
let user;
39-
if (typeof this.user.serialize === "function") {
40-
user = this.user.serialize();
41-
} else {
42-
user = this.user;
43-
}
44-
return {
45-
id: this._id,
46-
user: user,
47-
exercise: this.exercise,
48-
reps: this.reps,
49-
weight: this.weight,
50-
date: this.date
51-
};
22+
let user;
23+
if (typeof this.user.serialize === "function") {
24+
user = this.user.serialize();
25+
} else {
26+
user = this.user;
27+
}
28+
return {
29+
id: this._id,
30+
user: user,
31+
exercise: this.exercise,
32+
reps: this.reps,
33+
weight: this.weight,
34+
date: this.date
35+
};
5236
};
5337

5438
const Workout = mongoose.model("workout", workoutSchema);
5539

5640
const WorkoutJoiSchema = Joi.object().keys({
57-
user: Joi.string().optional(),
58-
exercise: Joi.string()
59-
.min(1)
60-
.required(),
61-
reps: Joi.number()
62-
.min(1)
63-
.required(),
64-
weight: Joi.number().min(1),
65-
date: Joi.date()
41+
user: Joi.string().optional(),
42+
exercise: Joi.string()
43+
.min(1)
44+
.required(),
45+
reps: Joi.number()
46+
.min(1)
47+
.required(),
48+
weight: Joi.number().min(1),
49+
date: Joi.date()
6650
});
6751

68-
module.exports = {
69-
Workout
70-
};
52+
module.exports = { Workout };

0 commit comments

Comments
 (0)