Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lab-skeleton
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SE464 Fall 2023
lab-skeleton
Commits
5cedf1ba
Commit
5cedf1ba
authored
1 year ago
by
Jack Hu
Browse files
Options
Downloads
Patches
Plain Diff
added some error codes for REST
parent
332a0ffe
No related branches found
No related tags found
1 merge request
!7
TS Migration
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/servers/restServer.ts
+4
-0
4 additions, 0 deletions
src/servers/restServer.ts
with
4 additions
and
0 deletions
src/servers/restServer.ts
+
4
−
0
View file @
5cedf1ba
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment