Passed
Push — main ( 849115...44fe89 )
by Julia
05:25 queued 03:07
created

server/routes/v1/user/trips.js   A

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 36
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 7
mnd 0
bc 0
fnc 2
dl 0
loc 36
rs 10
bpm 0
cpm 1
noi 6
c 0
b 0
f 0
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
export default router;
51