Skip to content

Commit 228750d

Browse files
branch Upto date
2 parents eb284b7 + 778f7d2 commit 228750d

75 files changed

Lines changed: 27756 additions & 946 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
const formidable = require("formidable");
2+
const _ = require("lodash");
3+
const fs = require("fs");
4+
const StudentPayment = require('../../Modules/Class/module.class');
5+
6+
/**
7+
* Get a specific Student payment controller
8+
* @param req
9+
* @param res
10+
* @param next
11+
* @param id
12+
* @returns {Promise<any>}
13+
*/
14+
const studentPaymentById = (req, res, next, id) => {
15+
StudentPayment.findById(id).exec((err,studentPayment) => {
16+
if (err || !studentPayment) {
17+
return res.status(400).json({
18+
error: "Payment not found"
19+
});
20+
}
21+
req.studentPayment = studentPayment;
22+
next();
23+
});
24+
};
25+
26+
// get the payment details except photo
27+
const read = (req, res) => {
28+
req.studentPayment.paymentSlip = undefined;
29+
return res.json(req.studentPayment);
30+
};
31+
32+
/**
33+
* Create Student Payment controller
34+
* @param req
35+
* @param res
36+
* @returns {Promise<any>}
37+
*/
38+
const createTeacherTask = (req, res) => {
39+
let form = new formidable.IncomingForm()
40+
form.keepExtensions = true
41+
form.parse(req, (err, fields, files) => {
42+
if(err) {
43+
return res.status(400).json({
44+
error: "Image could not be uploaded"
45+
});
46+
}
47+
let studentPayment = new StudentPayment(fields)
48+
49+
const {name,contactNo, studentID,depositedAmount,depositedDate,bank,branch,type,classes,teacher} = fields
50+
51+
// validate fields
52+
if(!name || !contactNo|| !studentID|| !depositedAmount|| !depositedDate || !bank || !branch || !type || !classes || !teacher) {
53+
return res.status(400).json({
54+
error: "All fields are required"
55+
});
56+
}
57+
58+
// validate photo size
59+
if(files.paymentSlip) {
60+
if(files.paymentSlip.size > 10000000) {
61+
return res.status(400).json({
62+
error: "Image should be less than 10mb in size"
63+
});
64+
}
65+
studentPayment.paymentSlip.data = fs.readFileSync(files.paymentSlip.path)
66+
studentPayment.paymentSlip.contentType = files.paymentSlip.type
67+
}
68+
69+
studentPayment.save((err, result) => {
70+
if(err) {
71+
return res.status(400).json({
72+
error: 'Error Found'
73+
});
74+
}
75+
res.json(result);
76+
});
77+
});
78+
}
79+
80+
/**
81+
* Get all Student Payments controller
82+
* @param req
83+
* @param res
84+
* @returns {Promise<any>}
85+
*/
86+
const getAllStudentPayment = (req, res) => {
87+
let order = req.query.order ? req.query.order : 'asc'
88+
let sortBy = req.query.sortBy ? req.query.sortBy : '_id'
89+
90+
StudentPayment.find()
91+
.select("-paymentSlip")
92+
.sort([[sortBy, order]])
93+
.exec((err, studentPayments) => {
94+
if(err) {
95+
return res.status(400).json ({
96+
error: 'No Student Payment Found'
97+
});
98+
}
99+
res.json(studentPayments);
100+
});
101+
}
102+
103+
// get the photo of conference
104+
const photo = (req, res, next) => {
105+
if(req.studentPayment.paymentSlip.data) {
106+
res.set('Content-Type', req.studentPayment.paymentSlip.contentType)
107+
return res.send(req.studentPayment.paymentSlip.data);
108+
}
109+
next();
110+
};
111+
112+
/**
113+
* Update only the status of student payment controller
114+
* @param req
115+
* @param res
116+
* @returns {Promise<any>}
117+
*/
118+
const updateStatus = async (req, res) => {
119+
const id = req.params.id;
120+
const {status} = req.body;
121+
const updateStudentPayment = {
122+
status
123+
}
124+
const update = await StudentPayment.findByIdAndUpdate(id, updateStudentPayment)
125+
.then(() => {
126+
res.status(200).send({status: "Status Updated"})
127+
}).catch((err) => {
128+
console.log(err);
129+
res.status(500).send({status: " Error", error:err.message});
130+
})
131+
}
132+
133+
/**
134+
* Update the student payment controller
135+
* @param req
136+
* @param res
137+
* @returns {Promise<any>}
138+
*/
139+
const updateById = async(req, res) => {
140+
let form = new formidable.IncomingForm()
141+
form.keepExtensions = true
142+
form.parse(req, (err, fields, files) => {
143+
if(err) {
144+
return res.status(400).json({
145+
error: "Image could not be uploaded"
146+
});
147+
}
148+
149+
const {name,contactNo, studentID,depositedAmount,depositedDate,bank,branch,type,classes,teacher} = fields
150+
151+
let studentPayment = req.studentPayment;
152+
studentPayment = _.extend(studentPayment,fields)
153+
154+
if(files.paymentSlip) {
155+
if(files.paymentSlip.size > 10000000) {
156+
return res.status(400).json({
157+
error: "Image should be less than 10mb in size"
158+
});
159+
}
160+
studentPayment.paymentSlip.data = fs.readFileSync(files.paymentSlip.path)
161+
studentPayment.paymentSlip.contentType = files.paymentSlip.type
162+
}
163+
164+
studentPayment.save((err, result) => {
165+
if(err) {
166+
return res.status(400).json({
167+
error: "Update Failed"
168+
});
169+
}
170+
res.json(result);
171+
});
172+
});
173+
};
174+
175+
/**
176+
* Delete student Payment controller
177+
* @param req
178+
* @param res
179+
* @returns {Promise<any>}
180+
*/
181+
const deleteById = (req, res) => {
182+
let studentPayment = req.studentPayment
183+
studentPayment.remove((err, deletedPayment) => {
184+
if(err) {
185+
return res.status(400).json({
186+
error: "Error On Delete"
187+
});
188+
}
189+
res.json({
190+
deletedPayment,
191+
message: "Payment Deleted successfully"
192+
});
193+
});
194+
};
195+
196+
/**
197+
* Calculate total Fee controller
198+
* @param req
199+
* @param res
200+
* @returns {Promise<any>}
201+
*/
202+
const calculateAmount = async (req, res) => {
203+
204+
}
205+
206+
/**
207+
* export controllers
208+
* @type {{createStudentPayment: createStudentPayment,
209+
* getAllStudentPayment: getAllStudentPayment,
210+
* viewStudentPaymentById: viewStudentPaymentById,
211+
* updateById: updateById,
212+
* deleteById: deleteById,
213+
* calculateAmount: calculateAmount}}
214+
*/
215+
module.exports = {
216+
studentPaymentById,
217+
read,
218+
createStudentPayment,
219+
getAllStudentPayment,
220+
photo,
221+
updateStatus,
222+
updateById,
223+
deleteById,
224+
calculateAmount
225+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
const formidable = require("formidable");
2+
const _ = require("lodash");
3+
const fs = require("fs");
4+
const {next} = require("lodash");
5+
const teacherTask = require('../../Modules/Class/module.class');
6+
7+
const createteacherTask = async (req, res) => {
8+
if(req.body) {
9+
const teacher = new teacherTask(req.body);
10+
await teacher.save()
11+
.then(data=>{
12+
res.status(200).send({data: data});
13+
})
14+
.catch(error =>{
15+
res.status(500).send({error: error.message});
16+
});
17+
}
18+
}
19+
const getAllteacherTask = async (req, res) => {
20+
let order = req.query.order ? req.query.order : 'asc'
21+
let sortBy = req.query.sortBy ? req.query.sortBy : '_id'
22+
23+
teacherTask.find()
24+
.sort([[sortBy, order]])
25+
.exec((err, teacherTask) => {
26+
if(err) {
27+
return res.status(400).json ({
28+
error: 'No task Found'
29+
});
30+
}
31+
res.json(teacherTask);
32+
});
33+
}
34+
35+
const viewteacherTaskById = async (req, res) => {
36+
teacherTask.findById(req.params.id, (error, data) =>{
37+
if (error) {
38+
return next(error)
39+
} else {
40+
res.json(data)
41+
}
42+
})
43+
}
44+
45+
46+
const updateById = async (req, res) => {
47+
const { slug } = req.params
48+
const {tasktitle,taskdescription,teacherid,implevel,validtill,status} = req.body
49+
teacherTask.findOneAndUpdate({slug}, {tasktitle,taskdescription,teacherid,implevel,validtill,status}, {new: true})
50+
.exec((err,topic) => {
51+
if(err) console.log(err)
52+
res.json(topic);
53+
})
54+
}
55+
56+
const deleteById = async (req, res) => {
57+
const id = req.params.id
58+
await teacherTask.findByIdAndRemove(id).exec()
59+
res.send("Deleted successfully");
60+
};
61+
62+
/**
63+
* Update only the status of student payment controller
64+
* @param req
65+
* @param res
66+
* @returns {Promise<any>}
67+
*/
68+
const updateStatus = async (req, res) => {
69+
const id = req.params.id;
70+
const {status} = req.body;
71+
const updateStatus= {
72+
status
73+
}
74+
const update = await teacherTask.findByIdAndUpdate(id, updateStatus)
75+
.then(() => {
76+
res.status(200).send({status: "Status Updated"})
77+
}).catch((err) => {
78+
console.log(err);
79+
res.status(500).send({status: " Error", error:err.message});
80+
})
81+
}
82+
83+
module.exports = {
84+
createteacherTask,
85+
getAllteacherTask,
86+
viewteacherTaskById,
87+
updateById,
88+
deleteById,
89+
updateStatus
90+
}

Backend/Controllers/Teacher/controller.tprofile.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const updateProfileById = async (req, res) => {
4545
}
4646
const update = await Profile.findByIdAndUpdate(id, updateProfile)
4747
.then(() => {
48-
res.status(200).send({status: "Teacher Profile Updated"})
48+
res.status(200).send({status: "Teacher Profile status Updated"})
4949
}).catch((err) => {
5050
console.log(err);
5151
res.status(500).send({status: " Error", error:err.message});
@@ -58,10 +58,21 @@ const deleteProfileById = async (req, res) => {
5858
res.send('Teacher Profile Deleted');
5959
}
6060

61+
const updateById = async(req, res) => {
62+
const { slug } = req.params
63+
const {registrationNumber, fName, lName, nic, passportNumber, address, contactNumber, email, password, editedDate} = req.body
64+
Profile.findOneAndUpdate({slug}, {registrationNumber, fName, lName, nic, passportNumber, address, contactNumber, email, password, editedDate}, {new: true})
65+
.exec((err,topic) => {
66+
if(err) console.log(err)
67+
res.json(topic);
68+
})
69+
};
70+
6171
module.exports = {
6272
createProfile,
6373
getAllProfiles,
6474
viewProfileById,
6575
updateProfileById,
66-
deleteProfileById
76+
deleteProfileById,
77+
updateById
6778
}

Backend/Modules/Class/module.class.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,18 @@ const ClassSchema = new mongoose.Schema({
2222
implevel: {
2323
type: String,
2424
trim: true
25-
},
25+
},
2626
validtill: {
2727
type: String,
2828
trim: true
29-
},
30-
extrainfo : {
31-
3229
},
3330
status: {
3431
type: String,
35-
default: "not approved"
36-
},
37-
});
32+
default: "not done"
33+
}
34+
},
35+
{ timestamps: true}
36+
);
3837

39-
const Class = mongoose.model('class', ClassSchema);
38+
const Class = mongoose.model('classess', ClassSchema);
4039
module.exports = Class;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const express = require('express');
2+
const router = express.Router();
3+
const controller = require('../../Controllers/Teacher/controller.teacherTask');
4+
5+
module.exports = function () {
6+
router.post('/createTeacherTask', controller.createteacherTask);
7+
router.get('/TeacherTask', controller.getAllteacherTask);
8+
router.get('/TeacherTask/:id', controller.viewteacherTaskById);
9+
router.put('/TeacherTask/:id', controller.updateById);
10+
router.delete('/TeacherTask/:id', controller.deleteById);
11+
router.put('/TeacherTask/status/:id', controller.updateStatus);
12+
return router;
13+
}

0 commit comments

Comments
 (0)