-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from ArinNigam/userModels
Updated Models and Schemas
- Loading branch information
Showing
37 changed files
with
1,797 additions
and
567 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
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 |
---|---|---|
@@ -1,25 +1,26 @@ | ||
import jwt from "jsonwebtoken"; | ||
import * as errorMessages from "../constants/errorMessages.js"; | ||
const passwordKey = process.env.PASSWORD_KEY; | ||
const secretKey = process.env.ACCESS_TOKEN_SECRET; | ||
|
||
const auth = async (req, res, next) => { | ||
try { | ||
const token = req.header("x-auth-token"); | ||
if (!token) | ||
return res.status(401).json({ msg: errorMessages.noAuthToken }); | ||
|
||
const verified = jwt.verify(token, passwordKey); | ||
if (!verified) | ||
return res | ||
.status(401) | ||
.json({ msg: errorMessages.tokenVerificationFailed }); | ||
|
||
req.user = verified.id; | ||
req.token = token; | ||
next(); | ||
} catch (err) { | ||
res.status(500).json({ error: err.message }); | ||
} | ||
try { | ||
const bearerHeader = req.headers['authorization']; | ||
if(typeof bearerHeader !== 'undefined') { | ||
const bearer = bearerHeader.split(' '); | ||
const bearerToken = bearer[1]; | ||
// Verify the token | ||
jwt.verify(bearerToken, secretKey, (err, user) => { | ||
if(err) { | ||
res.sendStatus(403); | ||
} else { | ||
req.user = user; | ||
next(); | ||
} | ||
}); | ||
} | ||
} catch (error) { | ||
res.status(500).json({ error: err.message }); | ||
} | ||
}; | ||
|
||
export default auth; |
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,10 @@ | ||
import mongoose from 'mongoose'; | ||
|
||
const achievementSchema = new mongoose.Schema({ | ||
name: { type: String, required: true }, | ||
date: { type: Date, required: true }, | ||
description: { type: String, required: true }, | ||
}); | ||
|
||
const Achievement = mongoose.model('Achievement', achievementSchema); | ||
export default Achievement; |
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,33 @@ | ||
import mongoose from 'mongoose'; | ||
|
||
const courseSchema = new mongoose.Schema({ | ||
name: { | ||
type: String, | ||
required: true | ||
}, | ||
courseCode: { | ||
type: String, | ||
required: true, | ||
unique: true | ||
}, | ||
primaryRoom: { | ||
type: String, | ||
}, | ||
credits: { | ||
type: Number, | ||
required: true, | ||
}, | ||
professorId: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'Faculty', | ||
required: true, | ||
}, | ||
branches: [{ | ||
type: String, | ||
required: true | ||
}] | ||
}); | ||
|
||
const Course = mongoose.model('Course', courseSchema); | ||
|
||
export default Course; |
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,27 @@ | ||
import mongoose from 'mongoose'; | ||
|
||
const facultySchema = new mongoose.Schema({ | ||
name: { | ||
type: String, | ||
default: 'Smart Insti User' | ||
}, | ||
email: { | ||
type: String, | ||
required: true, | ||
unique: true | ||
}, | ||
cabinNumber: { | ||
type: String, | ||
}, | ||
department: { | ||
type: String, | ||
}, | ||
courses: [{ | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'Course' | ||
}], | ||
|
||
}); | ||
|
||
const Faculty = mongoose.model('Faculty', facultySchema); | ||
export default Faculty; |
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,30 @@ | ||
import mongoose from 'mongoose'; | ||
|
||
const lostAndFoundItemSchema = new mongoose.Schema({ | ||
name: { | ||
type: String, | ||
required: true | ||
}, | ||
lastSeenLocation: { | ||
type: String, | ||
}, | ||
imagePath: { | ||
type: String, | ||
}, | ||
description: { | ||
type: String, | ||
required: true | ||
}, | ||
contactNumber: { | ||
type: String, | ||
required: true | ||
}, | ||
isLost: { | ||
type: Boolean, | ||
required: true | ||
} | ||
}); | ||
|
||
const LostAndFoundItem = mongoose.model('LostAndFoundItem', lostAndFoundItemSchema); | ||
|
||
export default LostAndFoundItem; |
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,24 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const messMenuSchema = new mongoose.Schema({ | ||
id: { | ||
type: String, | ||
required: true | ||
}, | ||
kitchenName: { | ||
type: String, | ||
required: true | ||
}, | ||
messMenu: { | ||
type: Map, | ||
of: { | ||
type: Map, | ||
of: [String] | ||
}, | ||
required: true | ||
} | ||
}); | ||
|
||
const MessMenu = mongoose.model('MessMenu', messMenuSchema); | ||
|
||
module.exports = MessMenu; |
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,26 @@ | ||
|
||
const mongoose = require('mongoose'); | ||
|
||
const roomSchema = new mongoose.Schema({ | ||
id: { | ||
type: String, | ||
required: true, | ||
}, | ||
name: { | ||
type: String, | ||
required: true, | ||
}, | ||
vacant: { | ||
type: Boolean, | ||
default: true, | ||
}, | ||
occupantId: { | ||
type: String, | ||
default: null, | ||
}, | ||
}); | ||
|
||
const Room = mongoose.model('Room', roomSchema); | ||
|
||
module.exports = Room; | ||
|
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,9 @@ | ||
import mongoose from 'mongoose'; | ||
|
||
const skillSchema = new mongoose.Schema({ | ||
name: { type: String, required: true }, | ||
level: { type: Number, required: true }, | ||
}); | ||
|
||
const Skill = mongoose.model('Skill', skillSchema); | ||
export default Skill; |
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,41 @@ | ||
import mongoose from 'mongoose'; | ||
const studentSchema = new mongoose.Schema({ | ||
name: { | ||
type: String, | ||
default: 'Smart Insti User' | ||
}, | ||
email: { | ||
type: String, | ||
required: true | ||
}, | ||
rollNumber: { | ||
type: String, | ||
}, | ||
about: { | ||
type: String, | ||
}, | ||
profilePicURI: { | ||
type: String, | ||
}, | ||
branch: { | ||
type: String, | ||
}, | ||
graduationYear: { | ||
type: Number, | ||
}, | ||
skills: [{ | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'Skill' | ||
}], | ||
achievements: [{ | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'Achievement' | ||
}], | ||
roles: { | ||
type: [String], | ||
} | ||
}); | ||
|
||
const Student = mongoose.model('Student', studentSchema); | ||
|
||
export default Student; |
Oops, something went wrong.