coryd.dev/cli/lib/tasks/updateReadingProgress.js

45 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import inquirer from 'inquirer';
import { loadConfig } from '../config.js';
import { initDirectusClient, searchItems, updateItem } from '../directus/client.js';
export const updateReadingProgress = async () => {
const config = await loadConfig();
initDirectusClient(config);
const readingBooks = await searchItems('books', '', { read_status: 'started' });
if (!readingBooks.length) {
console.log('📖 No books currently marked as "started".');
return;
}
const { bookId } = await inquirer.prompt({
type: 'list',
name: 'bookId',
message: '📚 Select a book to update progress:',
choices: readingBooks.map(book => {
const title = book.title || book.name || `Book #${book.id}`;
const progress = book.progress ?? 0;
return {
name: `${title} (${progress}%)`,
value: book.id
};
})
});
const { progress } = await inquirer.prompt({
name: 'progress',
message: '📕 New progress percentage (0100):',
validate: input => {
const num = Number(input);
return !isNaN(num) && num >= 0 && num <= 100 || 'Enter a number from 0 to 100';
}
});
await updateItem('books', bookId, { progress: Number(progress) });
console.log(`✅ Updated book progress to ${progress}%`);
};