Skip to content
Snippets Groups Projects
Commit 5cedf1ba authored by Jack Hu's avatar Jack Hu
Browse files

added some error codes for REST

parent 332a0ffe
No related branches found
No related tags found
1 merge request!7TS Migration
...@@ -25,6 +25,7 @@ export default class RestServer implements IServer { ...@@ -25,6 +25,7 @@ export default class RestServer implements IServer {
this.server.get("/product/:product_id", async (req: express.Request, res: express.Response) => { this.server.get("/product/:product_id", async (req: express.Request, res: express.Response) => {
const { productId } = req.params as ProductRequest; const { productId } = req.params as ProductRequest;
if (!productId) res.status(400).send("No product id provided");
const product = await this.db.queryProductById(productId); const product = await this.db.queryProductById(productId);
res.send(product) res.send(product)
}); // Gets a product by product id }); // Gets a product by product id
...@@ -52,18 +53,21 @@ export default class RestServer implements IServer { ...@@ -52,18 +53,21 @@ export default class RestServer implements IServer {
this.server.get("/orders", async (req: express.Request, res: express.Response) => { this.server.get("/orders", async (req: express.Request, res: express.Response) => {
const { id } = req.query as UserRequest; const { id } = req.query as UserRequest;
if (!id) res.status(400).send("No user id provided");
const orders = await this.db.queryOrdersByUser(id); const orders = await this.db.queryOrdersByUser(id);
res.send(orders); res.send(orders);
}); // Gets all of a single user's orders }); // Gets all of a single user's orders
this.server.get("/order/:id", async (req: express.Request, res: express.Response) => { this.server.get("/order/:id", async (req: express.Request, res: express.Response) => {
const { id } = req.params as OrderRequest; const { id } = req.params as OrderRequest;
if (!id) res.status(400).send("No order id provided");
const order = await this.db.queryOrderById(id); const order = await this.db.queryOrderById(id);
res.send(order); res.send(order);
}); // Gets more details on a specific order by id }); // Gets more details on a specific order by id
this.server.get("/user/:id", async (req: express.Request, res: express.Response) => { this.server.get("/user/:id", async (req: express.Request, res: express.Response) => {
const { id } = req.params as UserRequest; const { id } = req.params as UserRequest;
if (!id) res.status(400).send("No user id provided");
const user = await this.db.queryUserById(id); const user = await this.db.queryUserById(id);
res.send(user); res.send(user);
}); // Gets details on a specific user by username }); // Gets details on a specific user by username
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment