Skip to content

Commit 1024ec6

Browse files
author
Amr Monier
committed
added deleting note functionality
1 parent 7ff32ae commit 1024ec6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

app.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ yargs.command({
4747
}
4848
})
4949

50+
yargs.command({
51+
command: 'remove',
52+
describe: 'Removing a note',
53+
builder: {
54+
title: {
55+
describe: 'note title',
56+
demandOption: true,
57+
type: 'string'
58+
}
59+
},
60+
handler: (argv) => {
61+
console.log(notesStorage.removeNote(argv.title))
62+
}
63+
})
64+
5065
yargs.parse()
5166

5267

notesController.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ class NotesController {
5959
console.log(chalk.bgRed('ERROR: '), chalk.red('this title already exist'))
6060
}
6161
}
62+
63+
removeNote(title) {
64+
this.fetchJSON()
65+
let notesCount = this.notes.data.length
66+
this.notes.data = this.notes.data.filter(note => note.title !== title)
67+
this.dumpJson()
68+
return notesCount === this.notes.data.length ? chalk.red('title not found') : chalk.green('note deleted successfully')
69+
}
6270
}
6371

6472
module.exports = NotesController

0 commit comments

Comments
 (0)