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

@@ -264,6 +264,7 @@ export const storeListings = (jobId, providerId, listings) => {
* @param {number} [params.createdBefore] - Only include listings created at or before this unix timestamp (ms).
* @param {string} [params.userId] - Current user id used to scope listings (ignored for admins).
* @param {boolean} [params.isAdmin=false] - When true, returns all listings.
* @param {boolean} [params.hiddenOnly=false] - When true, returns only soft-deleted (manually_deleted = 1) listings.
* @returns {{ totalNumber:number, page:number, result:Object[] }}
*/
export const queryListings = ({
@@ -284,6 +285,7 @@ export const queryListings = ({
maxPrice = null,
userId = null,
isAdmin = false,
hiddenOnly = false,
} = {}) => {
// sanitize inputs
const safePageSize = Number.isFinite(pageSize) && pageSize > 0 ? Math.min(1000, Math.floor(pageSize)) : 50;
@@ -365,8 +367,8 @@ export const queryListings = ({
whereParts.push('(l.price <= @maxPrice)');
}
// Build whereSql (filtering by manually_deleted = 0)
whereParts.push('(l.manually_deleted = 0)');
// Build whereSql: in normal mode hide soft-deleted; in hiddenOnly mode show only soft-deleted.
whereParts.push(hiddenOnly ? '(l.manually_deleted = 1)' : '(l.manually_deleted = 0)');
const whereSqlWithAlias = whereParts.length ? `WHERE ${whereParts.join(' AND ')}` : '';
@@ -463,6 +465,23 @@ export const deleteListingsById = (ids, hardDelete = false) => {
);
};
/**
* Restore previously soft-deleted listings by clearing their `manually_deleted` flag.
*
* @param {string[]} ids - Array of DB row IDs to restore.
* @returns {any} The result from SqliteConnection.execute.
*/
export const restoreListingsById = (ids) => {
if (!Array.isArray(ids) || ids.length === 0) return;
const placeholders = ids.map(() => '?').join(',');
return SqliteConnection.execute(
`UPDATE listings
SET manually_deleted = 0
WHERE id IN (${placeholders})`,
ids,
);
};
/**
* Return all listings that are active, have an address, and do not yet have geocoordinates.
*