-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
40 lines (32 loc) · 928 Bytes
/
db.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
const mongoose = require('mongoose');
const { Schema } = mongoose;
var db;
const connect = async () => {
try {
db = await mongoose.connect(process.env.DB_CONNECTION_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
console.log('DB connected');
} catch (err) {
console.log('Failed to connect to DB', err);
}
return db;
};
const IssueSchema = new Schema({
issue_title: { type: String, required: true },
issue_text: { type: String, required: true },
created_by: { type: String, required: true },
created_on: Date,
updated_on: Date,
assigned_to: String,
status_text: String,
open: Boolean,
});
const Issue = mongoose.model('Issues', IssueSchema);
const ProjectSchema = new Schema({
name: { type: String, required: true },
issues: [IssueSchema],
});
const Project = mongoose.model('Projects', ProjectSchema);
module.exports = { connect, Issue, Project, db };