mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
ability to restore (soft deleted) listings
This commit is contained in:
@@ -26,6 +26,7 @@ export default async function listingsPlugin(fastify) {
|
||||
providerFilter,
|
||||
watchListFilter,
|
||||
statusFilter,
|
||||
hiddenOnly,
|
||||
sortfield = null,
|
||||
sortdir = 'asc',
|
||||
freeTextFilter,
|
||||
@@ -38,6 +39,7 @@ export default async function listingsPlugin(fastify) {
|
||||
};
|
||||
const normalizedActivity = toBool(activityFilter);
|
||||
const normalizedWatch = toBool(watchListFilter);
|
||||
const normalizedHidden = toBool(hiddenOnly) === true;
|
||||
const allowedStatuses = ['applied', 'rejected', 'accepted', 'none'];
|
||||
const normalizedStatus =
|
||||
typeof statusFilter === 'string' && allowedStatuses.includes(statusFilter.toLowerCase())
|
||||
@@ -62,6 +64,7 @@ export default async function listingsPlugin(fastify) {
|
||||
providerFilter,
|
||||
watchListFilter: normalizedWatch,
|
||||
statusFilter: normalizedStatus,
|
||||
hiddenOnly: normalizedHidden,
|
||||
sortField: sortfield || null,
|
||||
sortDir: sortdir === 'desc' ? 'desc' : 'asc',
|
||||
userId: request.session.currentUser,
|
||||
@@ -192,4 +195,21 @@ export default async function listingsPlugin(fastify) {
|
||||
}
|
||||
return reply.send();
|
||||
});
|
||||
|
||||
fastify.post('/restore', async (request, reply) => {
|
||||
const { ids } = request.body || {};
|
||||
const settings = await getSettings();
|
||||
try {
|
||||
if (settings.demoMode && !isAdminFn(request)) {
|
||||
return reply.code(403).send({ error: 'Sorry, but you cannot restore listings in demo mode ;)' });
|
||||
}
|
||||
if (Array.isArray(ids) && ids.length > 0) {
|
||||
listingStorage.restoreListingsById(ids);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
return reply.code(500).send({ error: error.message });
|
||||
}
|
||||
return reply.send();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user