mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
adding buttons to remove listings from a given job
This commit is contained in:
@@ -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 };
|
||||
|
||||
@@ -251,3 +251,14 @@ export const queryListings = ({
|
||||
|
||||
return { totalNumber, page: safePage, result: rows };
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete all listings for a given job id.
|
||||
*
|
||||
* @param {string} jobId - The job identifier whose listings should be removed.
|
||||
* @returns {any} The result from SqliteConnection.execute (may contain changes count).
|
||||
*/
|
||||
export const deleteListings = (jobId) => {
|
||||
if (!jobId) return;
|
||||
return SqliteConnection.execute(`DELETE FROM listings WHERE job_id = @jobId`, { jobId });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user