Skip to content

Commit 45c600e

Browse files
committed
feat: add GET /api/orders/:id endpoint
1 parent de2ba8d commit 45c600e

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

backend/server.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff 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 {

0 commit comments

Comments
 (0)