ability to restore (soft deleted) listings

This commit is contained in:
orangecoding
2026-06-11 08:24:26 +02:00
parent 3b727ea708
commit 3249881771
13 changed files with 438 additions and 134 deletions

View File

@@ -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();
});
}