-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcontrollers.ts
More file actions
63 lines (47 loc) · 1.51 KB
/
controllers.ts
File metadata and controls
63 lines (47 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import express from 'express';
import * as uuid from 'uuid';
import { Auction, Bid, User } from './types';
const router = express.Router();
// our 'database' (we'll be adding an actual database connection during the SQL workshop)
const auctions = new Map<string, Auction>();
const bids = new Map<string, Bid>();
const users = new Map<string, User>();
// add a fake auctioneer
const auctioneerId = '249b2f8b-5285-4031-a164-63102017a9ba';
const auctioneer = {
id: auctioneerId,
username: 'auctioneer',
balance: 100,
}
users.set(auctioneerId, auctioneer);
// define the routes
router.get('/auctions', (req, res) => {
const auctionList = Array.from(auctions.values());
return res.status(200).json({ auctions: auctionList });
});
router.get('/auction/:id', (req, res) => {
const { id } = req.params;
const auction = auctions.get(id);
if (auction) {
return res.status(200).json({ auction });
} else {
return res.status(404).json({ error: `Auction ${id} not found` });
}
});
router.post('/auction', (req, res) => {
// TODO: implement
});
router.post('/auction/:id/bid', (req, res) => {
// TODO: implement based on below steps
// 1. check if auction id is valid
// 2. check if auction hasn't ended
// 3. check if user id is valid
// 4. check if user has enough balance to place this bid
// 5. check if bid amount is high enough
// 6. update our database
// 7. return successful response
});
router.post('/user', (req, res) => {
// TODO: implement
});
export default router;