Code Duplication    Length = 35-35 lines in 2 locations

v1/models/users.js 2 locations

@@ 178-212 (lines=35) @@
175
        res.status(200).send({ user }); // Sends data from the specific user
176
    },
177
178
    getSpecificGoogleUser: async function(res, google_id, path) {
179
        let googleId = sanitize(google_id);
180
        let user = null;
181
182
        // Check if the scooterId are valid MongoDB id.
183
        if (!ObjectId.isValid(userId)) {
184
            return res.status(400).json({
185
                errors: {
186
                    status: 400,
187
                    detail: "The user_id is not a valid id."
188
                }
189
            });
190
        }
191
192
        let client = new MongoClient(mongoURI);
193
        try {
194
            let db = client.db("spark-rentals");
195
            let users_collection = db.collection("users");
196
            user = await users_collection.findOne({googleId: ObjectId(googleId)});
197
        } catch(e) { return res.status(500).send(); } finally { await client.close(); }
198
199
        // If nothing in users db collection
200
        if (user === null || !Object.keys(user).length) {
201
            return res.status(401).json({
202
                errors: {
203
                    status: 401,
204
                    source: "GET /users" + path,
205
                    title: "User not exists in database",
206
                    detail: "The User dosen't exists in database with the specified user_id."
207
                }
208
            });
209
        }
210
211
        res.status(200).send({ user }); // Sends data from the specific user
212
    },
213
214
    getUserHistory: async function(res, user_id, path) {
215
        let userId = sanitize(user_id);
@@ 142-176 (lines=35) @@
139
        return res.status(204).send(); // Everything went good
140
    },
141
142
    getSpecificUser: async function(res, user_id, path) {
143
        let userId = sanitize(user_id);
144
        let user = null;
145
146
        // Check if the scooterId are valid MongoDB id.
147
        if (!ObjectId.isValid(userId)) {
148
            return res.status(400).json({
149
                errors: {
150
                    status: 400,
151
                    detail: "The user_id is not a valid id."
152
                }
153
            });
154
        }
155
156
        let client = new MongoClient(mongoURI);
157
        try {
158
            let db = client.db("spark-rentals");
159
            let users_collection = db.collection("users");
160
            user = await users_collection.findOne({_id: ObjectId(userId)});
161
        } catch(e) { return res.status(500).send(); } finally { await client.close(); }
162
163
        // If nothing in users db collection
164
        if (user === null || !Object.keys(user).length) {
165
            return res.status(401).json({
166
                errors: {
167
                    status: 401,
168
                    source: "GET /users" + path,
169
                    title: "User not exists in database",
170
                    detail: "The User dosen't exists in database with the specified user_id."
171
                }
172
            });
173
        }
174
175
        res.status(200).send({ user }); // Sends data from the specific user
176
    },
177
178
    getSpecificGoogleUser: async function(res, google_id, path) {
179
        let googleId = sanitize(google_id);