Surya: history api
This commit is contained in:
parent
d99d661105
commit
74a8e7a2f1
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const {sequelize , Statementsmaster ,Sectionsmaster , Subsectionsmaster,Itemsmaster ,Fin_remarks} = require('../models')
|
const {sequelize , Statementsmaster ,Sectionsmaster , Subsectionsmaster,Itemsmaster ,Fin_remarks,Fin_masters_history} = require('../models')
|
||||||
const { logMsg } = require('../services/logger.js');
|
const { logMsg } = require('../services/logger.js');
|
||||||
|
|
||||||
|
|
||||||
@ -347,7 +347,7 @@ exports.createRemarks = (req, res) => {
|
|||||||
{
|
{
|
||||||
req_array_data.forEach((value, key)=>{
|
req_array_data.forEach((value, key)=>{
|
||||||
if (value.hasOwnProperty("id"))
|
if (value.hasOwnProperty("id"))
|
||||||
{ console.log(value.is_active)
|
{
|
||||||
Fin_remarks.update({ is_active : 0 },{ where: { id: value.id }});
|
Fin_remarks.update({ is_active : 0 },{ where: { id: value.id }});
|
||||||
logMsg.info("updated is_active = 0 for primary key for Remarks: "+value.id);
|
logMsg.info("updated is_active = 0 for primary key for Remarks: "+value.id);
|
||||||
Fin_remarks.create({ "entity_id":value.entity_id,"itemid":value.itemid,"remarks":value.remarks,"is_active":value.is_active,"createdby":value.createdby })
|
Fin_remarks.create({ "entity_id":value.entity_id,"itemid":value.itemid,"remarks":value.remarks,"is_active":value.is_active,"createdby":value.createdby })
|
||||||
@ -356,7 +356,7 @@ exports.createRemarks = (req, res) => {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
console.log(value.is_active)
|
|
||||||
Fin_remarks.create({ "entity_id":value.entity_id,"itemid":value.itemid,"remarks":value.remarks,"is_active":value.is_active,"createdby":value.createdby })
|
Fin_remarks.create({ "entity_id":value.entity_id,"itemid":value.itemid,"remarks":value.remarks,"is_active":value.is_active,"createdby":value.createdby })
|
||||||
logMsg.info("Created new Remarks entity_id: "+value.entity_id+"itemid:"+value.itemid);
|
logMsg.info("Created new Remarks entity_id: "+value.entity_id+"itemid:"+value.itemid);
|
||||||
|
|
||||||
@ -373,6 +373,63 @@ exports.createRemarks = (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.Historyapi = (req, res) => {
|
||||||
|
const reqq = req.query
|
||||||
|
//console.log(reqq)
|
||||||
|
let table_name;
|
||||||
|
if(req.query.table == "statement")
|
||||||
|
{
|
||||||
|
table_name = "statementsmaster"
|
||||||
|
console.log(table_name)
|
||||||
|
}
|
||||||
|
if(req.query.table == "section")
|
||||||
|
{
|
||||||
|
table_name = "sectionsmaster"
|
||||||
|
}
|
||||||
|
if(req.query.table == "subsection")
|
||||||
|
{
|
||||||
|
table_name = "subsectionsmaster"
|
||||||
|
}
|
||||||
|
if(req.query.table == "item")
|
||||||
|
{
|
||||||
|
table_name = "itemsmaster"
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (reqq.hasOwnProperty("id"))
|
||||||
|
{ console.log(table_name)
|
||||||
|
const id = req.query.id
|
||||||
|
Fin_masters_history.findAll({where: { data_id: id , table_name: table_name }}).then(data => {
|
||||||
|
if(data.length)
|
||||||
|
{
|
||||||
|
res.send({'status':200,'message':"success",'data':data});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
res.send({'status':404,'message':"Failed",'data':'nodata'});
|
||||||
|
}
|
||||||
|
|
||||||
|
// logMsg.info("Success :"(data));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
console.log(table_name)
|
||||||
|
Fin_masters_history.findAll({where: { table_name: table_name }}).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 inserting statements." ,'data': "No data"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -460,6 +517,5 @@ exports.createRemarks = (req, res) => {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
39
app/models/Fin_masters_history.js
Normal file
39
app/models/Fin_masters_history.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
'use strict'
|
||||||
|
const { Model } = require('sequelize')
|
||||||
|
module.exports = (sequelize, DataTypes) => {
|
||||||
|
class Fin_masters_history extends Model {
|
||||||
|
/**
|
||||||
|
* Helper method for defining associations.
|
||||||
|
* This method is not a part of Sequelize lifecycle.
|
||||||
|
* 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' })
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
Fin_masters_history.init(
|
||||||
|
{
|
||||||
|
|
||||||
|
table_name: { type: DataTypes.STRING },
|
||||||
|
column_name: { type: DataTypes.STRING },
|
||||||
|
data_id: { type: DataTypes.INTEGER },
|
||||||
|
old_data: { type: DataTypes.STRING },
|
||||||
|
new_data: { type: DataTypes.STRING },
|
||||||
|
user_id: { type: DataTypes.INTEGER },
|
||||||
|
user_name: { type: DataTypes.STRING },
|
||||||
|
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sequelize,
|
||||||
|
tableName: 'fin_masters_history',
|
||||||
|
modelName: 'Fin_masters_history',
|
||||||
|
createdAt: 'created_at',
|
||||||
|
updatedAt: false,
|
||||||
|
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return Fin_masters_history
|
||||||
|
}
|
||||||
@ -695,7 +695,32 @@ module.exports = app => {
|
|||||||
* description: failure in creating item
|
* description: failure in creating item
|
||||||
*/
|
*/
|
||||||
router.post("/createRemarks", master.createRemarks);
|
router.post("/createRemarks", master.createRemarks);
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/Historyapi:
|
||||||
|
* get:
|
||||||
|
* summary: Historyapi
|
||||||
|
* description: Historyapi
|
||||||
|
* parameters:
|
||||||
|
* - in: query
|
||||||
|
* name: table
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* required: true
|
||||||
|
* description: table name
|
||||||
|
* example: item
|
||||||
|
* - in: query
|
||||||
|
* name: id
|
||||||
|
* schema:
|
||||||
|
* type: integer
|
||||||
|
* required: true
|
||||||
|
* description: id
|
||||||
|
* example: 109
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: success
|
||||||
|
*/
|
||||||
|
router.get("/Historyapi", master.Historyapi);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user