tasks: refactor listByTypePaged into list with options
this way we can list by prefix (coming commit)
This commit is contained in:
+6
-6
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user