tasks: refactor listByTypePaged into list with options

this way we can list by prefix (coming commit)
This commit is contained in:
Girish Ramakrishnan
2025-10-06 19:28:47 +02:00
parent d010330b58
commit b21d29098b
3 changed files with 11 additions and 11 deletions
+6 -6
View File
@@ -6,7 +6,7 @@ exports = module.exports = {
update,
setCompleted,
setCompletedByType,
listByTypePaged,
list,
getLogs,
@@ -143,7 +143,7 @@ async function setCompletedByType(type, task) {
assert.strictEqual(typeof type, 'string');
assert.strictEqual(typeof task, 'object');
const results = await listByTypePaged(type, 1, 1);
const results = await list(1, 1, { type });
if (results.length !== 1) throw new BoxError(BoxError.NOT_FOUND, 'No such task');
await setCompleted(results[0].id, task);
@@ -232,17 +232,17 @@ async function stopAllTasks() {
if (error) debug(`stopAllTasks: error stopping stasks: ${error.message}`);
}
async function listByTypePaged(type, page, perPage) {
assert(typeof type === 'string' || type === null);
async function list(page, perPage, options) {
assert.strictEqual(typeof page, 'number');
assert.strictEqual(typeof perPage, 'number');
assert.strictEqual(typeof options, 'object');
const data = [];
let query = `SELECT ${TASKS_FIELDS} FROM tasks`;
if (type) {
if (options.type) {
query += ' WHERE TYPE=?';
data.push(type);
data.push(options.type);
}
query += ' ORDER BY creationTime DESC, id DESC LIMIT ?,?'; // put latest task first