Skip to content

Commit 4992475

Browse files
backend student payment
1 parent fa1180f commit 4992475

6 files changed

Lines changed: 198 additions & 1 deletion

File tree

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
const StudentPayment = require('../../Modules/Accountant/module.student.payment');
2+
3+
/**
4+
* Create Student Payment controller
5+
* @param req
6+
* @param res
7+
* @returns {Promise<any>}
8+
*/
9+
const createStudentPayment = async (req, res) => {
10+
if(req.body) {
11+
const studentPayment = new StudentPayment(req.body);
12+
await studentPayment.save()
13+
.then(data=>{
14+
res.status(200).send({data: data});
15+
})
16+
.catch(error =>{
17+
res.status(500).send({error: error.message});
18+
});
19+
}
20+
}
21+
22+
/**
23+
* Get all Student Payments controller
24+
* @param req
25+
* @param res
26+
* @returns {Promise<any>}
27+
*/
28+
const getAllStudentPayment = async (req, res) => {
29+
await StudentPayment.find({})
30+
.then(data=>{
31+
res.status(200).send({data: data});
32+
})
33+
.catch(error =>{
34+
res.status(500).send({error: error.message});
35+
});
36+
}
37+
38+
/**
39+
* Get a specific Student payment controller
40+
* @param req
41+
* @param res
42+
* @returns {Promise<any>}
43+
*/
44+
const viewStudentPaymentById = async (req, res) => {
45+
if (req.params && req.params.id) {
46+
await StudentPayment.findById(req.params.id)
47+
.populate('studentpayments', '_id name contactNo studentID depositedAmount depositedDate bank branch paymentSlip status type class teacher')
48+
.then(response => {
49+
res.status(200).send({ data: response });
50+
})
51+
.catch(error => {
52+
res.status(500).send({ error: error.message });
53+
});
54+
}
55+
}
56+
57+
/**
58+
* Update the status of student payment controller
59+
* @param req
60+
* @param res
61+
* @returns {Promise<any>}
62+
*/
63+
const updateById = async (req, res) => {
64+
const id = req.params.id;
65+
const {status} = req.body;
66+
const updateStudentPayment = {
67+
status
68+
}
69+
const update = await StudentPayment.findByIdAndUpdate(id, updateStudentPayment)
70+
.then(() => {
71+
res.status(200).send({status: "Status Updated"})
72+
}).catch((err) => {
73+
console.log(err);
74+
res.status(500).send({status: " Error", error:err.message});
75+
})
76+
}
77+
78+
/**
79+
* Delete student Payment controller
80+
* @param req
81+
* @param res
82+
* @returns {Promise<any>}
83+
*/
84+
const deleteById = async (req, res) => {
85+
const id = req.params.id
86+
await StudentPayment.findByIdAndRemove(id).exec()
87+
res.send('itemDeleted');
88+
}
89+
90+
/**
91+
* export controllers
92+
* @type {{createStudentPayment: createStudentPayment,
93+
* getAllStudentPayment: getAllStudentPayment,
94+
* viewStudentPaymentById: viewStudentPaymentById,
95+
* updateById: updateById,
96+
* deleteById: deleteById}}
97+
*/
98+
module.exports = {
99+
createStudentPayment,
100+
getAllStudentPayment,
101+
viewStudentPaymentById,
102+
updateById,
103+
deleteById
104+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const mongoose = require('mongoose');
2+
3+
const StudentPaymentSchema = new mongoose.Schema({
4+
name: {
5+
type: String,
6+
required: true,
7+
min: 1,
8+
max: 50
9+
},
10+
contactNo: {
11+
type: String,
12+
required: true
13+
},
14+
studentID: {
15+
type: String,
16+
required: true,
17+
min: 1,
18+
max: 20
19+
},
20+
depositedAmount : {
21+
type: Number,
22+
required: true
23+
},
24+
depositedDate: {
25+
type: Date,
26+
required: true
27+
},
28+
bank: {
29+
type: String,
30+
required: true
31+
},
32+
branch: {
33+
type: String,
34+
required: true
35+
},
36+
paymentSlip: {
37+
type: String,
38+
required:true
39+
},
40+
status: {
41+
type: String,
42+
default: "not decided"
43+
},
44+
type: {
45+
type: String,
46+
required: true,
47+
},
48+
class: {
49+
type: String,
50+
required: true,
51+
},
52+
teacher: {
53+
type: String,
54+
required: true,
55+
}
56+
/*class: [{
57+
type: mongoose.Schema.Types.ObjectId,
58+
required: false,
59+
ref: 'classes'
60+
}],*/
61+
/*teacher: [{
62+
type: mongoose.Schema.Types.ObjectId,
63+
required: false,
64+
ref: 'teachers'
65+
}]*/
66+
});
67+
68+
module.exports = mongoose.model('studentpayments', StudentPaymentSchema);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const express = require('express');
2+
const router = express.Router();
3+
const controller = require('../../Controllers/Accountant/controller.student.payment');
4+
5+
module.exports = function () {
6+
//POST Student Payment
7+
router.post('/create', controller.createStudentPayment);
8+
//GET Student Payment
9+
router.get('/', controller.getAllStudentPayment);
10+
//GET Student Payment By ID
11+
router.get('/viewbyid/:id', controller.viewStudentPaymentById);
12+
//DELETE Student Payment By ID
13+
router.delete('/delete/:id', controller.deleteById);
14+
//UPDATE payment status
15+
router.put('/update/:id', controller.updateById);
16+
return router;
17+
}

Backend/server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const dotenv = require('dotenv');
44
const cors = require('cors');
55
const bodyParser = require('body-parser');
66

7+
const studentPaymentRoute = require('./Routes/Accountant/route.student.payment');
8+
79
dotenv.config();
810
const app = express();
911
app.use(cors());
@@ -38,7 +40,7 @@ app.route('/').get((req, res) => {
3840
});
3941

4042
//API endpoints
41-
43+
app.use('/student-payment', studentPaymentRoute());
4244

4345

4446
app.listen(PORT,()=>{

frontend/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"@testing-library/react": "^11.1.0",
88
"@testing-library/user-event": "^12.1.10",
99
"axios": "^0.21.1",
10+
"moment": "^2.29.1",
1011
"react": "^17.0.2",
1112
"react-dom": "^17.0.2",
1213
"react-router-dom": "^5.2.0",

0 commit comments

Comments
 (0)