Surya:statement master crud apis & models changes

This commit is contained in:
surya 2021-08-14 10:47:12 +05:30
parent 896222af0c
commit 65294af68d
6 changed files with 479 additions and 5 deletions

View File

@ -0,0 +1,448 @@
//const db = require("../models");
//const Entities = db.tutorials;
//const Op = db.Sequelize.Op;
const { sequelize, Statementsmaster ,Sectionsmaster , Subsectionsmaster,Itemsmaster } = require('../models')
const { logMsg } = require('../services/logger.js');
//statementmaster
// Retrieve all statementmaster from the database.
exports.StatmentList = (req, res) => {
Statementsmaster.findAll()
.then(data => {
res.send({'status':200,'message':"success",'data':data});
logMsg.info("Success :"(data));
})
.catch(err => {
res.status(500).send({'status':404,
message: err.message || "Some error occurred while retrieving tutorials." ,'data': "No data" });
});
};
exports.Insertstatement = (req, res) => {
// Create a statement
const statement = {
statement: req.body.statement,
is_active: req.body.is_active,
createdby: req.body.createdby,
updatedby: req.body.updatedby,
};
// Save Tutorial in the database
Statementsmaster.create(statement)
.then(data => {
res.send(data);
})
.catch(err => {
res.status(500).send({
message:
err.message || "Some error occurred while creating the statement."
});
});
};
// Post a statement
// insert datas into statementmaster table.
// exports.Insertstatement = (req, res) => {
// Statementsmaster.create({
// statement: req.body.statement,
// is_active: req.body.is_active,
// createdby: req.body.createdby,
// updatedby: req.body.updatedby,
// })
// .then(data => {
// res.send({'status':200,'message':"success",'data':data});
// logMsg.info("Success :"(data));
// })
// .catch(err => {
// res.status(500).send({'status':404,
// message: err.message || "Some error occurred while retrieving tutorials." ,'data': "No data" });
// });
// };
// updates datas into statementmaster table.
exports.Updatestatement = (req, res) => {
const id = req.params.id;
Statementsmaster.update(req.body, {
where: { id: id }
})
.then(num => {
if (num == 1) {
res.send({
message: "statement was updated successfully."
});
} else {
res.send({
message: `Cannot update statement with id=${id}. Maybe statement was not found or req.body is empty!`
});
}
})
.catch(err => {
res.status(500).send({
message: "Error updating statement with id=" + id
});
});
};
//delete
exports.Deletestatement = (req, res) => {
const id = req.params.id;
Statementsmaster.destroy({
where: { id: id }
})
.then(num => {
if (num == 1) {
res.send({
message: "statement was deleted successfully!"
});
} else {
res.send({
message: `Cannot delete statement with id=${id}. Maybe statement was not found!`
});
}
})
.catch(err => {
res.status(500).send({
message: "Could not delete statement with id=" + id
});
});
};
//Sectionsmaster
// Retrieve all Sectionsmaster from the database.
exports.SectionList = (req, res) => {
Sectionsmaster.findAll()
.then(data => {
res.send({'status':200,'message':"success",'data':data});
logMsg.info("Success :"(data));
})
.catch(err => {
res.status(500).send({'status':404,
message: err.message || "Some error occurred while retrieving sections." ,'data': "No data" });
});
};
exports.Insertsection = (req, res) => {
// Create a section
const section = {
statement: req.body.statement,
section: req.body.section,
is_active: req.body.is_active,
createdby: req.body.createdby,
updatedby: req.body.updatedby,
};
// Save section in the database
Sectionsmaster.create(section)
.then(data => {
res.send(data);
})
.catch(err => {
res.status(500).send({
message:
err.message || "Some error occurred while creating the section."
});
});
};
exports.Updatesection = (req, res) => {
const id = req.params.id;
Sectionsmaster.update(req.body, {
where: { id: id }
})
.then(num => {
if (num == 1) {
res.send({
message: "section was updated successfully."
});
} else {
res.send({
message: `Cannot update section with id=${id}. Maybe section was not found or req.body is empty!`
});
}
})
.catch(err => {
res.status(500).send({
message: "Error updating section with id=" + id
});
});
};
//delete
exports.Deletesection = (req, res) => {
const id = req.params.id;
Sectionsmaster.destroy({
where: { id: id }
})
.then(num => {
if (num == 1) {
res.send({
message: "section was deleted successfully!"
});
} else {
res.send({
message: `Cannot delete section with id=${id}. Maybe section was not found!`
});
}
})
.catch(err => {
res.status(500).send({
message: "Could not delete section with id=" + id
});
});
};
//Subsectionsmaster
// Retrieve all Subsectionsmaster from the database.
exports.SubsectionList = (req, res) => {
Subsectionsmaster.findAll()
.then(data => {
res.send({'status':200,'message':"success",'data':data});
logMsg.info("Success :"(data));
})
.catch(err => {
res.status(500).send({'status':404,
message: err.message || "Some error occurred while retrieving subsections." ,'data': "No data" });
});
};
exports.Insertsubsection = (req, res) => {
// Create a statement
const subsection = {
section: req.body.section,
subsection: req.body.subsection,
itemtext: req.body.itemtext,
is_active: req.body.is_active,
createdby: req.body.createdby,
updatedby: req.body.updatedby,
};
// Save Tutorial in the database
Subsectionsmaster.create(subsection)
.then(data => {
res.send(data);
})
.catch(err => {
res.status(500).send({
message:
err.message || "Some error occurred while creating the subsection."
});
});
};
exports.Updatesubsection = (req, res) => {
const id = req.params.id;
Subsectionsmaster.update(req.body, {
where: { id: id }
})
.then(num => {
if (num == 1) {
res.send({
message: "subsection was updated successfully."
});
} else {
res.send({
message: `Cannot update subsection with id=${id}. Maybe subsection was not found or req.body is empty!`
});
}
})
.catch(err => {
res.status(500).send({
message: "Error updating subsection with id=" + id
});
});
};
//delete
exports.Deletesubsection = (req, res) => {
const id = req.params.id;
Subsectionsmaster.destroy({
where: { id: id }
})
.then(num => {
if (num == 1) {
res.send({
message: "subsection was deleted successfully!"
});
} else {
res.send({
message: `Cannot delete subsection with id=${id}. Maybe subsection was not found!`
});
}
})
.catch(err => {
res.status(500).send({
message: "Could not delete subsection with id=" + id
});
});
};
//itemsmaster
// Retrieve all itemsmaster from the database.
exports.ItemList = (req, res) => {
Itemsmaster.findAll()
.then(data => {
res.send({'status':200,'message':"success",'data':data});
logMsg.info("Success :"(data));
})
.catch(err => {
res.status(500).send({'status':404,
message: err.message || "Some error occurred while retrieving items." ,'data': "No data" });
});
};
exports.Insertitem = (req, res) => {
// Create a item
const item = {
statement: req.body.statement,
section: req.body.section,
subsection: req.body.subsection,
itemtext: req.body.itemtext,
is_active: req.body.is_active,
pvt_ltd: req.body.pvt_ltd,
LLP: req.body.LLP,
others: req.body.others,
formula: req.body.formula,
is_calculated: req.body.is_calculated,
createdby: req.body.createdby,
updatedby: req.body.updatedby,
};
// Save Tutorial in the database
Itemsmaster.create(item)
.then(data => {
res.send(data);
})
.catch(err => {
res.status(500).send({
message:
err.message || "Some error occurred while creating the item."
});
});
};
exports.Updateitem = (req, res) => {
const id = req.params.id;
Itemsmaster.update(req.body, {
where: { id: id }
})
.then(num => {
if (num == 1) {
res.send({
message: "item was updated successfully."
});
} else {
res.send({
message: `Cannot update item with id=${id}. Maybe item was not found or req.body is empty!`
});
}
})
.catch(err => {
res.status(500).send({
message: "Error updating item with id=" + id
});
});
};
//delete
exports.Deleteitem = (req, res) => {
const id = req.params.id;
Itemsmaster.destroy({
where: { id: id }
})
.then(num => {
if (num == 1) {
res.send({
message: "item was deleted successfully!"
});
} else {
res.send({
message: `Cannot delete item with id=${id}. Maybe statement was not found!`
});
}
})
.catch(err => {
res.status(500).send({
message: "Could not delete item with id=" + id
});
});
};
exports.test = (req, res) => {
sequelize.query("select * from statementsmaster")
.then(data => {
res.send({'status':200,'message':"success",'data':data});
logMsg.info("Success :"(data));
})
.catch(err => {
res.status(500).send({
message:
err.message || "Some error occurred while retrieving tutorials."
});
});
};

