From 65294af68de62caced35ae22212ab757ef565bfd Mon Sep 17 00:00:00 2001 From: surya Date: Sat, 14 Aug 2021 10:47:12 +0530 Subject: [PATCH] Surya:statement master crud apis & models changes --- app/controllers/master.controller.js | 448 +++++++++++++++++++++++++++ app/models/Itemsmaster.js | 8 +- app/models/Sectionsmaster.js | 3 +- app/models/Statementsmaster.js | 3 +- app/models/Subsectionsmaster.js | 3 +- app/routes/routes.js | 19 +- 6 files changed, 479 insertions(+), 5 deletions(-) create mode 100644 app/controllers/master.controller.js diff --git a/app/controllers/master.controller.js b/app/controllers/master.controller.js new file mode 100644 index 0000000..a423267 --- /dev/null +++ b/app/controllers/master.controller.js @@ -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." + }); + }); +}; + + + diff --git a/app/models/Itemsmaster.js b/app/models/Itemsmaster.js index de96e32..7be3e4d 100644 --- a/app/models/Itemsmaster.js +++ b/app/models/Itemsmaster.js @@ -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 }, diff --git a/app/models/Sectionsmaster.js b/app/models/Sectionsmaster.js index 50a1014..4c2cea9 100644 --- a/app/models/Sectionsmaster.js +++ b/app/models/Sectionsmaster.js @@ -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 }, diff --git a/app/models/Statementsmaster.js b/app/models/Statementsmaster.js index 3402f12..e3e87cb 100644 --- a/app/models/Statementsmaster.js +++ b/app/models/Statementsmaster.js @@ -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 }, diff --git a/app/models/Subsectionsmaster.js b/app/models/Subsectionsmaster.js index 9486307..751bc50 100644 --- a/app/models/Subsectionsmaster.js +++ b/app/models/Subsectionsmaster.js @@ -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 }, diff --git a/app/routes/routes.js b/app/routes/routes.js index 40ebcf9..6736870 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -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);