-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
203 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
P03_StackOverflow'sMiniature/P03_Bhanu0202/models/Profile.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
var mongoose = require("mongoose"); | ||
const Schema = mongoose.Schema; | ||
|
||
const ProfileSchema = new Schema({ | ||
user: { | ||
type: Schema.Types.ObjectId, | ||
ref: "myPerson" | ||
}, | ||
username: { | ||
type: String, | ||
required: true, | ||
max: 50 | ||
}, | ||
website: { | ||
type: String | ||
}, | ||
country: { | ||
type: String | ||
}, | ||
languages: { | ||
type: [String], | ||
required: true | ||
}, | ||
portfolio: { | ||
type: String | ||
}, | ||
workrole: [ | ||
{ | ||
role: { | ||
type: String, | ||
required: true | ||
}, | ||
company: { | ||
type: String | ||
}, | ||
country: { | ||
type: String | ||
}, | ||
from: { | ||
type: Date | ||
}, | ||
to: { | ||
type: Date | ||
}, | ||
current: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
details: { | ||
type: String | ||
} | ||
} | ||
], | ||
social: { | ||
youtube: { | ||
type: String | ||
}, | ||
facebook: { | ||
type: String | ||
}, | ||
instagram: { | ||
type: String | ||
} | ||
}, | ||
date: { | ||
type: Date, | ||
default: Date.now | ||
} | ||
}); | ||
|
||
module.exports = Profile = mongoose.model("ProfileSchema", ProfileSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
var mongoose = require("mongoose"); | ||
const Schema = mongoose.Schema; | ||
|
||
const QuesSchema = new Schema({ | ||
user: { | ||
type: mongoose.Types.ObjectId, | ||
ref: "myPerson" | ||
}, | ||
header: { | ||
type: String, | ||
required: true | ||
}, | ||
description: { | ||
type: String, | ||
required: true | ||
}, | ||
name: { | ||
type: String | ||
}, | ||
upvotes: [ | ||
{ | ||
user: { | ||
type: Schema.Types.ObjectId, | ||
ref: "myPerson" | ||
} | ||
} | ||
], | ||
answers: [ | ||
{ | ||
user: { | ||
type: Schema.Types.ObjectId, | ||
ref: "myPerson" | ||
}, | ||
text: { | ||
type: String, | ||
required: true | ||
}, | ||
name: { | ||
type: String | ||
}, | ||
date: { | ||
type: Date, | ||
default: Date.now | ||
} | ||
} | ||
], | ||
date: { | ||
type: Date, | ||
default: Date.now | ||
} | ||
}); | ||
|
||
module.exports = Ques = mongoose.model("QuesSchema", QuesSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
var express = require('express'); | ||
var route = express.Router(); | ||
var key = require("../setup/myurl"); | ||
const jsonwt = require("jsonwebtoken"); | ||
var passport = require("passport"); | ||
require("../strategies/jsonwtStrategy") (passport); | ||
var bcrypt = require("bcrypt"); | ||
var saltRounds = 10; | ||
|
||
//Models | ||
var User = require("../models/User"); | ||
var Profile = require("../models/Profile"); | ||
var Ques = require("../models/Ques"); | ||
|
||
route.get("/", (req, res) => { | ||
Ques.find() | ||
.sort({ date: "desc" }) | ||
.then(questions => res.json(questions)) | ||
.catch(err => res.json({ noquestions: "NO questions to display" })); | ||
}); | ||
|
||
route.post("/", passport.authenticate("jwt", { session: false }), | ||
(req, res) => { | ||
const newQues = new Ques({ | ||
header: req.body.header, | ||
description: req.body.description, | ||
user: req.user.id, | ||
name: req.body.name | ||
}); | ||
newQues | ||
.save() | ||
.then(ques => res.json(ques)) | ||
.catch(err => console.log("Error is " + err)); | ||
}); | ||
|
||
route.post("/answer:id", passport.authenticate("jwt", { session: false }), | ||
(req, res) => { | ||
Ques.findById(req.params.id) | ||
.then(ques => { | ||
const newAns = { | ||
user: req.user.id, | ||
name: req.body.name, | ||
text: req.body.text | ||
}; | ||
ques.answers.unshift(newAns); | ||
|
||
ques | ||
.save() | ||
.then(ques => res.json(ques)) | ||
.catch(err => console.log("Error is " + err)); | ||
}) | ||
.catch(err => console.log("Error is " + err)); | ||
}); | ||
|
||
|
||
module.exports = route; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters