From 896222af0c75ec2637de58e5627881d3e6a073c7 Mon Sep 17 00:00:00 2001 From: sriramv Date: Fri, 13 Aug 2021 13:02:20 +0530 Subject: [PATCH] gwm --- app/controllers/financial.controller.js | 46 ++++++++++++++++++++++++- app/models/Entities.js | 6 ++-- app/models/Sectionsmaster.js | 9 +++-- app/models/Statementsmaster.js | 9 ++--- app/models/Subsectionsmaster.js | 9 +++-- app/routes/routes.js | 14 ++++++-- server.js | 9 +++-- 7 files changed, 83 insertions(+), 19 deletions(-) diff --git a/app/controllers/financial.controller.js b/app/controllers/financial.controller.js index 855206d..b3794fb 100644 --- a/app/controllers/financial.controller.js +++ b/app/controllers/financial.controller.js @@ -1,10 +1,26 @@ //const db = require("../models"); //const Entities = db.tutorials; //const Op = db.Sequelize.Op; -const { sequelize, Entities , Financials} = require('../models') + +const { sequelize, Entities , Financials , Statementsmaster ,Sectionsmaster , Subsectionsmaster } = require('../models') const { logMsg } = require('../services/logger.js'); +// menu list api +exports.MenuList = async (req, res) => { + + try { + const losid = req.params.losid + //const MasterData = await Statementsmaster.findAll({include : 'sectionsmasterData'}); + let EntitiesData = await Entities.findAll({where : { losid } }); + + return res.send({'status':200,'message':"success",'data':EntitiesData}); + } catch (err) { + console.log(err) + return res.status(500).json({'status':404,'message':"failed",'data':"No data"}) + } + +}; // Retrieve all Entities from the database. exports.findAllEntities = (req, res) => { @@ -22,5 +38,33 @@ exports.findAllEntities = (req, res) => { }); }; +// Retrieve all Entities from the database. +exports.StatmentList = (req, res) => { + + Statementsmaster.findAll({include: 'sectionsmasterData' }) + .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.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/Entities.js b/app/models/Entities.js index f11d645..9b0030f 100644 --- a/app/models/Entities.js +++ b/app/models/Entities.js @@ -8,9 +8,9 @@ module.exports = (sequelize, DataTypes) => { * The `models/index` file will call this method automatically. */ // define association here - //static associate({ Model_name }) { - //this.hasMany(Model_name, { foreignKey: 'child_table_prim_key', as: 'child_tbl_name' }) - //} + static associate({ Financials }) { + this.hasMany(Financials, { foreignKey: 'entity_id', as: 'financials' }) + } } diff --git a/app/models/Sectionsmaster.js b/app/models/Sectionsmaster.js index 5d1549d..50a1014 100644 --- a/app/models/Sectionsmaster.js +++ b/app/models/Sectionsmaster.js @@ -8,9 +8,12 @@ module.exports = (sequelize, DataTypes) => { * The `models/index` file will call this method automatically. */ // define association here - //static associate({ Model_name }) { - //this.hasMany(Model_name, { foreignKey: 'child_table_prim_key', as: 'child_tbl_name' }) - //} + static associate({ Statementsmaster }) { + this.belongsTo(Statementsmaster, { foreignKey: 'id', as: 'statementsmasterData' }) + } + static associate({ Subsectionsmaster }) { + this.hasMany(Subsectionsmaster, { foreignKey: 'section', as: 'subsectionsmasterData' }) + } } diff --git a/app/models/Statementsmaster.js b/app/models/Statementsmaster.js index 5b1ca2f..3402f12 100644 --- a/app/models/Statementsmaster.js +++ b/app/models/Statementsmaster.js @@ -8,10 +8,11 @@ module.exports = (sequelize, DataTypes) => { * The `models/index` file will call this method automatically. */ // define association here - //static associate({ Model_name }) { - //this.hasMany(Model_name, { foreignKey: 'child_table_prim_key', as: 'child_tbl_name' }) - //} - + static associate({ Sectionsmaster }) { + this.hasMany(Sectionsmaster, { foreignKey: 'statement', as: 'sectionsmasterData' }) + } + +//Sectionsmaster.hasMany(Subsectionsmaster, { foreignKey: 'section', as: 'subsectionsmaster' }) } Statementsmaster.init( diff --git a/app/models/Subsectionsmaster.js b/app/models/Subsectionsmaster.js index bee2600..9486307 100644 --- a/app/models/Subsectionsmaster.js +++ b/app/models/Subsectionsmaster.js @@ -8,9 +8,12 @@ module.exports = (sequelize, DataTypes) => { * The `models/index` file will call this method automatically. */ // define association here - //static associate({ Model_name }) { - //this.hasMany(Model_name, { foreignKey: 'child_table_prim_key', as: 'child_tbl_name' }) - //} + static associate({ Sectionsmaster }) { + this.belongsTo(Sectionsmaster, { foreignKey: 'id', as: 'sectionsmasterData' }) + } + // static associate({ Model_name }) { + // this.hasMany(Model_name, { foreignKey: 'child_table_prim_key', as: 'child_tbl_name' }) + // } } diff --git a/app/routes/routes.js b/app/routes/routes.js index a520861..40ebcf9 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -6,10 +6,20 @@ module.exports = app => { // Retrieve all Tutorials router.get("/EntitiesList", financials.findAllEntities); + // get statment master data + router.get("/StatmentList", financials.StatmentList); + // get statment master data + router.get("/MenuList/:losid", financials.MenuList); - - + + + + + + // query execution test + router.get("/test", financials.test); + // third party api call example router.get('/third_party_api', (req, res) => { const options = { diff --git a/server.js b/server.js index 68ba194..a0e4bac 100644 --- a/server.js +++ b/server.js @@ -1,3 +1,4 @@ +require('dotenv').config(); const express = require('express') const app = express() app.use(express.json()) @@ -5,9 +6,11 @@ app.use(express.json()) app.get("/", (req, res) => { res.json({ message: "Welcome to the application." }); }); + require("./app/routes/routes.js")(app); -app.listen({ port: 3000 }, async () => { - console.log('Server up on http://localhost:3000') + +const PORT_NUMBER = process.env.SERVER_PORT +app.listen({ port: PORT_NUMBER }, async () => { + console.log('Server up on http://localhost:8000') //await sequelize.authenticate() - //console.log('Database Connected!') }) \ No newline at end of file