Skip to content

Commit 1836487

Browse files
committed
Added Middle Name
1 parent bff25f0 commit 1836487

File tree

6 files changed

+133
-120
lines changed

6 files changed

+133
-120
lines changed

app/config/keys.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ const dbURI = 'mongodb://archisbhoir:Archi%40123321@ds351807.mlab.com:51807/nitm
22
const SECRET = 'fdshgchsbfojsd153456ds4fndsjbvjkdsda4sfdfgf564sd56v4f';
33
module.exports = {dbURI, SECRET}
44

5-
//'mongodb://archisbhoir:Archi%40123321@ds351807.mlab.com:51807/nitmoi'
5+
//'mongodb://archisbhoir:Archi%40123321@ds351807.mlab.com:51807/nitmoi'
66
// 'mongodb://localhost:27017/nitmoi'
77
// 'mongodb+srv://archisbhoir:Archi%40123321@cluster0-hn5mn.mongodb.net/test?retryWrites=true&w=majority'

app/models/student.model.js

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
11
const mongoose = require('mongoose')
22

33
const StudentSchema = new mongoose.Schema({
4-
firstName: {
5-
type: String,
6-
require: [true, 'name required mann!!']
7-
},
8-
lastName: {
9-
type: String,
10-
require: [true, 'name required mann!!']
11-
},
12-
Address: String,
13-
standard: {
14-
type: Number,
15-
require: [true, 'std required mann!!']
16-
},
17-
Board: String,
18-
joinedOn: Date,
19-
lastYearmarks: {
20-
physics: Number,
21-
english: Number,
22-
maths: Number
23-
},
24-
sex: String,
25-
fees: {
26-
total: Number,
27-
installments: [{
28-
date: {
29-
type: Date,
30-
},
31-
amount: Number
32-
}],
33-
}
34-
});
4+
firstName: {
5+
type: String,
6+
require: [true, 'name required mann!!']
7+
},
8+
middleName: {
9+
type: String,
10+
},
11+
lastName: {
12+
type: String,
13+
require: [true, 'name required mann!!']
14+
},
15+
Address: {
16+
type: String,
17+
require: [true, 'name required mann!!']
18+
},
19+
standard: {
20+
type: Number,
21+
require: [true, 'std required mann!!']
22+
},
23+
Board: String,
24+
joinedOn: Date,
25+
lastYearmarks: {
26+
physics: Number,
27+
english: Number,
28+
maths: Number
29+
},
30+
sex: String,
31+
fees: {
32+
total: Number,
33+
installments: [{
34+
date: {
35+
type: Date,
36+
},
37+
amount: Number
38+
}],
39+
}
40+
});
3541

3642

3743

client/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
22

3+
34
# dependencies
45
/node_modules
56
/.pnp

