Code Duplication    Length = 34-34 lines in 2 locations

v1/models/auth.js 1 location

@@ 220-253 (lines=34) @@
217
            });
218
        }
219
220
        bcrypt.hash(password, 10, function(err, hash) {
221
            if (err) {
222
                return res.status(500).json({
223
                    errors: {
224
                        status: 500,
225
                        source: "/register",
226
                        title: "bcrypt error",
227
                        detail: "bcrypt error"
228
                    }
229
                });
230
            }
231
232
            db.run("INSERT INTO users (apiKey, email, password) VALUES (?, ?, ?)",
233
                apiKey,
234
                email,
235
                hash, (err) => {
236
                    if (err) {
237
                        return res.status(500).json({
238
                            errors: {
239
                                status: 500,
240
                                source: "/register",
241
                                title: "Database error",
242
                                detail: err.message
243
                            }
244
                        });
245
                    }
246
247
                    res.status(201).json({
248
                        data: {
249
                            message: "User successfully registered."
250
                        }
251
                    });
252
                });
253
        });
254
    }
255
256
    function checkToken(req, res, next) {

v2/models/auth.js 1 location

@@ 357-390 (lines=34) @@
354
            });
355
        }
356
357
        bcrypt.hash(password, 10, function(err, hash) {
358
            if (err) {
359
                return res.status(500).json({
360
                    errors: {
361
                        status: 500,
362
                        source: "/register",
363
                        title: "bcrypt error",
364
                        detail: "bcrypt error"
365
                    }
366
                });
367
            }
368
369
            db.run("INSERT INTO users (apiKey, email, password) VALUES (?, ?, ?)",
370
                apiKey,
371
                email,
372
                hash, (err) => {
373
                    if (err) {
374
                        return res.status(500).json({
375
                            errors: {
376
                                status: 500,
377
                                source: "/register",
378
                                title: "Database error",
379
                                detail: err.message
380
                            }
381
                        });
382
                    }
383
384
                    return res.status(201).json({
385
                        data: {
386
                            message: "User successfully registered."
387
                        }
388
                    });
389
                });
390
        });
391
    },
392
393
    checkToken: function(req, res, next) {