This commit is contained in:
sriramv 2021-08-13 13:02:20 +05:30
parent 0da977d05d
commit 896222af0c
7 changed files with 83 additions and 19 deletions

View File

@ -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."
});
});
};

View File

@ -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' })
}
}

View File

@ -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' })
}
}

View File

@ -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(

View File

@ -8,6 +8,9 @@ module.exports = (sequelize, DataTypes) => {
* The `models/index` file will call this method automatically.
*/
// define association here
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' })
// }

View File

@ -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 = {

View File

@ -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!')
})