Skip to content

Commit 247bc90

Browse files
committed
finished api
1 parent 761dbbb commit 247bc90

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

api/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ router.use((req, res, next) => {
1818
next()
1919
})
2020

21-
router.get('/info', async (req, res) => {
21+
router.get('/abstracts-info', async (req, res) => {
2222
try {
2323
const o = {
2424
map: function() {
@@ -41,20 +41,20 @@ router.get('/info', async (req, res) => {
4141
.map(({ _id, value }) => ({ flow: _id, courses: JSON.parse(value) }))
4242

4343
res.json({ data })
44-
} catch (e) {
45-
console.error(e)
46-
res.status(500).json({ error: 'Db error' })
44+
} catch (err) {
45+
log.error({ err }, 'api abstracts-info route')
46+
res.status(500).json({ error: 'error' })
4747
}
4848
})
4949

5050
router.get('/abstracts/:id?', async (req, res) => {
5151
try {
5252
const { id } = req.params
5353
if (id) {
54-
if (!mongoose.Types.ObjectId.isValid(req.params.id))
54+
if (!mongoose.Types.ObjectId.isValid(id))
5555
return res.status(400).json({ error: 'Invalid id' })
5656

57-
const abstract = await Abstract.findById(id)
57+
const abstract = await Abstract.findById(id, '-__v')
5858
return abstract
5959
? res.json({ data: abstract })
6060
: res.status(404).json({ data: null })
@@ -78,22 +78,22 @@ router.get('/abstracts/:id?', async (req, res) => {
7878
name: '$name',
7979
semester: '$semester',
8080
authorId: '$authorId',
81+
date: '$date',
8182
telegraph_url: '$telegraph_url',
8283
telegraph_path: '$telegraph_path',
8384
telegraph_title: '$telegraph_title'
84-
}
85-
} } },
85+
} } } },
8686
{ $project: {
8787
_id: 0,
8888
subject: '$_id',
8989
abstracts: '$abstracts'
9090
} }
9191
])
92-
throw new Error('test')
92+
9393
res.json({ data })
9494
} catch (err) {
9595
log.error({ err }, 'api abstracts route')
96-
res.status(500).json({ error: 'Error 500\nШось поломилося' })
96+
res.status(500).json({ error: 'error' })
9797
}
9898
})
9999

models/abstract.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const Schema = mongoose.Schema,
1717
semester: { type: Number, required: true },
1818
flow: { type: String, required: true },
1919
date: { type: Date, default: Date.now }
20-
})
20+
}, { versionKey: false })
2121

2222
if (process.env.NODE_ENV === 'production') {
2323
Abstract.post('save', async ({ flow, course, semester, authorId, author, subject, telegraph_url, name }) => {

modules/logger.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const bunyan = require('bunyan')
22
const { name } = require('../package')
33
const log = bunyan.createLogger({
44
name,
5+
serializers: bunyan.stdSerializers,
56
level: process.env.LOG_LEVEL || 'info'
67
})
78

0 commit comments

Comments
 (0)