aboutsummaryrefslogtreecommitdiffstats
path: root/pages/api/notes
diff options
context:
space:
mode:
Diffstat (limited to 'pages/api/notes')
-rw-r--r--pages/api/notes/[id].js14
-rw-r--r--pages/api/notes/index.js10
2 files changed, 11 insertions, 13 deletions
diff --git a/pages/api/notes/[id].js b/pages/api/notes/[id].js
index 58e458f..12f0ba4 100644
--- a/pages/api/notes/[id].js
+++ b/pages/api/notes/[id].js
@@ -4,7 +4,7 @@ import NoteList from 'models/NoteList'
import Note from 'models/Note'
export default withSession(async (req, res) => {
- const {id: _id} = req.query
+ const { id: _id } = req.query
await dbConnect()
switch (req.method) {
@@ -12,7 +12,7 @@ export default withSession(async (req, res) => {
try {
const user = req.session.get('user')
- if (!user || !user?.isVerified || !_id ) {
+ if (!user || !user?.isVerified || !_id) {
throw new Error('Something went wrong')
}
@@ -25,7 +25,7 @@ export default withSession(async (req, res) => {
res.status(200).json(note)
} catch (error) {
console.log(error)
- res.status(400).json({error: true})
+ res.status(400).json({ error: true })
}
break
case 'DELETE':
@@ -37,10 +37,10 @@ export default withSession(async (req, res) => {
}
const noteId = await NoteList.getNoteId(user.noteList, _id)
- if ( !noteId) throw new Error('Something went wrong')
+ if (!noteId) throw new Error('Something went wrong')
await Note.findByIdAndDelete(noteId)
- const {notes} = await NoteList.removeNote(user.noteList, _id)
+ const { notes } = await NoteList.removeNote(user.noteList, _id)
res.status(200).json(notes)
} catch (error) {
@@ -51,14 +51,14 @@ export default withSession(async (req, res) => {
case 'PUT':
try {
const user = req.session.get('user')
- const {title, noteId, content} = req.body
+ const { title, noteId, content } = req.body
if (!user || !user?.isVerified || !_id || !content) {
throw new Error('Something went wrong')
}
await Note.updateNote(noteId, content)
- const {notes} = await NoteList.updateList(user.noteList, noteId, title)
+ const { notes } = await NoteList.updateList(user.noteList, noteId, title)
res.status(200).json(notes)
} catch (error) {
diff --git a/pages/api/notes/index.js b/pages/api/notes/index.js
index f62f849..16cb88c 100644
--- a/pages/api/notes/index.js
+++ b/pages/api/notes/index.js
@@ -15,7 +15,7 @@ export default withSession(async (req, res) => {
throw new Error('Something went wrong')
}
- const {notes} = await NoteList.getList(user.noteList)
+ const { notes } = await NoteList.getList(user.noteList)
res.status(200).json(notes)
} catch (error) {
@@ -25,14 +25,14 @@ export default withSession(async (req, res) => {
case 'POST':
try {
const user = req.session.get('user')
- const {title, content} = req.body
+ const { title, content } = req.body
if (!user || !user?.isVerified || !content) {
throw new Error('Something went wrong')
}
- const note = await Note.create({content})
- const {notes} = await NoteList.addNote(user.noteList, note._id, title)
+ const note = await Note.create({ content })
+ const { notes } = await NoteList.addNote(user.noteList, note._id, title)
res.status(200).json(notes)
} catch (error) {
@@ -44,5 +44,3 @@ export default withSession(async (req, res) => {
break
}
})
-
-