Skip to content

Commit

Permalink
add routes for auto release config
Browse files Browse the repository at this point in the history
  • Loading branch information
birdpump committed Aug 13, 2024
1 parent 573f919 commit f34ff0a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
18 changes: 18 additions & 0 deletions controllers/admin/adminAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
18 changes: 18 additions & 0 deletions controllers/admin/adminData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];

Expand Down
47 changes: 46 additions & 1 deletion routes/admin/adminData.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -12,6 +17,8 @@ import {
manualCreateUser,
manualVerifyUser,
queryAreaRestriction,
queryAutoReleaseDates,
queryAutoReleaseEnablement,
queryAvailableLockersCount,
queryGradeRestriction,
queryStats,
Expand Down Expand Up @@ -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,

Expand Down

0 comments on commit f34ff0a

Please sign in to comment.