Skip to content

Commit 2df6eb9

Browse files
committed
faculty management - addition complete
1 parent 3938276 commit 2df6eb9

File tree

11 files changed

+317
-14
lines changed

11 files changed

+317
-14
lines changed

admin/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,8 @@ router.use('/saving_folder_id', saving_folder_id)
5858

5959
const uploadBib = require("./routes/uploadBib")
6060
router.use('/uploadBib', uploadBib)
61+
62+
const facManagementRouter = require('./routes/faculty-management')
63+
router.use('/faculty-management', facManagementRouter)
64+
6165
module.exports = router
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const User = require('../../../models/user');
2+
3+
const router = require('express').Router()
4+
5+
router.get('/', (req, res) => {
6+
var user = req.session.user;
7+
if (user != undefined) {
8+
res.render('fac-management', {
9+
profileimgsrc: 'images/profiledefault.jfif',
10+
title_top: 'Faculty Management',
11+
user: {
12+
imgUrl: user.imageUrl,
13+
name: user.name,
14+
email: user.email
15+
},
16+
Navbar: req.session.Navbar,
17+
Drive: req.session.isAdmin
18+
})
19+
} else {
20+
res.redirect("/login")
21+
}
22+
})
23+
24+
function check(...args) {
25+
for(let i =0; i<args.length; i++) {
26+
if(args[i] == undefined || args[i]==null || args[i] == '') {
27+
return false;
28+
}
29+
}
30+
return true;
31+
}
32+
router.post('/', (req, res) => {
33+
34+
const {name, email, designation, department, ext_no, role} = req.body
35+
36+
if(check(name, email, designation, department, role) && role != 1) {
37+
// create user
38+
User.create({
39+
name,
40+
email,
41+
designation,
42+
department,
43+
ext_no,
44+
role
45+
})
46+
.then(value => {
47+
res.redirect('/faculty-management')
48+
})
49+
.catch(err => {
50+
res.json(err)
51+
})
52+
}
53+
else {
54+
res.send("all field are neccessary")
55+
}
56+
})
57+
58+
module.exports = router

admin/routes/googlesign.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,13 @@ router.get('/oauth2callback', function(req, res, next) {
105105
link: '/profile',
106106
title: 'Faculty Profile',
107107
id: 'profile'
108-
}]
108+
}, {
109+
link: '/faculty-management',
110+
title: 'Faculty Management',
111+
id: 'fac-management'
112+
}
113+
]
114+
109115
req.session.Navbar = Navbar;
110116
req.session.isAdmin = "true";
111117
// console.log(mainAdmin);

api/README.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fetch(`${BASE_URL}/api/notice`)
1919

2020
<br/>
2121

22-
### 2. `api/notice/active`
22+
### 2. `/api/notice/active`
2323
This route can be used to get all the visible notices in the institute
2424
For example :
2525
```js
@@ -32,10 +32,26 @@ fetch(`${BASE_URL}/api/notice/active`)
3232
console.log(err)
3333
})
3434
```
35+
Response
36+
```json
37+
[
38+
{
39+
"id": 1598709975846,
40+
"title": "first notice",
41+
"timestamp": 1598712753805,
42+
"attachments": [
43+
{
44+
"caption": "well well",
45+
"url": "https://drive.google.com/file/d/13aL6hsRWdWM-bhk3ufkJp2N9MrzkFObW/view?usp=drivesdk"
46+
}
47+
]
48+
}
49+
]
50+
```
3551

3652
<br/>
3753

38-
### 3. `api/notice/archive`
54+
### 3. `/api/notice/archive`
3955
This route can be used to get all the archived (not active) notices in the institute
4056
For example :
4157
```js

app.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
const express = require('express')
22
const db = require('./db')
3+
const bodyParser = require('body-parser');
34

45
const app = express()
56

67

78
app.set('view engine', 'ejs')
89
app.use(express.static("public"));
9-
10+
app.use(bodyParser.json())
11+
app.use(bodyParser.urlencoded({extended: true}))
1012

1113
// Handling api routes
1214
const apiRouter = require('./api')
1315
app.use('/api', apiRouter)
1416

1517

1618
// Handling admin router
17-
const adminRouter = require('./admin')
19+
const adminRouter = require('./admin');
20+
1821
app.use('/', adminRouter)
1922

2023
//**************************** */

models/image.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const db = require('../db');
2+
const User = require('./user');
3+
4+
class Image {
5+
/**
6+
*
7+
* @param {number} id unique id
8+
* @param {string} name varchar(50)
9+
* @param {string} email
10+
* @param {string} imgUrl
11+
*/
12+
constructor(id, name, email, imgUrl) {
13+
this.id = id;
14+
this.name = name;
15+
this.email = email || ''
16+
this.imgUrl = imgUrl || ''
17+
18+
}
19+
/**
20+
* @private
21+
*/
22+
static get tableName() {
23+
return 'images'
24+
}
25+
26+
/**
27+
* @returns {Promise<Object>}
28+
*/
29+
static createTable() {
30+
const query = `
31+
CREATE TABLE ${this.tableName} (
32+
user_id int,
33+
email varchar(50),
34+
image blob,
35+
PRIMARY KEY(user_id),
36+
UNIQUE KEY(email),
37+
FOREIGN KEY(user_id) REFERENCES ${User.tableName}(id) ON DELETE CASCADE
38+
);
39+
`
40+
41+
return db.createTable(this.tableName, query)
42+
43+
}
44+
45+
46+
}
47+
48+
Image.createTable()
49+
50+
module.exports = Image

models/notice.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const db = require('../db')
2-
const { json } = require('body-parser')
3-
2+
const Image = require('./image')
3+
// Image
44
/**
55
*
66
* @param {class} Class

models/user.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const db = require('../db');
22

3-
43
class User {
54
/**
65
*
@@ -9,15 +8,15 @@ class User {
98
* @param {string} email
109
* @param {string} imgUrl
1110
*/
12-
constructor(id, name, email, imgUrl) {
13-
this.id = id;
11+
constructor(name, email, imgUrl) {
12+
1413
this.name = name;
1514
this.email = email || ''
1615
this.imgUrl = imgUrl || ''
1716

1817
}
1918
/**
20-
* @private
19+
*
2120
*/
2221
static get tableName() {
2322
return 'users'
@@ -33,8 +32,6 @@ class User {
3332
name varchar(50),
3433
email varchar(100),
3534
role int(1),
36-
imgUrl varchar(512),
37-
image blob,
3835
department varchar(100),
3936
designation varchar(100),
4037
ext_no int(4),
@@ -93,6 +90,9 @@ class User {
9390
const query = `
9491
INSERT INTO ${User.tableName} SET ?;
9592
`
93+
if(user.id) {
94+
delete user.id
95+
}
9696
return new Promise((res,rej) => {
9797
db.query(query, user, (err, results, fields) => {
9898
if(err) {

public/css/style.css

+7
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ a.active {
6767

6868
.main {
6969
background: rgb(240, 240, 232);
70+
padding: 2% 2%;
71+
}
72+
73+
@media (min-width: 768px) {
74+
.main {
75+
padding: 2% 5%;
76+
}
7077
}
7178

7279
@media(min-width:768px) {

0 commit comments

Comments
 (0)