diff --git a/app/controllers/salespd.controller.js b/app/controllers/salespd.controller.js index 6430f28..63f4314 100644 --- a/app/controllers/salespd.controller.js +++ b/app/controllers/salespd.controller.js @@ -42,7 +42,7 @@ exports.PullSalesPdData = async (req, res) => if(values.pincode == 'Others') { pincode = values.pincode_others; }else { pincode = values.pincode; } if(values.person_met_contact_no == "") { delete values.person_met_contact_no; } - Object.assign(values, { ref_no: req.body.pdid , product :req.body.product , case_no :req.body.caseno , completed_date : new Date(req.body.completed_date) , pincode : pincode , sales_pd_type:req.body.sales_pd_type}); + Object.assign(values, { ref_no: req.body.pdid , product :req.body.product , case_no :req.body.caseno , completed_date : new Date(req.body.completed_date) , pincode : pincode , sales_pd_type:req.body.sales_pd_type,employee_id : req.body.employee_id}); await GeneralSection.create( values ) .then((successData)=>{logMsg.info("GeneralSection insert success ,PdId= "+successData.dataValues.pd_id);}) .catch((err)=>{ logMsg.info("GeneralSection insert failed ,PdId(ref_no)= "+req.body.pdid+ " ERR =" + err); }); @@ -96,7 +96,7 @@ exports.PullSalesPdData = async (req, res) => if (keys == 'section1') { if(values.pincode == 'Others') { pincode = values.pincode_others; }else { pincode = values.pincode; } if(values.person_met_contact_no == "") { delete values.person_met_contact_no; } - Object.assign(values, { ref_no: req.body.pdid , product :req.body.product , case_no :req.body.caseno ,completed_date : new Date(req.body.completed_date) , pincode : pincode}); + Object.assign(values, { ref_no: req.body.pdid , product :req.body.product , case_no :req.body.caseno ,completed_date : new Date(req.body.completed_date) , pincode : pincode, sales_pd_type:req.body.sales_pd_type,employee_id : req.body.employee_id}); await GeneralSection.create( values ) .then((successData)=>{logMsg.info("GeneralSection insert success ,PdId= "+successData.dataValues.pd_id);}) .catch((err)=>{ logMsg.info("GeneralSection insert failed ,PdId(ref_no)= "+req.body.pdid+ " ERR =" + err); }); @@ -134,7 +134,8 @@ exports.PullSalesPdData = async (req, res) => pre_year_sales = 0; pre_year_net_profit = 0; pre_year_net_pro_loss_per = 0; - for (let i = 0; i < 4; i++) + con = Object.keys(values).filter(key => !isNaN(parseInt(key))).length; + for (let i = 0; i < con; i++) { if(values[i]) { @@ -1141,4 +1142,164 @@ const storage = new Storage({ keyFilename : path.join(__dirname, "../../googleCl res.send({'status':404,message: err.message || "Some error occurred while retrieving data." ,'data': "No data" }); } //end of try catch -}; \ No newline at end of file +}; + +exports.test = async (req, res) => { + const storage = new Storage({ keyFilename : path.join(__dirname, "../../googleCloud.json") }); + bucketName = 'pd-giene-data'; + const bucket = storage.bucket(bucketName); + + try { + const [files] = await bucket.getFiles(); + + const fileNames = files.map((file) => file.name); + console.log('File names:', fileNames); + res.send({'data':fileNames}) + } catch (error) { + console.error('Error retrieving file names:', error); + } + } + + + +exports.readLogFileName = async (req , res) => +{ + try + { + folderName = req; + const logFilePath = 'storage/log'; + + const fileNames = fs.readdirSync(logFilePath); + // Remove the first element (0th index) + const [, ...data] = fileNames; + return data; + + } + 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.readLogFile = async (req , res) => +{ + try + { + folderName = req.body.folder; + fileName = req.body.file; + const logFilePath = 'storage/log/'+fileName; + + fs.readFile(logFilePath, 'utf8', (err, data) => { + if (err) { + console.error(err); + res.status(500).send({'status':404,'message': err.message || "Error reading log file." ,'data': "No data"}); + } + res.send({'status':200 , message:"Success." ,'data': data}); + }); + + } + 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.viewLandingPage = async (req , res) => +{ + try + { + moduleName = [ { "module":"SALES PD","folder":"smc_cet_salespd_backend"} ]; + img = [] + for(const [index,val] of moduleName.entries()) + { + fileName = await this.readLogFileName(val.folder); + for (let i = 0; i < fileName.length; i++) + { + filePath = 'storage/log/'+fileName[i]; + const logData = fs.readFileSync(filePath); + // Convert the file content to Base64 + const base64Data = logData.toString('base64'); + // Create Base64 URL from Base64 data + const base64Url = `data:application/octet-stream;base64,${encodeURIComponent(base64Data)}`; + img.push(base64Url) + } + moduleName[index] = await Object.assign(val,{'file':fileName , 'img':img}); + }; + res.render( 'module' , { 'data' : moduleName } ,function (err, html ) { + res.send(html) + }) + + } + 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.deleteLogFile = async (req , res) => +{ + try + { + folderName = req.body.folder; + fileName = req.body.file; + + // folderName = 'smc_cet_creditpd_backend'; + // fileName = 'msg.log.2023-07-10'; + const logFilePath = 'storage/log/'+fileName; + fs.unlink(logFilePath, (err) => { + if (err) { + console.error(`Error deleting file: ${err}`); + return; + } + + console.log('File deleted successfully.'); + res.send({'status':200 , message:"Success." ,'data': 'No data'}); + }); + + } + 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.callSineedgeApi = (req, res) => +{ + try + { + request('http://www.google.com', function (error, response, body) { + res = this.PullSalesPdData(body); + if(res.status == 200){ + res.send({'status':200 , message:"Success." ,'data': Msg}); + } + else{ + res.send({'status':404 , message:"Failed." ,'data': "No data"}); + } + }); + + } catch(err) { + res.status(500).send({'status':404, + message: err.message || "Some error occurred while inserting statements." ,'data': "No data" + }); } //end of try catch + +}; + + + + + + + + \ No newline at end of file diff --git a/app/controllers/test.controller.js b/app/controllers/test.controller.js index fe4afb0..518a868 100644 --- a/app/controllers/test.controller.js +++ b/app/controllers/test.controller.js @@ -70,3 +70,6 @@ exports.SalesPd = async (req, res) => } } + + + diff --git a/app/models/GeneralSection.js b/app/models/GeneralSection.js index 622f083..74044fe 100644 --- a/app/models/GeneralSection.js +++ b/app/models/GeneralSection.js @@ -16,6 +16,7 @@ module.exports = (sequelize, DataTypes) => { product: { type: DataTypes.STRING }, case_no: { type: DataTypes.STRING }, losid: { type: DataTypes.STRING }, + sales_pd_type : { type: DataTypes.INTEGER }, application_id: { type: DataTypes.STRING }, main_loan_applicant: { type: DataTypes.STRING }, company_name: { type: DataTypes.STRING }, @@ -38,7 +39,9 @@ module.exports = (sequelize, DataTypes) => { updatedby: { type: DataTypes.INTEGER }, completed_date : {type : DataTypes.DATE}, sales_pd_type : { type: DataTypes.INTEGER }, - landmark : { type: DataTypes.STRING } + landmark : { type: DataTypes.STRING }, + employee_id : { type: DataTypes.STRING } + }, { diff --git a/app/models/OfficerDetails.js b/app/models/OfficerDetails.js index f16c1f7..a9eab37 100644 --- a/app/models/OfficerDetails.js +++ b/app/models/OfficerDetails.js @@ -11,6 +11,7 @@ module.exports = (sequelize, DataTypes) => { designation: { type: DataTypes.STRING }, date: { type: DataTypes.STRING }, officer_id :{ type: DataTypes.INTEGER }, + employee_id :{ type: DataTypes.STRING }, email : { type: DataTypes.STRING }, mobile_no :{ type: DataTypes.INTEGER }, officer_full_name : { type: DataTypes.STRING }, diff --git a/app/routes/routes.js b/app/routes/routes.js index 2435d4d..f7caee5 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -19,7 +19,7 @@ module.exports = app => { * description: success */ router.get("/demo", Mycontroller.Welcome); - +router.get("/test", SalesPdController.test); // landing page api /** * @swagger @@ -408,7 +408,13 @@ router.get("/PropertyInformationList", SalesPdController.PropertyInformationList +router.get("/getfilename", SalesPdController.readLogFileName); +router.post("/readlogs", SalesPdController.readLogFile); + +router.get("/view", SalesPdController.viewLandingPage); + +router.post("/deletelog", SalesPdController.deleteLogFile); diff --git a/app/views/module.ejs b/app/views/module.ejs new file mode 100644 index 0000000..a1f9ca5 --- /dev/null +++ b/app/views/module.ejs @@ -0,0 +1,346 @@ + + + + + + + + + + + +
+ <% for (let i = 0; i < data.length; i++) { %> +
+
+
+

+ LOGS + +

+
+ <%= data[i].file.length %> +
+
+
+ <% for (let j = 0; j < data[i].file.length; j++) { %> +
+
    +
  • + <%= data[i].file[j] %> +
  • + + +
+
+ <% } %> +
+
+ Close +
+
+
+
+
+ <% } %> +
+ + + + + + + + + + \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 7d9e6bd..e1e9d4e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -724,7 +724,6 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, "requires": { "color-convert": "^2.0.1" } @@ -1102,7 +1101,6 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, "requires": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -1111,14 +1109,12 @@ "has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" }, "supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, "requires": { "has-flag": "^4.0.0" } @@ -1210,7 +1206,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, "requires": { "color-name": "~1.1.4" } @@ -1538,6 +1533,14 @@ "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" }, + "ejs": { + "version": "3.1.9", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.9.tgz", + "integrity": "sha512-rC+QVNMJWv+MtPgkt0y+0rVEIdbtxVADApW9JXrUVlzHetgcyczP/E7DJmWJ4fJCZF2cPcBk0laWO9ZHMG3DmQ==", + "requires": { + "jake": "^10.8.5" + } + }, "emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", @@ -1739,6 +1742,32 @@ "moment": "^2.29.1" } }, + "filelist": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz", + "integrity": "sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==", + "requires": { + "minimatch": "^5.0.1" + }, + "dependencies": { + "brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "requires": { + "balanced-match": "^1.0.0" + } + }, + "minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "requires": { + "brace-expansion": "^2.0.1" + } + } + } + }, "fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -1812,6 +1841,11 @@ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" }, + "fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" + }, "fs-constants": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", @@ -2342,6 +2376,24 @@ "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" }, + "jake": { + "version": "10.8.7", + "resolved": "https://registry.npmjs.org/jake/-/jake-10.8.7.tgz", + "integrity": "sha512-ZDi3aP+fG/LchyBzUM804VjddnwfSfsdeYkwt8NcbKRvo4rFkjhs456iLFn3k2ZUWvNe4i48WACDbza8fhq2+w==", + "requires": { + "async": "^3.2.3", + "chalk": "^4.0.2", + "filelist": "^1.0.4", + "minimatch": "^3.1.2" + }, + "dependencies": { + "async": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz", + "integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==" + } + } + }, "js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", @@ -3003,6 +3055,15 @@ "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" }, + "path": { + "version": "0.12.7", + "resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz", + "integrity": "sha512-aXXC6s+1w7otVF9UletFkFcDsJeO7lSZBPUQhtb5O0xJe8LtYhj/GxldoL09bBj9+ZmE2hNoHqQSFMN5fikh4Q==", + "requires": { + "process": "^0.11.1", + "util": "^0.10.3" + } + }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", @@ -3960,6 +4021,21 @@ "prepend-http": "^2.0.0" } }, + "util": { + "version": "0.10.4", + "resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz", + "integrity": "sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==", + "requires": { + "inherits": "2.0.3" + }, + "dependencies": { + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw==" + } + } + }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/package.json b/package.json index 85f99a9..801498d 100644 --- a/package.json +++ b/package.json @@ -9,21 +9,24 @@ "author": "", "license": "ISC", "dependencies": { + "@google-cloud/storage": "^6.9.3", "body-parser": "^1.19.0", "cors": "^2.8.5", "dotenv": "^10.0.0", + "ejs": "^3.1.9", "express": "^4.17.1", + "fs": "0.0.1-security", "lodash": "^4.17.21", "log4js": "^6.3.0", "mssql": "^7.2.0", "multer": "^1.4.4", + "path": "^0.12.7", "request": "^2.88.2", "sequelize": "^6.6.5", "swagger-jsdoc": "^6.1.0", "swagger-ui-express": "^4.1.6", "winston": "^3.3.3", - "winston-daily-rotate-file": "^4.5.5", - "@google-cloud/storage": "^6.9.3" + "winston-daily-rotate-file": "^4.5.5" }, "devDependencies": { "nodemon": "^2.0.12" diff --git a/server.js b/server.js index 71704fe..7e03da7 100644 --- a/server.js +++ b/server.js @@ -2,6 +2,7 @@ require('dotenv').config(); const express = require('express') const app = express() const bodyParser = require('body-parser'); +const path = require('path'); //it is used to clear cache app.use(function(req, res, next) { @@ -14,6 +15,9 @@ app.use(function(req, res, next) { const {logMsg} = require('./app/services/logger.js'); +app.set('views', path.join(__dirname, 'app\\views')); +app.set('view engine', 'ejs'); + const swaggerJsdoc = require('swagger-jsdoc'); const swaggerUi = require('swagger-ui-express'); @@ -62,3 +66,5 @@ app.listen({ port: PORT_NUMBER }, async () => { //await sequelize.authenticate() }) + +