Skip to content

Commit 7e7d6b7

Browse files
authored
Merge pull request #8 from oslabs-beta/renderNextjs
changed DB string to be personal DB and moved it into .env
2 parents 3ba584d + 91ccda4 commit 7e7d6b7

File tree

1 file changed

+43
-34
lines changed

1 file changed

+43
-34
lines changed

server/models/reactypeModels.js

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,24 @@
1010
*/
1111
const mongoose = require('mongoose');
1212
const bcrypt = require('bcryptjs');
13-
const mongoURI = 'mongodb+srv://Daniel:[email protected]/Cluster0?retryWrites=true&w=majority';
14-
const URI = process.env.NODE_ENV === 'production' ? mongoURI : 'mongodb+srv://Daniel:[email protected]/Cluster0?retryWrites=true&w=majority';
13+
require('dotenv').config();
14+
const mongoURI = process.env.MONGO_DB_NEW;
15+
const URI =
16+
process.env.NODE_ENV === 'production' ? mongoURI : process.env.MONGO_DB_NEW;
1517

16-
const SALT_WORK_FACTOR = 14;
18+
const SALT_WORK_FACTOR = 10;
1719
// connect to mongo db
1820
mongoose
19-
.connect(URI,
20-
{
21-
// options for the connect method to parse the URI
22-
useNewUrlParser: true,
23-
useUnifiedTopology: true,
24-
useCreateIndex: true,
25-
// stop deprecation warning for findOneAndUpdate and findOneAndDelete queries
26-
useFindAndModify: false,
27-
// sets the name of the DB that our collections are part of
28-
dbName: 'ReacType',
29-
})
21+
.connect(URI, {
22+
// options for the connect method to parse the URI
23+
useNewUrlParser: true,
24+
useUnifiedTopology: true,
25+
useCreateIndex: true,
26+
// stop deprecation warning for findOneAndUpdate and findOneAndDelete queries
27+
useFindAndModify: false,
28+
// sets the name of the DB that our collections are part of
29+
dbName: 'ReacType'
30+
})
3031
.then(() => console.log('Connected to Mongo DB.'))
3132
.catch(err => console.log(err));
3233

@@ -35,7 +36,7 @@ const { Schema } = mongoose;
3536
const userSchema = new Schema({
3637
username: { type: String, required: true, unique: true },
3738
email: { type: String, required: false, unique: true },
38-
password: { type: String, required: true },
39+
password: { type: String, required: true }
3940
});
4041

4142
// mongoose middleware that will run before the save to
@@ -51,7 +52,7 @@ userSchema.pre('save', function cb(next) {
5152
log: `bcrypt password hashing error: ${err}`,
5253
message: {
5354
err: 'bcrypt hash error: check server logs for details.'
54-
},
55+
}
5556
});
5657
}
5758
this.password = hash;
@@ -63,36 +64,44 @@ const commentsSchema = new Schema({
6364
username: { type: String, required: true },
6465
text: { type: String, required: true },
6566
projectId: { type: Schema.Types.ObjectId, required: true },
66-
createdAt: { type: Date, default: Date.now },
67+
createdAt: { type: Date, default: Date.now }
6768
});
6869

6970
const sessionSchema = new Schema({
7071
cookieId: { type: String, required: true, unique: true },
71-
createdAt: { type: Date, default: Date.now },
72+
createdAt: { type: Date, default: Date.now }
7273
});
7374

74-
const projectSchema = new Schema({
75-
name: String,
76-
likes: { type: Number, default: 0 },
77-
published: { type: Boolean, default: false },
78-
project: { type: Object, required: true },
79-
userId: {
80-
type: Schema.Types.ObjectId,
81-
ref: 'Users',
75+
const projectSchema = new Schema(
76+
{
77+
name: String,
78+
likes: { type: Number, default: 0 },
79+
published: { type: Boolean, default: false },
80+
project: { type: Object, required: true },
81+
userId: {
82+
type: Schema.Types.ObjectId,
83+
ref: 'Users'
84+
},
85+
username: { type: String, required: true },
86+
createdAt: { type: Date, default: Date.now },
87+
comments: [
88+
{
89+
type: Schema.Types.ObjectId,
90+
ref: 'Comments'
91+
}
92+
]
8293
},
83-
username: { type: String, required: true },
84-
createdAt: { type: Date, default: Date.now },
85-
comments: [{
86-
type: Schema.Types.ObjectId,
87-
ref: 'Comments',
88-
}],
89-
}, { minimize: true });
94+
{ minimize: true }
95+
);
9096

9197
const Users = mongoose.model('Users', userSchema);
9298
const Comments = mongoose.model('Comments', commentsSchema);
9399
const Sessions = mongoose.model('Sessions', sessionSchema);
94100
const Projects = mongoose.model('Projects', projectSchema);
95101

96102
module.exports = {
97-
Users, Comments, Sessions, Projects,
103+
Users,
104+
Comments,
105+
Sessions,
106+
Projects
98107
};

0 commit comments

Comments
 (0)