adding buttons to remove listings from a given job

This commit is contained in:
orangecoding
2025-10-03 13:04:35 +02:00
parent 31a14a0352
commit 4b15894603
5 changed files with 67 additions and 9 deletions

View File

@@ -1,6 +1,8 @@
import restana from 'restana';
import * as listingStorage from '../../services/storage/listingsStorage.js';
import { isAdmin as isAdminFn } from '../security.js';
import logger from '../../services/logger.js';
const service = restana();
const listingsRouter = service.newRouter();
@@ -8,7 +10,7 @@ const listingsRouter = service.newRouter();
listingsRouter.get('/table', async (req, res) => {
const { page, pageSize = 50, filter, sortfield = null, sortdir = 'asc' } = req.query || {};
const result = listingStorage.queryListings({
res.body = listingStorage.queryListings({
page: page ? parseInt(page, 10) : 1,
pageSize: pageSize ? parseInt(pageSize, 10) : 50,
filter: filter || undefined,
@@ -17,7 +19,18 @@ listingsRouter.get('/table', async (req, res) => {
userId: req.session.currentUser,
isAdmin: isAdminFn(req),
});
res.body = result;
res.send();
});
listingsRouter.delete('/', async (req, res) => {
const { jobId } = req.body;
try {
listingStorage.deleteListings(jobId);
} catch (error) {
res.send(new Error(error));
logger.error(error);
}
res.send();
});
export { listingsRouter };