@@ -50,14 +50,25 @@ router.post('/login', async (req, res) => {
50
50
}
51
51
} )
52
52
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
+
53
64
router . post ( '/item' , auth , async ( req , res ) => {
54
65
try {
55
66
await db . addItem ( req . body )
56
67
57
68
res . json ( { added : req . body } )
58
69
59
70
} catch ( error ) {
60
- res . status ( 400 ) . json ( { error : error } )
71
+ res . status ( 400 ) . json ( { error : error . toString ( ) } )
61
72
}
62
73
} )
63
74
@@ -68,7 +79,7 @@ router.put('/item', auth, async (req, res) => {
68
79
res . json ( { updated : req . body } )
69
80
70
81
} catch ( error ) {
71
- res . status ( 400 ) . json ( { error : error } )
82
+ res . status ( 400 ) . json ( { error : error . toString ( ) } )
72
83
}
73
84
} )
74
85
@@ -79,7 +90,7 @@ router.delete('/item', auth, async (req, res) => {
79
90
res . json ( { deleted : req . body } )
80
91
81
92
} catch ( error ) {
82
- res . status ( 400 ) . json ( { error : error } )
93
+ res . status ( 400 ) . json ( { error : error . toString ( ) } )
83
94
}
84
95
} )
85
96
@@ -99,7 +110,7 @@ router.post('/category', auth, async (req, res) => {
99
110
res . json ( { added : req . body } )
100
111
101
112
} catch ( error ) {
102
- res . status ( 400 ) . json ( { error : error } )
113
+ res . status ( 400 ) . json ( { error : error . toString ( ) } )
103
114
}
104
115
} )
105
116
@@ -110,7 +121,7 @@ router.put('/category', auth, async (req, res) => {
110
121
res . json ( { updated : req . body } )
111
122
112
123
} catch ( error ) {
113
- res . status ( 400 ) . json ( { error : error } )
124
+ res . status ( 400 ) . json ( { error : error . toString ( ) } )
114
125
}
115
126
} )
116
127
@@ -121,7 +132,7 @@ router.delete('/category', auth, async (req, res) => {
121
132
res . json ( { deleted : req . body } )
122
133
123
134
} catch ( error ) {
124
- res . status ( 400 ) . json ( { error : error } )
135
+ res . status ( 400 ) . json ( { error : error . toString ( ) } )
125
136
}
126
137
} )
127
138
@@ -168,7 +179,7 @@ router.post('/promo', auth, async (req, res) => {
168
179
res . json ( { added : req . body } )
169
180
170
181
} catch ( error ) {
171
- res . status ( 400 ) . json ( { error : error } )
182
+ res . status ( 400 ) . json ( { error : error . toString ( ) } )
172
183
}
173
184
} )
174
185
@@ -179,7 +190,7 @@ router.delete('/promo', auth, async (req, res) => {
179
190
res . json ( { deleted : req . body } )
180
191
181
192
} catch ( error ) {
182
- res . status ( 400 ) . json ( { error : error } )
193
+ res . status ( 400 ) . json ( { error : error . toString ( ) } )
183
194
}
184
195
} )
185
196
@@ -190,7 +201,7 @@ router.get('/promos', auth, async (req, res) => {
190
201
res . json ( result )
191
202
192
203
} catch ( error ) {
193
- res . status ( 400 ) . json ( { error : error } )
204
+ res . status ( 400 ) . json ( { error : error . toString ( ) } )
194
205
}
195
206
} )
196
207
0 commit comments