diff --git a/app/config/db.config.js b/app/config/db.config.js deleted file mode 100644 index ceea409..0000000 --- a/app/config/db.config.js +++ /dev/null @@ -1,16 +0,0 @@ -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)) - - } - }; \ No newline at end of file diff --git a/app/controllers/data.json b/app/controllers/data.json new file mode 100644 index 0000000..388b2d8 --- /dev/null +++ b/app/controllers/data.json @@ -0,0 +1,8 @@ +[ + { + "email": "aadhavanvalli@gmail.com" + }, + { + "email": "aadhavancarousell@gmail.com" + } +] \ No newline at end of file diff --git a/app/controllers/rosy-semiotics-399007-a9066914a24a.json b/app/controllers/rosy-semiotics-399007-a9066914a24a.json new file mode 100644 index 0000000..5592760 --- /dev/null +++ b/app/controllers/rosy-semiotics-399007-a9066914a24a.json @@ -0,0 +1,13 @@ +{ + "type": "service_account", + "project_id": "rosy-semiotics-399007", + "private_key_id": "a9066914a24a4cf1892ec3d5e73dcbdd9e0c5690", + "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDnrREnBGg7V35b\nxF4754WUdPniqyIojGO0NzThMHDzcLtu+bD7PTlkE1yYT7oUk8ncw7ogKEymuAoY\nnIvqkgEnmulva+stBIqRVVcUndhFTXB/mw4g0TfjW9MZgD4fkK+B2UpPnsWPZikf\n2zECHDTQ/mhXFlv70R8arCnsGY3dOEupdfEyO6mt2i0Z0YG1Ni8TJBdV7HvGAFt5\nsFTS/igxQYUAZQ+uIbC1NbdCgWIQdlsB83YQy2gvHXxtL+7Luyd0kK0SY1lun0bC\nJk2HsE3OWpgiyFi646eoHXuzs6J2TANVPwsLsMCxRO1EkKFRSVDGimmE0FMumbi1\nVCDHZpdPAgMBAAECggEAAMIuTQ2Lf4iGq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/rAoGBAKitQDMBZ7Ov1vLsL3ZK\nhkx4cbFV9pQcjTQr62VVyNKXgq/gfwq57YnErQyRTtYVMkJT2D5cNOiiV5nwOrjT\nz34YqYb8T7jbfcdRO/QQ60wgcx5eJDeCX1gqRKMl+0PoS3l58yZ0n30eulBCUwtv\nnrO/gauaV/QcXqSEkvzU0W5s\n-----END PRIVATE KEY-----\n", + "client_email": "test-google-sheet@rosy-semiotics-399007.iam.gserviceaccount.com", + "client_id": "106850194283146982068", + "auth_uri": "https://accounts.google.com/o/oauth2/auth", + "token_uri": "https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/test-google-sheet%40rosy-semiotics-399007.iam.gserviceaccount.com", + "universe_domain": "googleapis.com" +} diff --git a/app/controllers/test.controller.js b/app/controllers/test.controller.js index 747e869..cfcd2a1 100644 --- a/app/controllers/test.controller.js +++ b/app/controllers/test.controller.js @@ -1,21 +1,49 @@ -const { sequelize,Test} = require('../models') +// const { sequelize,Test} = require('../models') const { logMsg } = require('../services/logger.js'); const { GoogleSpreadsheet } = require('google-spreadsheet'); const fs = require('fs'); +const path = require('path'); +// const { log } = require('util'); require('dotenv').config(); let dropdown = []; let column_name; let doc; +let CREDENTIALS; // use in addRow and getRow api let tempData = []; +const filePath = path.join(__dirname, 'data.json'); +const datafromjson = require('./data.json'); +const { log } = require('console'); +// const { col } = require('sequelize'); + +let number; // Declare number as a global variable + +async function fetchSheetData() { + try { + let sheet1 = doc.sheetsByIndex[0]; + let rows1 = await sheet1.getRows(); + number = rows1.length+1; // Assign the value to the global variable 'number' + + // You can now use the 'number' variable as a global variable. + console.log(`Number of rows: ${number}`); + } catch (error) { + console.error('Error fetching sheet data:', error); + } +} + +// Call the async function to fetch and work with sheet data. +// You can use 'number' outside of the function. +console.log(`Global number variable: ${number}`); exports.Welcome = (req, res) => { + // number=0; + console.log(datafromjson.length); try { - const Msg = "Welcome....!"; + const Msg = "Welcom....!"; console.log(Msg); logMsg.info("Api Call Success"); res.send({'status':200 , message:"Success." ,'data': Msg}); @@ -27,8 +55,6 @@ exports.Welcome = (req, res) => }; - - exports.loginPage = async (req, res ) => { try @@ -40,130 +66,178 @@ exports.loginPage = async (req, res ) => }; - - -exports.getRow = async (req, res) => +exports.adduser = async (req, res ) => { try { - email = req.query.email; - // arr for ejs - const empData = []; - // clear array - tempData = []; - // clear temp data - tempData = []; - await doc.loadInfo(); - // Index of the sheet - let sheet = doc.sheetsByIndex[0]; - // Get all the rows - let rows = await sheet.getRows(); - - // dropdown array for each dropdown column - category = []; age_Category = []; - basthi = []; varga = []; - milan_shaka = []; poruppu = []; - blood_group = []; ganavesh_2w_4w_basg = []; - new_index = 0; - - category.push(''); - age_Category.push(''); - basthi.push(''); - varga.push(''); - milan_shaka.push(''); - poruppu.push(''); - blood_group.push(''); - ganavesh_2w_4w_basg.push('') - - for (let index = 0; index < rows.length; index++) { - const row = rows[index]; - category.push(row['Çategory']); - age_Category.push(row['Age Category']); - basthi.push(row['Basthi']); - varga.push(row['Varga']); - milan_shaka.push(row['Milan / Shaka']); - poruppu.push(row['Poruppu']); - blood_group.push(row['Blood Group']); - ganavesh_2w_4w_basg.push(row['Ganavesh']); - if (index == rows.length-1) { - new_index = Number(row['Sl.']) + 1; - } - }; - dropdown = - { - "category": [...new Set(category)], - "age_Category" : [...new Set(age_Category)], - "basthi" : [...new Set(basthi)], - "varga" : [...new Set(varga)], - "milan_shaka" : [...new Set(milan_shaka)], - "poruppu" : [...new Set(poruppu)], - "blood_group" : [...new Set(blood_group)], - "ganavesh_2w_4w_basg" : [...new Set(ganavesh_2w_4w_basg)], - "new_index" : new_index - } - for (let index = 0; index < rows.length; index++) { - const row = rows[index]; - // get sheet column name for dynamic insertion - if(index == 0){ column_name = row._sheet.headerValues; } - if (row.email == email) { - // store login person data from sheet because get person id that is used to match other person manager_id - var obj = {} - for (let i = 0; i < column_name.length; i++){ - // get email position in dynamic array - Object.assign( obj , { [column_name[i]] : row[column_name[i]] }); - } - tempData.push(obj); - } - }; - if (tempData.length > 0) - { - for (let index = 0; index < rows.length; index++) { - const row = rows[index]; - if (row.email == email || row.Gatnayak == tempData[0]['email'] ) { - var obj = {} - for (let i = 0; i < column_name.length; i++){ - // get email position in dynamic array - Object.assign( obj , { [column_name[i]] : row[column_name[i]] }); - } - empData.push(obj); - } - }; - res.render( 'displaydata' , { "data" : empData , "dropdown" : dropdown} , function (err, html ) { res.send(html) }); - } - else - { - res.send('
No Data
'); - } + res.render( 'adduser' ,function (err, html ) { res.send(html) }) } catch(err) { res.send({'status':404,message: err.message || "Some error occurred while retrieving data." ,'data': "No data" }); } //end of try catch }; - - -exports.addRow = async (req, res) => +exports.addjson = async (req, res ) => { try { - newData = req.body.data; - // key value mapping - var obj = {} - for (let i = 0; i < column_name.length; i++){ - // get email position in dynamic array - Object.assign( obj , { [column_name[i]] : newData[i] }); - } - let rows = [obj]; - // load the documents info - await doc.loadInfo(); - // Index of the sheet - let sheet = doc.sheetsByIndex[0]; - for (let index = 0; index < rows.length; index++) { - const row = rows[index]; - await sheet.addRow(row); - } - if (rows[0]['Gatnayak'] == tempData[0].email ) {res.send({'status':200 , message:"Success." ,'data': "success" , 'statusCode' : 1 }); } + + const getvalue = req.body.data; + // console.log(req.body.data); + let newData={"email":getvalue}; + fs.readFile(filePath, 'utf8', (readErr, data) => { + if (readErr) { + console.error('Error reading file:', readErr); + return; + } + let existingData = []; + + try { + // Parse the existing JSON data (if any) + existingData = JSON.parse(data); + } catch (parseErr) { + console.error('Error parsing existing data:', parseErr); + } + + // Append the new data to the existing array + existingData.push(newData); + + // Write the updated data back to the JSON file + fs.writeFile(filePath, JSON.stringify(existingData, null, 2), (writeErr) => { + if (writeErr) { + console.error('Error writing to file:', writeErr); + } else { + console.log('Data appended and saved to file successfully.'); + } + }); + }) + if(rows[0]['Gatnayak'] == tempData[0].email ) {res.send({'status':200 , message:"Success." ,'data': "success" , 'statusCode' : 1 }); } else{res.send({'status':200 , message:"Success." ,'data': "success", 'statusCode' : 0 }); } + } catch(err) { + res.send({'status':404,message: err.message || "Some error occurred while retrieving data." ,'data': "No data" }); + } //end of try catch + +}; + +exports.getRow = async (req, res) => +{ + try + { + fetchSheetData(); + for (let index = 0; index < datafromjson.length; index++) { + // console.log(req.query.email); + // email = req.query.email; + const email=req.body.email; + req.session.user = { email }; + // console.log(req.session.user.email); + // console.log(email); + aadhaemail= datafromjson[0].email; + let emaill = datafromjson[index].email; + if (email == emaill) { + const empData = []; + tempData = ['fdd']; + await doc.loadInfo(); + let sheet = doc.sheetsByIndex[0]; + let rows = await sheet.getRows(); + // const number = rows.length+1; + category = []; age_Category = []; + basthi = []; varga = []; + milan_shaka = []; poruppu = []; + blood_group = []; ganavesh_2w_4w_basg = []; + // new_index = 0; + + category.push('Redmi','Samsung','ONEPLUS'); + age_Category.push('18-21','22-25','26-30'); + basthi.push('Niruha/Kashaya Basthi','Anuvasana Basthi'); + varga.push('Rasi','Hora','Chaturthamsa','Dasamsa','Shodasamsa'); + milan_shaka.push(''); + poruppu.push(''); + blood_group.push('A+','A-','B+','B-','AB+','AB-','O+','O-'); + ganavesh_2w_4w_basg.push('') + for (let index = 0; index < rows.length; index++) { + const row = rows[index]; + category.push(row['Category']); + age_Category.push(row['Age Category']); + basthi.push(row['Basthi']); + varga.push(row['Varga']); + milan_shaka.push(row['Milan / Shaka']); + poruppu.push(row['Poruppu']); + blood_group.push(row['Blood Group']); + ganavesh_2w_4w_basg.push(row['Ganavesh']); + // if (index == rows.length-1) { + // new_index = Number(row.Sl) + 1; + // } + }; + dropdown ={ + "category": [...new Set(category)], + "age_Category" : [...new Set(age_Category)], + "basthi" : [...new Set(basthi)], + "varga" : [...new Set(varga)], + "milan_shaka" : [...new Set(milan_shaka)], + "poruppu" : [...new Set(poruppu)], + "blood_group" : [...new Set(blood_group)], + "ganavesh_2w_4w_basg" : [...new Set(ganavesh_2w_4w_basg)], + // "new_index" : new_index + } + for (let index = 0; index < rows.length; index++) { + const row = rows[index]; + if(index == 0){ column_name = row._sheet.headerValues; } + if (row.email == email) { + var obj = {} + for (let i = 0; i < column_name.length; i++){ + Object.assign( obj , { [column_name[i]] : row[column_name[i]] }); + } + tempData.push(obj); + } + }; + // if (tempData.length > 0) { + for (let index = 0; index < rows.length; index++) { + const row = rows[index]; + // console.log(rows[0]._rawData[22]); + // if (row == email || row.Gatnayak == tempData[0]['email'] ) { + if(true){ + // console.log(row.); + var obj = {} + for (let i = 0; i < column_name.length; i++){ + Object.assign( obj , { [column_name[i]] : row[column_name[i]] }); + } + empData.push(obj); + } + }; + + res.render( 'displaydata' , { "data" : empData , "dropdown" : dropdown , aadhaemail,email,number} , function (err, html ) { res.send(html) }); + // } + // else{ + // res.send('No Data
'); + // } + } + } + + res.end("-
| Sl. | +Sl | +Sno | Name | Category | Age Category | @@ -501,17 +557,18 @@ label{ padding-left: 20px; }Gurupooja 2021 | Gatnayak | Phone | +Phone | |||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| <%=emp['Sl.'] %> | -<%=emp.Name %> | -<%=emp['Çategory'] %> | +<%=emp.Sl %> | +<%=emp.Sno %> | +<%=emp.Name %> | +<%=emp['Category'] %> | <%=emp['Age Category'] %> | -<%=emp.ContactNo %> | +<%=emp.ContactNo %> | <%=emp.Address %> | <%=emp.Reference %> | <%=emp.Basthi %> | @@ -540,23 +597,28 @@ label{ padding-left: 20px; }