Skip to content

Commit 03f1891

Browse files
author
Nitro
committed
Now API doesn't return sensitive user information.
Excluded: GET vote: _id, email GET comment: pw
1 parent 5aa1632 commit 03f1891

3 files changed

Lines changed: 2 additions & 10 deletions

File tree

src/database/comment.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,13 @@ async function deleteComment(id, pw) {
4848

4949
async function getComment(date1, date2) {
5050
const db = await getDB()
51-
// [TODO] exclude pw
5251
let result = await db.collection(colName).find(
5352
{
5453
date: {
5554
$gte: new Date(date1),
5655
$lt: new Date(date2)
5756
}
58-
}
57+
}, { projection: { pw: 0 } }
5958
).toArray()
6059
return result
6160
}

src/database/vote.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,13 @@ async function updateVote(date, meal, email, rate) {
5252

5353
async function getVote(date1, date2) {
5454
const db = await getDB()
55-
// [TODO] exclude _id and email array from the result
5655
let result = await db.collection(colName).find(
5756
{
5857
date: {
5958
$gte: new Date(date1),
6059
$lt: new Date(date2)
6160
}
62-
}
61+
}, { projection: { _id: 0, email: 0 } }
6362
).toArray()
6463
return result
6564
}

src/index.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ app.post('/vote', async (req, res) => {
9393
if (r) {
9494
callback(res, 200, 'POST Success: User rate has been successfully reflected.'
9595
)
96-
} else {
97-
callback(res, 400, 'POST Error: Unknown Error.')
9896
}
9997
})
10098

@@ -192,8 +190,6 @@ app.post('/comment', async (req, res) => {
192190
})
193191
if (r) {
194192
callback(res, 200, 'POST Success: Comment Added.')
195-
} else {
196-
callback(res, 400, 'POST Error: Unknown Error.')
197193
}
198194
})
199195

@@ -221,8 +217,6 @@ app.post('/delete_comment', async (req, res) => {
221217
})
222218
if (r) {
223219
callback(res, 200, 'POST Success: Comment Removed.')
224-
} else {
225-
callback(res, 400, 'POST Error: Unknown Error.')
226220
}
227221
})
228222

0 commit comments

Comments
 (0)