Code Duplication    Length = 25-25 lines in 2 locations

v1/models/auth.js 1 location

@@ 20-44 (lines=25) @@
17
18
module.exports = (function () {
19
    function isValidAPIKey(apiKey, next, path, res) {
20
        db.get("SELECT email FROM apikeys WHERE key = ?", apiKey, (err, row) => {
21
            if (err) {
22
                return res.status(500).json({
23
                    errors: {
24
                        status: 500,
25
                        source: path,
26
                        title: "Database error",
27
                        detail: err.message
28
                    }
29
                });
30
            }
31
32
            if (row !== undefined) {
33
                return next();
34
            }
35
36
            res.status(401).json({
37
                errors: {
38
                    status: 401,
39
                    source: path,
40
                    title: "Valid API key",
41
                    detail: "No valid API key provided."
42
                }
43
            });
44
        });
45
    }
46
47
    function getNewAPIKey(res, path, email) {

v2/models/auth.js 1 location

@@ 44-68 (lines=25) @@
41
    },
42
43
    isValidAPIKey: function(apiKey, next, path, res) {
44
        db.get("SELECT email FROM apikeys WHERE key = ?", apiKey, (err, row) => {
45
            if (err) {
46
                return res.status(500).json({
47
                    errors: {
48
                        status: 500,
49
                        source: path,
50
                        title: "Database error",
51
                        detail: err.message
52
                    }
53
                });
54
            }
55
56
            if (row !== undefined) {
57
                return next();
58
            }
59
60
            return res.status(401).json({
61
                errors: {
62
                    status: 401,
63
                    source: path,
64
                    title: "Valid API key",
65
                    detail: "No valid API key provided."
66
                }
67
            });
68
        });
69
    },
70
71
    getNewAPIKey: function(res, email) {