1
|
|
|
import express from "express"; |
2
|
|
|
import tripModel from "../../../src/models/trip.js"; |
3
|
|
|
|
4
|
|
|
const router = express.Router(); |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @description Route for trips for one user |
8
|
|
|
* |
9
|
|
|
* @param {express.Request} req Request object |
10
|
|
|
* @param {express.Response} res Response object |
11
|
|
|
* @param {express.NextFunction} next Next function |
12
|
|
|
* |
13
|
|
|
* @returns {void} |
14
|
|
|
*/ |
15
|
|
|
router.get("/", async (req, res, next) => { |
16
|
|
|
try { |
17
|
|
|
const userId = req.body.user_id; |
18
|
|
|
|
19
|
|
|
const trips = await tripModel.userTrips(userId); |
20
|
|
|
|
21
|
|
|
res.status(200).json(trips); |
22
|
|
|
} catch (error) { |
23
|
|
|
next(error); |
24
|
|
|
} |
25
|
|
|
}); |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @description Route for trips for one user using pagination |
29
|
|
|
* |
30
|
|
|
* @param {express.Request} req Request object |
31
|
|
|
* @param {express.Response} res Response object |
32
|
|
|
* @param {express.NextFunction} next Next function |
33
|
|
|
* |
34
|
|
|
* @returns {void} |
35
|
|
|
*/ |
36
|
|
|
router.get("/limit/:limit/offset/:offset", async (req, res, next) => { |
37
|
|
|
try { |
38
|
|
|
const userId = req.body.user_id; |
39
|
|
|
const limit = parseInt(req.params.limit); |
40
|
|
|
const offset = parseInt(req.params.offset); |
41
|
|
|
|
42
|
|
|
const trips = await tripModel.userTripsPag(userId, offset, limit); |
43
|
|
|
|
44
|
|
|
res.status(200).json(trips); |
45
|
|
|
} catch (error) { |
46
|
|
|
next(error); |
47
|
|
|
} |
48
|
|
|
}); |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @description Route for trips all trips in system |
52
|
|
|
* |
53
|
|
|
* @param {express.Request} req Request object |
54
|
|
|
* @param {express.Response} res Response object |
55
|
|
|
* @param {express.NextFunction} next Next function |
56
|
|
|
* |
57
|
|
|
* @returns {void} |
58
|
|
|
*/ |
59
|
|
|
router.get("/all", async (req, res, next) => { |
60
|
|
|
// code here for getting trips for one user |
61
|
|
|
// Båda admin och användare använder den här routen |
62
|
|
|
// user_id finns antingen i token eller body (admin) |
63
|
|
|
}); |
64
|
|
|
|
65
|
|
|
export default router; |
66
|
|
|
|