Code Duplication    Length = 41-41 lines in 2 locations

v1/models/orders.js 1 location

@@ 242-282 (lines=41) @@
239
    }
240
241
    function deleteOrder(res, body) {
242
        if (Number.isInteger(parseInt(body.id))) {
243
            db.run("DELETE FROM orders WHERE apiKey = ? AND orderId = ?",
244
                body.api_key,
245
                body.id, (err) => {
246
                    if (err) {
247
                        return res.status(500).json({
248
                            errors: {
249
                                status: 500,
250
                                source: "DELETE /order",
251
                                title: "Database error",
252
                                detail: err.message
253
                            }
254
                        });
255
                    } else {
256
                        db.run("DELETE FROM order_items WHERE apiKey = ? AND orderId = ?",
257
                            body.api_key,
258
                            body.id, (err) => {
259
                                if (err) {
260
                                    return res.status(500).json({
261
                                        errors: {
262
                                            status: 500,
263
                                            source: "DELETE /order order_items",
264
                                            title: "Database error",
265
                                            detail: err.message
266
                                        }
267
                                    });
268
                                } else {
269
                                    res.status(204).send();
270
                                }
271
                            });
272
                    }
273
                });
274
        } else {
275
            res.status(400).json({
276
                errors: {
277
                    status: 400,
278
                    detail: "Required attribute order id (id) " +
279
                        " was not included in the request."
280
                }
281
            });
282
        }
283
    }
284
285
    return {

v2/models/orders.js 1 location

@@ 235-275 (lines=41) @@
232
    },
233
234
    deleteOrder: function(res, body) {
235
        if (Number.isInteger(parseInt(body.id))) {
236
            db.run("DELETE FROM orders WHERE apiKey = ? AND ROWID = ?",
237
                body.api_key,
238
                body.id, (err) => {
239
                    if (err) {
240
                        return res.status(500).json({
241
                            errors: {
242
                                status: 500,
243
                                source: "DELETE /order",
244
                                title: "Database error",
245
                                detail: err.message
246
                            }
247
                        });
248
                    }
249
250
                    db.run("DELETE FROM order_items WHERE apiKey = ? AND orderId = ?",
251
                        body.api_key,
252
                        body.id, (err) => {
253
                            if (err) {
254
                                return res.status(500).json({
255
                                    errors: {
256
                                        status: 500,
257
                                        source: "DELETE /order order_items",
258
                                        title: "Database error",
259
                                        detail: err.message
260
                                    }
261
                                });
262
                            }
263
264
                            return res.status(204).send();
265
                        });
266
                });
267
        } else {
268
            return res.status(400).json({
269
                errors: {
270
                    status: 400,
271
                    detail: "Required attribute order id (id) " +
272
                        " was not included in the request."
273
                }
274
            });
275
        }
276
    }
277
};
278