Total Complexity | 7 |
Complexity/F | 1.4 |
Lines of Code | 55 |
Function Count | 5 |
Duplicated Lines | 0 |
Ratio | 0 % |
Coverage | 92.31% |
Changes | 0 |
1 | 1 | const db = require("../db/database.js"); |
|
2 | |||
3 | 1 | module.exports = (function () { |
|
4 | function getDeliveries(res, apiKey) { |
||
5 | 2 | const sql = "SELECT deliveryId as id, productId as product_id, amount," + |
|
6 | " deliveryDate as delivery_date, comment" + |
||
7 | " FROM deliveries WHERE apiKey = ?"; |
||
8 | |||
9 | 2 | db.all(sql, apiKey, (err, rows) => { |
|
10 | 2 | if (err) { |
|
11 | return res.status(500).json({ |
||
12 | errors: { |
||
13 | status: 500, |
||
14 | source: "/deliveries", |
||
15 | title: "Database error", |
||
16 | detail: err.message |
||
17 | } |
||
18 | }); |
||
19 | } else { |
||
|
|||
20 | 2 | res.json({ data: rows }); |
|
21 | } |
||
22 | }); |
||
23 | } |
||
24 | |||
25 | function addDelivery(res, body) { |
||
26 | 6 | const sql = "INSERT INTO deliveries (deliveryId, productId, amount, deliveryDate," + |
|
27 | " comment, apiKey) VALUES (?, ?, ?, ?, ?, ?)"; |
||
28 | |||
29 | 6 | db.run(sql, |
|
30 | body.id, |
||
31 | body.product_id, |
||
32 | body.amount, |
||
33 | body.delivery_date, |
||
34 | body.comment, |
||
35 | body.api_key, (err) => { |
||
36 | 6 | if (err) { |
|
37 | 5 | return res.status(500).json({ |
|
38 | errors: { |
||
39 | status: 500, |
||
40 | source: "/delivery", |
||
41 | title: "Database error", |
||
42 | detail: err.message |
||
43 | } |
||
44 | }); |
||
45 | } else { |
||
46 | 1 | res.status(201).json({ data: body }); |
|
47 | } |
||
48 | }); |
||
49 | } |
||
50 | |||
51 | 1 | return { |
|
52 | getDeliveries: getDeliveries, |
||
53 | addDelivery: addDelivery, |
||
54 | }; |
||
55 | }()); |
||
56 |