Skip to content

Commit 2e71442

Browse files
author
ivan.kozhukhov
committed
feature: admin get item by id
1 parent 53c8d85 commit 2e71442

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

backend/routes/admin.js

+20-9
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,25 @@ router.post('/login', async (req, res) => {
5050
}
5151
})
5252

53+
router.get('/item', auth, async (req, res) => {
54+
try {
55+
const item = await db.getItemById(req.query.id)
56+
57+
res.json(item)
58+
59+
} catch (error) {
60+
res.status(400).json({ error: error.toString() })
61+
}
62+
})
63+
5364
router.post('/item', auth, async (req, res) => {
5465
try {
5566
await db.addItem(req.body)
5667

5768
res.json({ added: req.body })
5869

5970
} catch (error) {
60-
res.status(400).json({ error: error })
71+
res.status(400).json({ error: error.toString() })
6172
}
6273
})
6374

@@ -68,7 +79,7 @@ router.put('/item', auth, async (req, res) => {
6879
res.json({ updated: req.body })
6980

7081
} catch (error) {
71-
res.status(400).json({ error: error })
82+
res.status(400).json({ error: error.toString() })
7283
}
7384
})
7485

@@ -79,7 +90,7 @@ router.delete('/item', auth, async (req, res) => {
7990
res.json({ deleted: req.body })
8091

8192
} catch (error) {
82-
res.status(400).json({ error: error })
93+
res.status(400).json({ error: error.toString() })
8394
}
8495
})
8596

@@ -99,7 +110,7 @@ router.post('/category', auth, async (req, res) => {
99110
res.json({ added: req.body })
100111

101112
} catch (error) {
102-
res.status(400).json({ error: error })
113+
res.status(400).json({ error: error.toString() })
103114
}
104115
})
105116

@@ -110,7 +121,7 @@ router.put('/category', auth, async (req, res) => {
110121
res.json({ updated: req.body })
111122

112123
} catch (error) {
113-
res.status(400).json({ error: error })
124+
res.status(400).json({ error: error.toString() })
114125
}
115126
})
116127

@@ -121,7 +132,7 @@ router.delete('/category', auth, async (req, res) => {
121132
res.json({ deleted: req.body })
122133

123134
} catch (error) {
124-
res.status(400).json({ error: error })
135+
res.status(400).json({ error: error.toString() })
125136
}
126137
})
127138

@@ -168,7 +179,7 @@ router.post('/promo', auth, async (req, res) => {
168179
res.json({ added: req.body })
169180

170181
} catch (error) {
171-
res.status(400).json({ error: error })
182+
res.status(400).json({ error: error.toString() })
172183
}
173184
})
174185

@@ -179,7 +190,7 @@ router.delete('/promo', auth, async (req, res) => {
179190
res.json({ deleted: req.body })
180191

181192
} catch (error) {
182-
res.status(400).json({ error: error })
193+
res.status(400).json({ error: error.toString() })
183194
}
184195
})
185196

@@ -190,7 +201,7 @@ router.get('/promos', auth, async (req, res) => {
190201
res.json(result)
191202

192203
} catch (error) {
193-
res.status(400).json({ error: error })
204+
res.status(400).json({ error: error.toString() })
194205
}
195206
})
196207

0 commit comments

Comments
 (0)