Skip to content

Commit

Permalink
feat: reindex command (#8)
Browse files Browse the repository at this point in the history
Signed-off-by: inimaz <[email protected]>
  • Loading branch information
inimaz authored Nov 4, 2024
1 parent a17ef8e commit bddbb07
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Commands:
start <id> Start a task
update [options] <id> Update a task
agenda|a Show the agenda of today as if you had to do all the tasks today
reindex Reindex tasks so that their IDs go from 1 to N
help [command] display help for command
```
Expand Down
1 change: 1 addition & 0 deletions docs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Commands:
start <id> Start a task
update [options] <id> Update a task
agenda|a Show the agenda of today as if you had to do all the tasks today
reindex Reindex tasks so that their IDs go from 1 to N
help [command] display help for command
```
Expand Down
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,12 @@ program
await taskCommands.showAgendaDashboard();
});

program
.command("reindex")
.description("Reindex tasks so that their IDs go from 1 to N")
.action(async () => {
await taskCommands.setUpConfig();
await taskCommands.reindexTasks();
});

program.parse(process.argv);
13 changes: 13 additions & 0 deletions src/tasks/taskCommands.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ export default class TaskCommands {
await this.db.write();
await this.archivedb.write();
}
/**
* Reindex tasks so that their IDs go from 1 to N
*/
async reindexTasks() {
// Get all tasks
const tasks = await this.taskAPi.getAll();
let newId = 1;
tasks.data.forEach(async (task: ITask) => {
task._id = `${newId}`;
newId += 1;
});
await this.db.write();
}

/**
* Show the agenda dashboard
Expand Down

0 comments on commit bddbb07

Please sign in to comment.