From f34ff0a961f40f50c2c21ca8f97e6bf9461352c3 Mon Sep 17 00:00:00 2001 From: Marc Hyeler Date: Tue, 13 Aug 2024 11:56:05 -0700 Subject: [PATCH] add routes for auto release config --- controllers/admin/adminAction.js | 18 ++++++++++++ controllers/admin/adminData.js | 18 ++++++++++++ routes/admin/adminData.js | 47 +++++++++++++++++++++++++++++++- 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/controllers/admin/adminAction.js b/controllers/admin/adminAction.js index e3930ed..13077fa 100644 --- a/controllers/admin/adminAction.js +++ b/controllers/admin/adminAction.js @@ -15,6 +15,24 @@ export async function setAreaRestriction(data) { try { if (await editConfig('restricted_areas', data)) return true; + } catch (err) { + return false; + } +} + +export async function setAutoReleaseEnablement(data) { + try { + if (await editConfig('enable_auto_release', data)) return true; + + } catch (err) { + return false; + } +} + +export async function setAutoReleaseDates(data) { + try { + if (await editConfig('auto_release_dates', data)) return true; + } catch (err) { return false; } diff --git a/controllers/admin/adminData.js b/controllers/admin/adminData.js index c604de3..e82a013 100644 --- a/controllers/admin/adminData.js +++ b/controllers/admin/adminData.js @@ -9,6 +9,7 @@ import {verificationQueue} from "../../models/verificationQueue.js"; import {createDataUser, createUser} from "../app/appData.js"; import {readConfig} from "../../utils/admin/config/configManager.js"; import {throwApplicationError} from "../../middleware/errorHandler.js"; +import {setAutoReleaseDates} from "./adminAction.js"; //todo fix try catch here @@ -29,6 +30,23 @@ export async function queryAreaRestriction() { } } +export async function queryAutoReleaseEnablement() { + try { + return await readConfig('enable_auto_release'); + } catch (err) { + throw err; + } +} + +export async function queryAutoReleaseDates() { + try { + return await readConfig('auto_release_dates'); + } catch (err) { + throw err; + } +} + + export async function queryStats() { let targetGrades = [9, 10, 11, 12]; diff --git a/routes/admin/adminData.js b/routes/admin/adminData.js index 5e7e1c5..328b1c8 100644 --- a/routes/admin/adminData.js +++ b/routes/admin/adminData.js @@ -1,5 +1,10 @@ import {loadLockers, loadUsers} from "../../controllers/admin/adminImportData.js"; -import {setAreaRestriction, setGradeRestriction} from "../../controllers/admin/adminAction.js"; +import { + setAreaRestriction, + setAutoReleaseDates, + setAutoReleaseEnablement, + setGradeRestriction +} from "../../controllers/admin/adminAction.js"; import { checkLocker, clearLockerDB, @@ -12,6 +17,8 @@ import { manualCreateUser, manualVerifyUser, queryAreaRestriction, + queryAutoReleaseDates, + queryAutoReleaseEnablement, queryAvailableLockersCount, queryGradeRestriction, queryStats, @@ -79,6 +86,44 @@ adminRouter.get('/management/area-restrictions', async (req, res) => { } }); +adminRouter.post('/management/auto-release-enablement', async (req, res) => { + const data = req.body; + + if (await setAutoReleaseEnablement(data)) { + res.status(200).json({status: 'upload successful'}); + } else { + res.status(500).json({status: 'Internal server error'}); + } + +}); +adminRouter.get('/management/auto-release-enablement', async (req, res) => { + try { + const data = await queryAutoReleaseEnablement(); + res.json(data); + } catch (error) { + res.status(500).json({error: 'Internal server error'}); + } +}); + + +adminRouter.post('/management/auto-release-dates', async (req, res) => { + const data = req.body; + + if (await setAutoReleaseDates(data)) { + res.status(200).json({status: 'upload successful'}); + } else { + res.status(500).json({status: 'Internal server error'}); + } + +}); +adminRouter.get('/management/auto-release-dates', async (req, res) => { + try { + const data = await queryAutoReleaseDates(); + res.json(data); + } catch (error) { + res.status(500).json({error: 'Internal server error'}); + } +}); //total users, total lockers, last hour,