Initial:GWM
This commit is contained in:
parent
61c08e43d3
commit
4e7f57113b
53
.gitignore
vendored
53
.gitignore
vendored
@ -1,50 +1,3 @@
|
||||
# These are some examples of commonly ignored file patterns.
|
||||
# You should customize this list as applicable to your project.
|
||||
# Learn more about .gitignore:
|
||||
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore
|
||||
|
||||
# Node artifact files
|
||||
node_modules/
|
||||
dist/
|
||||
|
||||
# Compiled Java class files
|
||||
*.class
|
||||
|
||||
# Compiled Python bytecode
|
||||
*.py[cod]
|
||||
|
||||
# Log files
|
||||
*.log
|
||||
|
||||
# Package files
|
||||
*.jar
|
||||
|
||||
# Maven
|
||||
target/
|
||||
dist/
|
||||
|
||||
# JetBrains IDE
|
||||
.idea/
|
||||
|
||||
# Unit test reports
|
||||
TEST*.xml
|
||||
|
||||
# Generated by MacOS
|
||||
.DS_Store
|
||||
|
||||
# Generated by Windows
|
||||
Thumbs.db
|
||||
|
||||
# Applications
|
||||
*.app
|
||||
*.exe
|
||||
*.war
|
||||
|
||||
# Large media files
|
||||
*.mp4
|
||||
*.tiff
|
||||
*.avi
|
||||
*.flv
|
||||
*.mov
|
||||
*.wmv
|
||||
|
||||
/node_modules
|
||||
/storage
|
||||
.env
|
||||
16
app/config/db.config.js
Normal file
16
app/config/db.config.js
Normal file
@ -0,0 +1,16 @@
|
||||
require('dotenv').config();
|
||||
|
||||
const { logMsg } = require('../services/logger');
|
||||
module.exports = {
|
||||
|
||||
"development": {
|
||||
"username": process.env.USER_NAME,
|
||||
"password": process.env.PASSWORD,
|
||||
"database": process.env.DATABASE,
|
||||
"port": process.env.PORT,
|
||||
"host": process.env.HOST,
|
||||
"dialect": "mssql",
|
||||
"logging": (message) =>(logMsg.info(message))
|
||||
|
||||
}
|
||||
};
|
||||
148
app/controllers/other.income.controller.js
Normal file
148
app/controllers/other.income.controller.js
Normal file
@ -0,0 +1,148 @@
|
||||
|
||||
const { sequelize,MasterP , MasterC , OtherIncomeP , OtherIncomeC} = require('../models')
|
||||
const { logMsg } = require('../services/logger.js');
|
||||
|
||||
exports.otherIncomeList = async (req, res) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
OtherIncomeData = await OtherIncomeP.findAll({ where:{ losid:req.query.losid, is_active:1},include:[{model:OtherIncomeC}]}).catch(err=>{});
|
||||
|
||||
if(OtherIncomeData.length != 0)
|
||||
{
|
||||
|
||||
res.send({'status':200 , message:"Success." ,'data': OtherIncomeData});
|
||||
console.log("data already exist");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
MasterData = await MasterP.findAll({ where:{ is_active:1},include:[{model:MasterC}]}).catch(err=>{});
|
||||
var MasterDataInsert = new Promise(async(resolve, reject) => {
|
||||
|
||||
MasterData.forEach(async(master_value,index,array) => {
|
||||
OtherIncomeP.create({losid:req.query.losid,table_name:master_value.table_name,particulars:master_value.particulars})
|
||||
.then(async(parent_data)=>{
|
||||
master_value.MasterCs.forEach(async(child_data) => {
|
||||
await OtherIncomeC.create({other_income_id:parent_data.dataValues.id,column_name:child_data.column_name,value:child_data.value})
|
||||
.catch(err=>{logMsg.info(err);});
|
||||
});
|
||||
if (index === array.length -1) { resolve(); }
|
||||
}).catch(err=>{logMsg.info(err);});
|
||||
});
|
||||
|
||||
});
|
||||
MasterDataInsert.then(async()=>{
|
||||
OtherIncomeData = await OtherIncomeP.findAll({ where:{ losid:req.query.losid, is_active:1},include:[{model:OtherIncomeC}]}).catch(err=>{});
|
||||
res.send({'status':200 , message:"Success." ,'data': OtherIncomeData});
|
||||
});
|
||||
|
||||
console.log("create master data for losid");
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch(err) {
|
||||
res.status(500).send({'status':404,
|
||||
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
||||
}); } //end of try catch
|
||||
|
||||
};
|
||||
|
||||
|
||||
exports.updateOtherIncome = async (req, res) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
IncomeData = req.body;
|
||||
|
||||
await OtherIncomeP.update({updatedby:IncomeData.updatedby},{where:{id:IncomeData.id}}).catch(err=>{logMsg.info(err);});
|
||||
|
||||
IncomeData.childData.forEach(async(child_data) => {
|
||||
await OtherIncomeC.update({value:child_data.value},{where:{id:child_data.id,other_income_id:child_data.other_income_id,column_name:child_data.column_name}})
|
||||
.catch(err=>{logMsg.info(err);});
|
||||
});
|
||||
setTimeout(() => {
|
||||
res.send({'status':200 , message:"Success." ,'data': "no data"});
|
||||
}, 300);
|
||||
|
||||
|
||||
|
||||
|
||||
} catch(err) {
|
||||
res.status(500).send({'status':404,
|
||||
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
||||
}); } //end of try catch
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
18
app/controllers/test.controller.js
Normal file
18
app/controllers/test.controller.js
Normal file
@ -0,0 +1,18 @@
|
||||
const { sequelize,Test} = require('../models')
|
||||
const { logMsg } = require('../services/logger.js');
|
||||
|
||||
exports.Welcome = (req, res) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
const Msg = "Welcome....!";
|
||||
console.log(Msg);
|
||||
logMsg.info("Api Call Success");
|
||||
res.send({'status':200 , message:"Success." ,'data': Msg});
|
||||
|
||||
} catch(err) {
|
||||
res.status(500).send({'status':404,
|
||||
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
|
||||
}); } //end of try catch
|
||||
|
||||
};
|
||||
22
app/models/MasterC.js
Normal file
22
app/models/MasterC.js
Normal file
@ -0,0 +1,22 @@
|
||||
'use strict'
|
||||
const { Model } = require('sequelize')
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
class MasterC extends Model {
|
||||
|
||||
|
||||
}
|
||||
MasterC.init(
|
||||
{
|
||||
master_id: { type: DataTypes.INTEGER },
|
||||
column_name: { type: DataTypes.STRING },
|
||||
value: { type: DataTypes.INTEGER },
|
||||
is_active: { type: DataTypes.INTEGER }
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
tableName: 'master_c',
|
||||
modelName: 'MasterC',
|
||||
}
|
||||
)
|
||||
return MasterC
|
||||
}
|
||||
27
app/models/MasterP.js
Normal file
27
app/models/MasterP.js
Normal file
@ -0,0 +1,27 @@
|
||||
'use strict'
|
||||
const { Model } = require('sequelize')
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
class MasterP extends Model {
|
||||
|
||||
|
||||
}
|
||||
MasterP.init(
|
||||
{
|
||||
table_name: { type: DataTypes.STRING },
|
||||
particulars: { type: DataTypes.STRING },
|
||||
is_active: { type: DataTypes.INTEGER }
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
tableName: 'master_p',
|
||||
modelName: 'MasterP',
|
||||
}
|
||||
)
|
||||
MasterP.associate = models => {
|
||||
MasterP.hasMany(models.MasterC, {
|
||||
foreignKey: 'master_id',
|
||||
sourceKey : 'id'
|
||||
});
|
||||
}
|
||||
return MasterP
|
||||
}
|
||||
26
app/models/OtherIncomeC.js
Normal file
26
app/models/OtherIncomeC.js
Normal file
@ -0,0 +1,26 @@
|
||||
'use strict'
|
||||
const { Model } = require('sequelize')
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
class OtherIncomeC extends Model {
|
||||
|
||||
|
||||
}
|
||||
OtherIncomeC.init(
|
||||
{
|
||||
|
||||
other_income_id: { type: DataTypes.INTEGER },
|
||||
column_name: { type: DataTypes.STRING },
|
||||
value: { type: DataTypes.INTEGER },
|
||||
is_active: { type: DataTypes.INTEGER },
|
||||
createdby: { type: DataTypes.INTEGER },
|
||||
updatedby: { type: DataTypes.INTEGER }
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
tableName: 'other_income_c',
|
||||
modelName: 'OtherIncomeC',
|
||||
}
|
||||
)
|
||||
|
||||
return OtherIncomeC
|
||||
}
|
||||
30
app/models/OtherIncomeP.js
Normal file
30
app/models/OtherIncomeP.js
Normal file
@ -0,0 +1,30 @@
|
||||
'use strict'
|
||||
const { Model } = require('sequelize')
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
class OtherIncomeP extends Model {
|
||||
|
||||
|
||||
}
|
||||
OtherIncomeP.init(
|
||||
{
|
||||
losid: { type: DataTypes.STRING },
|
||||
table_name: { type: DataTypes.STRING },
|
||||
particulars: { type: DataTypes.STRING },
|
||||
is_active: { type: DataTypes.INTEGER },
|
||||
createdby: { type: DataTypes.INTEGER },
|
||||
updatedby: { type: DataTypes.INTEGER }
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
tableName: 'other_income_p',
|
||||
modelName: 'OtherIncomeP',
|
||||
}
|
||||
)
|
||||
OtherIncomeP.associate = models => {
|
||||
OtherIncomeP.hasMany(models.OtherIncomeC, {
|
||||
foreignKey: 'other_income_id',
|
||||
sourceKey : 'id'
|
||||
});
|
||||
}
|
||||
return OtherIncomeP
|
||||
}
|
||||
27
app/models/RentalIncome
Normal file
27
app/models/RentalIncome
Normal file
@ -0,0 +1,27 @@
|
||||
'use strict'
|
||||
const { Model } = require('sequelize')
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
class RentalIncome extends Model {
|
||||
|
||||
|
||||
}
|
||||
RentalIncome.init(
|
||||
{
|
||||
losid: { type: DataTypes.STRING },
|
||||
particulars: { type: DataTypes.STRING },
|
||||
amount: { type: DataTypes.INTEGER },
|
||||
considered: { type: DataTypes.STRING },
|
||||
annual_income_considered: { type: DataTypes.INTEGER },
|
||||
is_active: { type: DataTypes.INTEGER },
|
||||
createdby: { type: DataTypes.INTEGER },
|
||||
updatedby: { type: DataTypes.INTEGER },
|
||||
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
tableName: 'rental_income',
|
||||
modelName: 'RentalIncome',
|
||||
}
|
||||
)
|
||||
return RentalIncome
|
||||
}
|
||||
22
app/models/Test.js
Normal file
22
app/models/Test.js
Normal file
@ -0,0 +1,22 @@
|
||||
'use strict'
|
||||
const { Model } = require('sequelize')
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
class Test extends Model {
|
||||
|
||||
|
||||
}
|
||||
Test.init(
|
||||
{
|
||||
losid: { type: DataTypes.STRING },
|
||||
createdby: { type: DataTypes.INTEGER },
|
||||
updatedby: { type: DataTypes.INTEGER },
|
||||
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
tableName: 'test',
|
||||
modelName: 'Test',
|
||||
}
|
||||
)
|
||||
return Test
|
||||
}
|
||||
39
app/models/index.js
Normal file
39
app/models/index.js
Normal file
@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const Sequelize = require('sequelize');
|
||||
const basename = path.basename(__filename);
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
const config = require(__dirname + '/../config/db.config.js')[env];
|
||||
//console.log(env);
|
||||
//console.log(config);
|
||||
const db = {};
|
||||
|
||||
let sequelize;
|
||||
if (config.use_env_variable) {
|
||||
sequelize = new Sequelize(process.env[config.use_env_variable], config);
|
||||
} else {
|
||||
sequelize = new Sequelize(config.database, config.username, config.password, config);
|
||||
}
|
||||
|
||||
fs
|
||||
.readdirSync(__dirname)
|
||||
.filter(file => {
|
||||
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
|
||||
})
|
||||
.forEach(file => {
|
||||
const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
|
||||
db[model.name] = model;
|
||||
});
|
||||
|
||||
Object.keys(db).forEach(modelName => {
|
||||
if (db[modelName].associate) {
|
||||
db[modelName].associate(db);
|
||||
}
|
||||
});
|
||||
|
||||
db.sequelize = sequelize;
|
||||
db.Sequelize = Sequelize;
|
||||
|
||||
module.exports = db;
|
||||
89
app/routes/routes.js
Normal file
89
app/routes/routes.js
Normal file
@ -0,0 +1,89 @@
|
||||
module.exports = app => {
|
||||
const request = require("request");
|
||||
const cors=require('cors');
|
||||
const IncomeController = require("../controllers/other.income.controller.js");
|
||||
const { logMsg } = require('../services/logger.js');
|
||||
var router = require("express").Router();
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/otherIncomeList:
|
||||
* get:
|
||||
* summary: other Income data List
|
||||
* description:
|
||||
* parameters:
|
||||
* - in: query
|
||||
* name: losid
|
||||
* schema:
|
||||
* type: string
|
||||
* required: true
|
||||
* description: Loan ID
|
||||
* example: MW112233
|
||||
* responses:
|
||||
* 200:
|
||||
* description: success
|
||||
*/
|
||||
router.get("/otherIncomeList", IncomeController.otherIncomeList);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* definitions:
|
||||
* updateOtherIncome:
|
||||
* type: object
|
||||
* properties:
|
||||
* id:
|
||||
* type: integer
|
||||
* description:
|
||||
* example: 34
|
||||
* losid:
|
||||
* type: string
|
||||
* description:
|
||||
* example: MW112233
|
||||
* table_name:
|
||||
* type: string
|
||||
* description:
|
||||
* example: rental_income
|
||||
* particulars:
|
||||
* type: string
|
||||
* description:
|
||||
* example: Latest Month's Rental Income
|
||||
* childData:
|
||||
* type: array
|
||||
* description:
|
||||
* example:
|
||||
* updatedby:
|
||||
* type: integer
|
||||
* description:
|
||||
* example: 003
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/updateOtherIncome:
|
||||
* post:
|
||||
* summary: create Other Income data
|
||||
* description:
|
||||
* requestBody:
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/definitions/updateOtherIncome'
|
||||
* responses:
|
||||
* 200:
|
||||
* description: updated
|
||||
* 500:
|
||||
* description: failure in updating
|
||||
*/
|
||||
router.post("/updateOtherIncome", IncomeController.updateOtherIncome);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// routes started here
|
||||
app.use('/api', router);
|
||||
};
|
||||
|
||||
|
||||
27
app/services/logger.js
Normal file
27
app/services/logger.js
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Configurations of logger.
|
||||
*/
|
||||
var winston = require('winston');
|
||||
require('winston-daily-rotate-file');
|
||||
|
||||
var transport = new winston.transports.DailyRotateFile({
|
||||
filename: 'storage/log/msg.log',
|
||||
datePattern: 'YYYY-MM-DD',
|
||||
zippedArchive: true,
|
||||
maxSize: '20m',
|
||||
maxFiles: '14d'
|
||||
});
|
||||
|
||||
transport.on('rotate', function(oldFilename, newFilename) {
|
||||
// do something fun
|
||||
});
|
||||
|
||||
const logger = winston.createLogger({
|
||||
transports: [
|
||||
transport
|
||||
]
|
||||
});
|
||||
module.exports = {
|
||||
'logMsg': logger,
|
||||
};
|
||||
|
||||
3426
package-lock.json
generated
Normal file
3426
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
package.json
Normal file
30
package.json
Normal file
@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "smc_cet_otherincome_backend",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"start": "nodemon server.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.19.0",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^10.0.0",
|
||||
"express": "^4.17.1",
|
||||
"log4js": "^6.3.0",
|
||||
"mssql": "^7.2.0",
|
||||
"request": "^2.88.2",
|
||||
"sequelize": "^6.6.5",
|
||||
"swagger-jsdoc": "^6.1.0",
|
||||
"swagger-ui-express": "^4.1.6",
|
||||
"sync": "^0.2.5",
|
||||
"winston": "^3.3.3",
|
||||
"winston-daily-rotate-file": "^4.5.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.12"
|
||||
}
|
||||
}
|
||||
62
server.js
Normal file
62
server.js
Normal file
@ -0,0 +1,62 @@
|
||||
require('dotenv').config();
|
||||
const express = require('express')
|
||||
const app = express()
|
||||
//it is used to clear cache
|
||||
app.use(function(req, res, next) {
|
||||
res.set("Cache-Control", "no-cache, no-store, must-revalidate, max-age=0")
|
||||
res.set("Pragma", "no-cache")
|
||||
res.set("Expires", 0)
|
||||
next()
|
||||
})
|
||||
const {logMsg} = require('./app/services/logger.js');
|
||||
|
||||
const swaggerJsdoc = require('swagger-jsdoc');
|
||||
const swaggerUi = require('swagger-ui-express');
|
||||
|
||||
|
||||
|
||||
const options = {
|
||||
definition: {
|
||||
openapi: '3.0.0',
|
||||
info: {
|
||||
title: 'Smc_cet_OtherIncome',
|
||||
version: '1.0.0',
|
||||
},
|
||||
},
|
||||
apis: ['./app/routes/routes.js'], // files containing annotations as above
|
||||
};
|
||||
|
||||
const swaggerDocument = swaggerJsdoc(options);
|
||||
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
|
||||
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /:
|
||||
* get:
|
||||
* description: Welcome to swagger-jsdoc!
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Returns a mysterious string.
|
||||
*/
|
||||
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
res.json({ message: "Welcome to the application." });
|
||||
logMsg.info("Server Sent A Welcome to the application!");
|
||||
|
||||
});
|
||||
|
||||
|
||||
app.use(express.json())
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
|
||||
require("./app/routes/routes.js")(app);
|
||||
|
||||
const PORT_NUMBER = process.env.SERVER_PORT
|
||||
app.listen({ port: PORT_NUMBER }, async () => {
|
||||
console.log('Server up on http://localhost:'+PORT_NUMBER)
|
||||
|
||||
//await sequelize.authenticate()
|
||||
})
|
||||
Loading…
Reference in New Issue
Block a user