View File

@ -19,7 +19,13 @@ module.exports = (sequelize, DataTypes) => {
statement: { type: DataTypes.INTEGER },
section: { type: DataTypes.INTEGER },
subsection: { type: DataTypes.INTEGER },
itemtext: { type: DataTypes.STRING },
itemtext: { type: DataTypes.STRING },
is_active: { type: DataTypes.INTEGER },
pvt_ltd: { type: DataTypes.INTEGER },
LLP: { type: DataTypes.INTEGER },
others: { type: DataTypes.INTEGER },
formula: { type: DataTypes.INTEGER },
is_calculated: { type: DataTypes.INTEGER },
createdby: { type: DataTypes.INTEGER },
updatedby: { type: DataTypes.INTEGER },

View File

@ -20,7 +20,8 @@ module.exports = (sequelize, DataTypes) => {
Sectionsmaster.init(
{
statement: { type: DataTypes.INTEGER },
section: { type: DataTypes.STRING },
section: { type: DataTypes.STRING },
is_active: { type: DataTypes.INTEGER },
createdby: { type: DataTypes.INTEGER },
updatedby: { type: DataTypes.INTEGER },

View File

@ -17,7 +17,8 @@ module.exports = (sequelize, DataTypes) => {
}
Statementsmaster.init(
{
statement: { type: DataTypes.STRING },
statement: { type: DataTypes.STRING },
is_active: { type: DataTypes.INTEGER },
createdby: { type: DataTypes.INTEGER },
updatedby: { type: DataTypes.INTEGER },

View File

@ -21,7 +21,8 @@ module.exports = (sequelize, DataTypes) => {
{
section: { type: DataTypes.INTEGER },
subsection: { type: DataTypes.STRING },
itemtext: { type: DataTypes.STRING },
itemtext: { type: DataTypes.STRING },
is_active: { type: DataTypes.INTEGER },
createdby: { type: DataTypes.INTEGER },
updatedby: { type: DataTypes.INTEGER },

View File

@ -1,6 +1,7 @@
module.exports = app => {
const request = require("request");
const financials = require("../controllers/financial.controller.js");
const master = require("../controllers/master.controller.js");
var router = require("express").Router();
@ -10,8 +11,24 @@ module.exports = app => {
router.get("/StatmentList", financials.StatmentList);
// get statment master data
router.get("/MenuList/:losid", financials.MenuList);
//master.controller api's
// get statment master data
router.get("/StatmentsList", master.StatmentList);
router.post("/Insertstatement", master.Insertstatement);
router.put("/Updatestatement/:id", master.Updatestatement);
router.delete("/Deletestatement/:id", master.Deletestatement);
router.get("/SectionList", master.SectionList);
router.get("/Insertsection", master.Insertsection);
router.get("/SubsectionList", master.SubsectionList);
router.get("/ItemList", master.ItemList);
//sample
//router.put("/:id", tutorials.update);
//router.delete("/:id", tutorials.delete);