Browse Source

Add Athlete model and correlation to trainer

Also change the order that socket gets initiated in index. It must be after DB conn.
main
Haris Razis 4 years ago
parent
commit
4c5d5dd42c
  1. 1
      server/connections/mongo_conn.js
  2. 4
      server/index.js
  3. 10
      server/models/Athlete.js
  4. 2
      server/models/User.js

1
server/connections/mongo_conn.js

@ -3,6 +3,7 @@ const chalk = require('chalk')
const {mongo_uri} = require('../config/keys');
require('../models/User');
require('../models/Athlete');
mongoose.Promise = global.Promise;
mongoose.connect(mongo_uri, {

4
server/index.js

@ -6,11 +6,12 @@ const cors = require('cors')
const history = require('connect-history-api-fallback');
const rateLimit = require('express-rate-limit');
require('./services/socket')(server);
require('./connections/mongo_conn');
require('./services/socket')(server);
const dataRoute = require('./routes/data')
const authRoute = require('./routes/auth')
const athletesRoute = require('./routes/athletes')
const passport = require('./services/passport');
const {session_secret} = require('./config/keys');
@ -43,6 +44,7 @@ app.use(passport.session(undefined));
app.use(dataRoute)
app.use(authRoute)
app.use(athletesRoute)
app.use(history({
verbose: true

10
server/models/Athlete.js

@ -0,0 +1,10 @@
const mongoose = require('mongoose');
const {Schema} = mongoose;
const AthleteSchema = new Schema({
id: String,
name: String,
_trainer: {type: Schema.Types.ObjectId, ref: 'User'}
});
mongoose.model('Athlete', AthleteSchema);

2
server/models/User.js

@ -3,7 +3,7 @@ const {Schema} = mongoose;
const userSchema = new Schema({
username: String,
password: String
password: String,
});
mongoose.model('User', userSchema);
Loading…
Cancel
Save