-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.js
71 lines (62 loc) · 2 KB
/
models.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const mongoose = require('mongoose');
//const integerValidator = require('mongoose-integer');
//Schema for Players
const playerSchema = mongoose.Schema({
firstName: {type: String, required: true},
lastName: {type: String, required: true},
status: {type: String, default: 'active'},
preferredPosition: {type: String, default: 'Not Specified'}
});
playerSchema.methods.playerRepr = function() {
return {
id: this._id,
firstName: this.firstName,
lastName: this.lastName,
status: this.status,
preferredPosition: this.preferredPosition
};
}
//Schema for Formations
const formationSchema = mongoose.Schema({
name: String,
layers: [{type: Number, required: true}],
});
formationSchema.virtual('amountOfLayers').get(function(){
return `${this.layers.length}`;
});
formationSchema.methods.formationRepr = function() {
return {
id: this._id,
name: this.name,
layers: this.layers
};
}
//formationSchema.plugin(integerValidator, { message: 'Error, expected {PATH} to be an integer.' });
const rosterSchema = mongoose.Schema({
formationId: {type: String, required: true},
playerPositions: [{
layer: {type: Number, required: true},
position: {type: Number, required: true},
playerId: {type: String, required: true}
}],
//dateCreated: { type: Date, default: Date.now}
dateCreated: {type: String, default: new Date().toDateString()},
lastModified: {type: String, default: ''},
description: {type: String, default: ''},
notes: {type: String, default: ''}
});
rosterSchema.methods.rosterRepr = function() {
return {
id: this._id,
formationId: this.formationId,
playerPositions: this.playerPositions,
dateCreated: this.dateCreated,
lastModified: this.lastModified,
description: this.description,
notes: this.notes
};
}
const Player = mongoose.model('Player', playerSchema);
const Formation = mongoose.model('Formation', formationSchema);
const Roster = mongoose.model('Roster', rosterSchema);
module.exports = {Player, Formation, Roster};