From b6a9a70c283acb8af1f30e6a56e4a7169ac27670 Mon Sep 17 00:00:00 2001 From: Alexander Metzger Date: Fri, 12 Jan 2024 17:20:59 -0800 Subject: [PATCH] Revert "Sheets endpoint" This reverts commit 44d9b1fb5cd552146c90f0ac53e38623fc295dc6. --- public/components/Table.js | 17 ++-------- server/Business.js | 4 +-- server/Sheets.js | 64 -------------------------------------- server/server.js | 4 --- 4 files changed, 4 insertions(+), 85 deletions(-) delete mode 100644 server/Sheets.js diff --git a/public/components/Table.js b/public/components/Table.js index 122b23c..612a0c3 100644 --- a/public/components/Table.js +++ b/public/components/Table.js @@ -34,6 +34,7 @@ export class Table extends Component { +

role changed

@@ -41,8 +42,6 @@ export class Table extends Component {

success

- - `; } @@ -65,7 +64,6 @@ export class Table extends Component { 'N/A': 'lightgray', 'ABSENT(self-marked)': '#fc6060', }; - console.log(attendancearr); for (let i = 0; i < attendancearr.length; i++) { if (attendancearr[i].user_id) attendancearr[i].id = attendancearr[i].user_id; if (!map.has(attendancearr[i].id)) { @@ -419,20 +417,9 @@ export class Table extends Component { } // combine each row data with new line character csv_data = csv_data.join('\n'); + // console.log(csv_data); this.downloadCSVFile(csv_data); }; - - this.shadowRoot.getElementById('copy-sheets-import').onfocus = () => { - // onfocus instead of onclick fixes the clipboard DOM exception security issue - window.navigator.clipboard.writeText( - `=IMPORTDATA("https://verified-tomcat-generally.ngrok-free.app/sheet/${this.businessID}")`, - ); - this.shadowRoot.getElementById('copy-sheets-import').classList.add('success'); - document.activeElement.blur(); - setTimeout(() => { - this.shadowRoot.getElementById('copy-sheets-import').classList.remove('success'); - }, 5000); - }; } } diff --git a/server/Business.js b/server/Business.js index a0ab4d5..62b8e1a 100644 --- a/server/Business.js +++ b/server/Business.js @@ -267,7 +267,7 @@ router.get('/changeName', async (request, response) => { }); router.get('/getRecordSettings', async (request, response) => { - const uid = await handleAuth(request, response); + const uid = await handleAuth(request, response, request.query.businessId, { read: true }); if (!uid) return; const businessId = request.query.businessId; @@ -279,7 +279,7 @@ router.get('/getRecordSettings', async (request, response) => { }); router.get('/changeRecordSettings', async (request, response) => { - const uid = await handleAuth(request, response); + const uid = await handleAuth(request, response, request.query.businessId, { write: true }); if (!uid) return; const businessId = request.query.businessId; diff --git a/server/Sheets.js b/server/Sheets.js deleted file mode 100644 index 76c4b02..0000000 --- a/server/Sheets.js +++ /dev/null @@ -1,64 +0,0 @@ -// express for routing -const express = require('express'), - router = express.Router(); -// database access -const { asyncGet, asyncAll, asyncRun, asyncRunWithID, asyncRunWithChanges } = require('./Database'); -// user auth -const { handleAuth, getAccess } = require('./Auth'); -// random universal unique ids for joincodes -const uuid = require('uuid'); - -router.get('/sheet/:bid/', async (req, res) => { - const businessId = req.params.bid; - - const events = await asyncAll( - ` - SELECT - Events.id, - Events.name - FROM - Events - WHERE - Events.business_id = ?`, - [businessId], - ); - - const concatArr = []; - for (let i = 0; i < events.length; i++) { - concatArr.push( - `group_concat(case when Events.id = ${events[i].id} then IFNULL(Records.status, case when CAST(strftime('%s', 'now') AS INT) > Events.endtimestamp then 'ABSENT' else 'N/A' end) end) as "z${events[i].id}"`, - ); - } - - const tableData = await asyncAll( - ` - SELECT - Users.name AS Name, - ${concatArr.join(', ')} - FROM - Members - INNER JOIN Users ON Members.user_id = Users.id - JOIN Events ON Events.business_id = Members.business_id - LEFT JOIN Records ON Events.id = Records.event_id AND Records.user_id = Users.id - WHERE - Members.business_id = ? - GROUP BY - Users.id - ORDER BY - Users.name`, - [businessId], - ); - - const tableCSV = [['Name', ...events.map(x => "'" + x.name)]].concat(tableData); - res.set('Content-Type', 'text/csv'); - res.send( - tableCSV - .map(it => { - return Object.values(it).toString(); - }) - .join('\n'), - ); -}); - -// ============================ SHEETS EXPORTS ============================ -exports.sheetsRouter = router; diff --git a/server/server.js b/server/server.js index d454dbf..2f43400 100644 --- a/server/server.js +++ b/server/server.js @@ -57,10 +57,6 @@ app.use('/', attendanceRouter); const { eventRouter } = require('./Event'); app.use('/', eventRouter); -// ============================ SHEETS ============================ -const { sheetsRouter } = require('./Sheets'); -app.use('/', sheetsRouter); - // ============================ SERVER ============================ // listen for requests :) module.exports.app = app;