-
Notifications
You must be signed in to change notification settings - Fork 0
/
detailstore.js
90 lines (76 loc) · 1.58 KB
/
detailstore.js
1
console.log('Starting detailstore.js');const fs = require('fs');var fetchnotes = ()=>{ try { var notesString = fs.readFileSync('store.json'); return JSON.parse(notesString); } catch (e) { }}; var saveNotes = (notes) => { fs.writeFileSync('store.json', JSON.stringify(notes));};var addNote = (name,mail,phone,block,city,pc,state,adhno,add) => { var notes=fetchnotes(); var note = { name, mail, phone, block, city, pc, state, adhno, add }; notes.push(note); saveNotes(notes); }; var listNote =()=> { var notes=fetchnotes(); return notes; } var nameNote =(name) => { var notes=fetchnotes(); var n=name; var filteredNotes = notes.filter((note) => note.name === n); return filteredNotes; } var cityNote =(city) => { var notes=fetchnotes(); var c=city; var filteredNotes = notes.filter((note) => note.city === c); return filteredNotes; } var pcNote =(pc) => { var notes=fetchnotes(); var p=pc; var filteredNotes = notes.filter((note) => note.pc === p); return filteredNotes; } var stateNote =(state) => { var notes=fetchnotes(); var s=state; var filteredNotes = notes.filter((note) => note.state === s); return filteredNotes; } var removeNote = (name) => { var notes = fetchnotes(); var filteredNotes = notes.filter((note) => note.name !== name); saveNotes(filteredNotes); return notes.length !== filteredNotes.length;};module.exports = { addNote, listNote, nameNote, cityNote, pcNote, stateNote, removeNote};