client/src/components/add-student/AddStudent.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const customStyles = {
1919
export default class AddStudent extends Component {
2020
constructor() {
2121
super()
22-
this.firstNameEl = React.createRef(); this.lastNameEl = React.createRef();
22+
this.firstNameEl = React.createRef(); this.middleNameEl = React.createRef(); this.lastNameEl = React.createRef();
2323
this.addressEl = React.createRef(); this.standardEl = React.createRef();
2424
this.boardEl = React.createRef(); this.physicsEl = React.createRef();
2525
this.englishEl = React.createRef(); this.mathsEl = React.createRef();
@@ -49,6 +49,7 @@ export default class AddStudent extends Component {
4949
e.preventDefault();
5050
this.setState({ loading: true })
5151
const fName = this.firstNameEl.current.value;
52+
const mName = this.firstNameEl.current.value;
5253
const lName = this.lastNameEl.current.value;
5354
const std = this.standardEl.current.value;
5455
const addr = this.addressEl.current.value;
@@ -60,7 +61,7 @@ export default class AddStudent extends Component {
6061
const fees = this.feesEl.current.value;
6162

6263
const addStudentRequest = {
63-
"firstName": fName, "lastName": lName,
64+
"firstName": fName, "middleName": mName, "lastName": lName,
6465
"Address": addr, "standard": std,
6566
"Board": brd,
6667
"lastYearmarks": {
@@ -105,15 +106,15 @@ export default class AddStudent extends Component {
105106
return (this.state.loading) ? <MyLoader loading={this.state.loading} /> :
106107
<AuthContext.Consumer>
107108
{context => (
108-
<div className="d-lg-flex border justify-content-center p-3">
109+
<div className="d-lg-flex justify-content-center p-3">
109110
<h3>Add New Student</h3>
110-
<form onSubmit={this.handleAddForm}>
111+
<form className="py-3" onSubmit={this.handleAddForm}>
111112
<div className="row py-3">
112113
<div className="col">
113114
<input type="text" ref={this.firstNameEl} className="form-control" placeholder="First name" required />
114115
</div>
115116
<div className="col">
116-
<input type="text" className="form-control" placeholder="Middle name" />
117+
<input type="text" ref={this.middleNameEl} className="form-control" placeholder="Middle name" />
117118
</div>
118119
<div className="col">
119120
<input type="text" ref={this.lastNameEl} className="form-control" placeholder="Last name" required />

client/src/components/fees/Fee.js

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import React, {useEffect, useState} from 'react'
1+
import React, { useEffect, useState } from 'react'
22
import './fees.css'
33
import Modal from 'react-modal'
44
import MyCalendar from '../reusables/Calendar'
55
import MyLoader from '../reusables/MyLoader'
66

77
const customStyles = {
8-
content : {
9-
top : '50%',
10-
left : '50%',
11-
right : 'auto',
12-
bottom : 'auto',
13-
marginRight : '-50%',
14-
transform : 'translate(-50%, -50%)'
8+
content: {
9+
top: '50%',
10+
left: '50%',
11+
right: 'auto',
12+
bottom: 'auto',
13+
marginRight: '-50%',
14+
transform: 'translate(-50%, -50%)'
1515
}
1616
};
1717

@@ -22,49 +22,49 @@ const Fee = (props) => {
2222
const [date, setDate] = useState(new Date())
2323
const [amount, setAmount] = useState(Number)
2424
const [dateModalOpen, setDateModalOpen] = useState(false)
25-
26-
useEffect(()=> getStudents(),[])
2725

28-
const getStudents = ()=>{
26+
useEffect(() => getStudents(), [])
27+
28+
const getStudents = () => {
2929
setLoading(true)
30-
fetch('/api/students',{
30+
fetch('/api/students', {
3131
method: 'GET',
3232
mode: 'cors',
3333
headers: {
3434
'Content-Type': 'application/json'
3535
}
3636
})
37-
.then(res => {
38-
if (res.status !== 200 && res.status !== 201) {
39-
if(res.status === 401){
40-
setLoading(false)
41-
props.history.push('/login')
42-
}
43-
if(res.status === 404){
37+
.then(res => {
38+
if (res.status !== 200 && res.status !== 201) {
39+
if (res.status === 401) {
40+
setLoading(false)
41+
props.history.push('/login')
42+
}
43+
if (res.status === 404) {
44+
setLoading(false)
45+
return <h4>Not Found !!</h4>
46+
}
4447
setLoading(false)
45-
return <h4>Not Found !!</h4>
48+
throw new Error(res.status)
4649
}
50+
return res.json()
51+
})
52+
.then(resdata => {
4753
setLoading(false)
48-
throw new Error(res.status)
49-
}
50-
return res.json()
51-
})
52-
.then(resdata => {
53-
setLoading(false)
54-
setStudents(resdata)
55-
})
56-
.catch(err => {
57-
console.log(err)
58-
setLoading(false)
59-
})
54+
setStudents(resdata)
55+
})
56+
.catch(err => {
57+
console.log(err)
58+
setLoading(false)
59+
})
6060
}
6161

6262
const selectStudent = (obj, e) => {
6363
e.preventDefault();
6464
setSelectedStudent(obj)
6565
}
6666

67-
const isEmpty = (obj) => {
67+
const isEmpty = (obj) => {
6868
for (var key in obj) {
6969
if (hasOwnProperty.call(obj, key)) return false
7070
}
@@ -90,107 +90,107 @@ const Fee = (props) => {
9090
"date": date,
9191
"amount": amount
9292
}
93-
fetch('/api/fee/installment/'+ selectedStudent._id,{
94-
method: 'PUT' ,
93+
fetch('/api/fee/installment/' + selectedStudent._id, {
94+
method: 'PUT',
9595
mode: 'cors',
9696
headers: {
9797
'content-type': 'application/json'
9898
},
9999
body: JSON.stringify(body)
100100
})
101-
.then(res=>{
102-
if (res.status !== 200 && res.status !== 201) {
103-
if(res.status === 401){
101+
.then(res => {
102+
if (res.status !== 200 && res.status !== 201) {
103+
if (res.status === 401) {
104+
setLoading(false)
105+
props.history.push('/login')
106+
}
107+
if (res.status === 404) {
108+
setLoading(false)
109+
return <h4>Not Found !!</h4>
110+
}
104111
setLoading(false)
105-
props.history.push('/login')
106-
}
107-
if(res.status === 404){
108-
setLoading(false)
109-
return <h4>Not Found !!</h4>
112+
throw new Error(res.status)
110113
}
114+
return res.json();
115+
})
116+
.then(data => {
111117
setLoading(false)
112-
throw new Error(res.status)
113-
}
114-
return res.json();
115-
})
116-
.then(data=>{
117-
setLoading(false)
118-
getStudents()
119-
setSelectedStudent(data)
120-
})
121-
.catch(err=>{
122-
console.log(err)
123-
setLoading(false)
124-
})
118+
getStudents()
119+
setSelectedStudent(data)
120+
})
121+
.catch(err => {
122+
console.log(err)
123+
setLoading(false)
124+
})
125125
}
126-
127-
const remainingFees = ()=>{
128-
const {total, installments} = selectedStudent.fees;
126+
127+
const remainingFees = () => {
128+
const { total, installments } = selectedStudent.fees;
129129
let temp = total;
130130
installments.map(inst => (temp = temp - inst.amount))
131131
return <h6>{temp}</h6>
132132
}
133-
134-
const {fees} = selectedStudent;
133+
134+
const { fees } = selectedStudent;
135135

136136
return (loading) ?
137-
<MyLoader loading={loading} />:
137+
<MyLoader loading={loading} /> :
138138
<div className="container">
139139
<h1 className='main-heading'>Fees</h1>
140140
<div className="row">
141141
<div className="col-md-4">
142142
<table className="table table-dark">
143-
<thead onClick={e=> setSelectedStudent({})}>
143+
<thead onClick={e => setSelectedStudent({})}>
144144
<tr>
145145
<th scope='col'>#</th>
146146
<th scope='col'>Student</th>
147147
</tr>
148148
</thead>
149149
<tbody>
150-
{
151-
students.sort((a,b)=> {return a.standard-b.standard}).map((stud, i)=>(
152-
<tr key={i} onClick={e=>selectStudent(stud,e)}>
153-
<th scope='row'>{i}</th>
154-
<td>{stud.firstName} {stud.lastName}</td>
155-
</tr>
156-
))
157-
}
150+
{
151+
students.sort((a, b) => { return a.standard - b.standard }).map((stud, i) => (
152+
<tr key={i} onClick={e => selectStudent(stud, e)}>
153+
<th scope='row'>{i}</th>
154+
<td>{stud.firstName} {stud.lastName}</td>
155+
</tr>
156+
))
157+
}
158158
</tbody>
159159
</table>
160160
</div>
161161
{!isEmpty(selectedStudent) && <div className="col bg-dark text-white pt-3 fees">
162162
<div className="col-md total">
163163
<h5>Total Fees</h5>
164-
<hr className='border'/>
164+
<hr className='border' />
165165
{!isEmpty(selectedStudent) && <h6>{fees.total}</h6>}
166166
</div>
167167
<div className="col rem">
168168
<h5>Remaining Fees</h5>
169-
<hr className='border'/>
169+
<hr className='border' />
170170
{!isEmpty(selectedStudent) && <span>{remainingFees()}</span>}
171171
</div>
172172
</div>}
173173
<div className="h-100 border"></div>
174174
{!isEmpty(selectedStudent) && <div className="col-md bg-dark text-white pt-3 fees">
175175
<div className="col paid">
176176
<h5>Installments Paid</h5>
177-
<hr className='border'/>
177+
<hr className='border' />
178178
{!isEmpty(selectedStudent) && <h6>{fees.installments
179-
.map((inst,i)=> <div key={i}>{inst.amount}</div>)}</h6>}
179+
.map((inst, i) => <div key={i}>{inst.amount}</div>)}</h6>}
180180
</div>
181181

182182
<div className="col new">
183183
<h5>Add Installment</h5>
184-
<hr className='border'/>
184+
<hr className='border' />
185185
<form onSubmit={handleSubmit}>
186186
<div className="form-group">
187187
<label htmlFor="installment">Amount</label>
188-
<input type="tel" onChange={e=> setAmount(e.target.value)} className='form-control form-control-sm' name="installment" required/>
188+
<input type="tel" onChange={e => setAmount(e.target.value)} className='form-control form-control-sm' name="installment" required />
189189
<label htmlFor="date">Date</label>
190190
<i className="far fa-calendar-alt btn-lg" id="date" onClick={openModal}></i>
191191
<p>Selected Date:- {date.toLocaleString('en-IN').split(',')[0]}</p>
192192
</div>
193-
<input type="submit" className='btn btn-sm btn-light mt-3' value="Add Installment"/>
193+
<input type="submit" className='btn btn-sm btn-light mt-3' value="Add Installment" />
194194
</form>
195195
</div>
196196
</div>}

0 commit comments

Comments
 (0)