File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -109,6 +109,28 @@ const server = createServer(async (req, res) => {
109109 sendJson ( res , 200 , orders ) ;
110110 return ;
111111 }
112+ if ( method === 'GET' && path . startsWith ( '/api/orders/' ) ) {
113+ console . log ( "I AM INSIDE ORDER ID ROUTE" ) ;
114+ const orderId = path . replace ( '/api/orders/' , '' ) ;
115+
116+
117+ const authHeader = req . headers . authorization ;
118+ if ( ! authHeader ) {
119+ sendJson ( res , 401 , { error : 'Unauthorized' } ) ;
120+ return ;
121+ }
122+
123+ const orders = database . getOrders ( { } ) ;
124+ const order = orders . find ( o => o . id === orderId ) ;
125+
126+ if ( ! order ) {
127+ sendJson ( res , 404 , { error : `Order not found: ${ orderId } ` } ) ;
128+ return ;
129+ }
130+
131+ sendJson ( res , 200 , order ) ;
132+ return ;
133+ }
112134
113135 if ( method === 'POST' && path === '/api/orders' ) {
114136 try {
You can’t perform that action at this time.
0 commit comments