-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
44 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,38 @@ | ||
import mongoose from 'mongoose'; | ||
import '../models/note'; | ||
import config from '../../etc/config.json'; | ||
import config from '../etc/config.json'; | ||
|
||
const Note = mongoose.model('Note'); | ||
|
||
export function setUpConnection() { | ||
mongoose.connect(`mongodb://${config.db.host}:${config.db.port}/${config.db.name}`, { useMongoClient: true }); | ||
} | ||
const dbUtils = { | ||
|
||
export function listNotes() { | ||
return Note.find(); | ||
} | ||
setUpConnection: () => { | ||
mongoose.connect(`mongodb://${config.db.host}:${config.db.port}/${config.db.name}`, {useMongoClient: true}); | ||
}, | ||
|
||
export function createNote(data) { | ||
const note = new Note({ | ||
title: data.title, | ||
text: data.text, | ||
color: data.color, | ||
createdAt: new Date() | ||
}); | ||
listNotes: () => { | ||
return Note.find(); | ||
}, | ||
|
||
return note.save(); | ||
} | ||
createNote: (data) => { | ||
const note = new Note({ | ||
title: data.title, | ||
text: data.text, | ||
color: data.color, | ||
createdAt: new Date() | ||
}); | ||
|
||
export function deleteNote(id) { | ||
return Note.findById(id).remove(); | ||
} | ||
return note.save(); | ||
}, | ||
|
||
deleteNote: (id) => { | ||
return Note.findById(id).remove(); | ||
}, | ||
|
||
//for mongo _id = Object(id). $set gonna modify only matched fields | ||
updateNote: (data) => { | ||
return Note.update({_id: Object(data.id)},{$set: data}); | ||
} | ||
}; | ||
|
||
export default dbUtils; |