Skip to content

Commit 7d128d1

Browse files
company transaction added
1 parent f6bc87c commit 7d128d1

29 files changed

Lines changed: 1720 additions & 279 deletions
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
const formidable = require("formidable");
2+
const _ = require("lodash");
3+
const slugify = require("slugify");
4+
const CompanyPayment = require('../../Modules/Accountant/module.company.payment');
5+
6+
/**
7+
* Create Company Payment controller
8+
* @param req
9+
* @param res
10+
* @returns {Promise<any>}
11+
*/
12+
const createCompanyPayment = (req, res) => {
13+
const {name,amount,date,type} = req.body
14+
// validate fields
15+
if(!name || !amount|| !date|| !type) {
16+
return res.status(400).json({
17+
error: "All fields are required"
18+
});
19+
}
20+
21+
CompanyPayment.create({name,amount,date,type},(err,name) => {
22+
if(err) {
23+
return res.status(400).json({
24+
error: 'Error Found'
25+
});
26+
}
27+
res.json(name);
28+
});
29+
}
30+
31+
/**
32+
* Get all Company Payments controller
33+
* @param req
34+
* @param res
35+
* @returns {Promise<any>}
36+
*/
37+
const getAllCompanyPayment = (req, res) => {
38+
let order = req.query.order ? req.query.order : 'asc'
39+
let sortBy = req.query.sortBy ? req.query.sortBy : '_id'
40+
41+
CompanyPayment.find()
42+
.sort([[sortBy, order]])
43+
.exec((err, companyPayments) => {
44+
if(err) {
45+
return res.status(400).json ({
46+
error: 'No company Payment Found'
47+
});
48+
}
49+
res.json(companyPayments);
50+
});
51+
}
52+
53+
/**
54+
* Get a specific Company payment controller
55+
* @param req
56+
* @param res
57+
* @param next
58+
* @param id
59+
* @returns {Promise<any>}
60+
*/
61+
const companyPaymentById = async (req, res) => {
62+
if (req.params && req.params.id) {
63+
await CompanyPayment.findById(req.params.id)
64+
.then(response => {
65+
res.status(200).send({data: response});
66+
})
67+
.catch(error => {
68+
res.status(500).send({error: error.message});
69+
});
70+
}
71+
};
72+
73+
/**
74+
* Update the company payment controller
75+
* @param req
76+
* @param res
77+
* @returns {Promise<any>}
78+
*/
79+
const updateById = async(req, res) => {
80+
const { slug } = req.params
81+
const {name,amount,date,type} = req.body
82+
CompanyPayment.findOneAndUpdate({slug}, {name,amount,date,type}, {new: true})
83+
.exec((err,topic) => {
84+
if(err) console.log(err)
85+
res.json(topic);
86+
})
87+
};
88+
89+
/**
90+
* Delete company Payment controller
91+
* @param req
92+
* @param res
93+
* @returns {Promise<any>}
94+
*/
95+
const deleteById = async (req, res) => {
96+
const id = req.params.id
97+
await CompanyPayment.findByIdAndRemove(id).exec()
98+
res.send("Payment Deleted successfully");
99+
};
100+
101+
/**
102+
* export controllers
103+
* @type {{companyPaymentById: companyPaymentById,
104+
* createCompanyPayment: createCompanyPayment,
105+
* getAllCompanyPayment: getAllCompanyPayment,
106+
* updateById: updateById,
107+
* deleteById: deleteById}}
108+
*/
109+
module.exports = {
110+
companyPaymentById,
111+
createCompanyPayment,
112+
getAllCompanyPayment,
113+
updateById,
114+
deleteById
115+
}

Backend/Middlewares/authJwt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const db = require("../Modules");
44
const User = db.user;
55
const Role = db.role;
66

7-
87
verifyToken = (req, res, next) => {
98
let token = req.headers["x-access-token"];
109

@@ -144,6 +143,7 @@ verifyToken = (req, res, next) => {
144143
);
145144
});
146145
};
146+
147147
const authJwt = {
148148
verifyToken,
149149
isAdmin,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const mongoose = require('mongoose');
2+
const { ObjectId } = mongoose.Schema;
3+
4+
const CompanyPaymentSchema = new mongoose.Schema(
5+
{
6+
name: {
7+
type: String,
8+
required: true,
9+
trim: true,
10+
min: 1,
11+
max: 50
12+
},
13+
amount : {
14+
type: Number,
15+
required: true
16+
},
17+
date: {
18+
type: Date,
19+
required: true
20+
},
21+
type: {
22+
type: String,
23+
required: true,
24+
}
25+
},
26+
{ timestamps: true}
27+
);
28+
29+
module.exports = mongoose.model('companypayments', CompanyPaymentSchema);
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.company.payment');
4+
5+
module.exports = function () {
6+
//POST Company Payment
7+
router.post('/create', controller.createCompanyPayment);
8+
//GET Company Payment
9+
router.get('/', controller.getAllCompanyPayment);
10+
//GET Company Payment By ID
11+
router.get('/:id', controller.companyPaymentById);
12+
//DELETE Company 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/package-lock.json

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

Backend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"nodemon": "^2.0.12"
1414
},
1515
"devDependencies": {
16-
"formidable": "^1.2.2"
16+
"formidable": "^1.2.2",
17+
"slugify": "^1.6.0"
1718
}
1819
}

Backend/server.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const bodyParser = require('body-parser');
66
const TeacherAPI = require('./Routes/Teacher/route.teacher');
77
const ProfileAPI = require('./Routes/Teacher/route.tprofile');
88
const studentPaymentRoute = require('./Routes/Accountant/route.student.payment');
9+
const companyPaymentRoute = require('./Routes/Accountant/route.company.payment');
910

1011
dotenv.config();
1112
const app = express();
@@ -56,6 +57,7 @@ require('./routes/user.routes')(app);
5657
app.use('/teacher', TeacherAPI());
5758
app.use('/profile', ProfileAPI());
5859
app.use('/student-payment', studentPaymentRoute());
60+
app.use('/company-payment', companyPaymentRoute());
5961

6062
app.listen(PORT, () => {
6163
console.log('######################################################');

0 commit comments

Comments
 (0)