<commit_before>'use strict';

const express = require("express");
const fs = require("fs");
const port = 3000;
const bodyParser = require("body-parser")
const app = express();

app.use(bodyParser.json());

function loadTodos(callback) {
  return fs.readFile("./todos.json", (err, data) => {
    if (err) throw err;
    callback(JSON.parse(data))
  });
}

app.route("/todos")
.get((req, res) => {
  loadTodos((json) => {
    res.json(json.data);
  });
})
.post((req, res) => {
  let newTodo = req.body;
  newTodo.completed = false;
  console.log(newTodo);
  loadTodos((json) =>{
    json.data.push(newTodo);
    json.lastId++;
    newTodo.id = json.lastId;
    fs.writeFile("./todos.json", JSON.stringify(json, null, " "), (err) => {
      if (err) throw err;
      res.status(200).end();
    });
  });
});

app.route("/todos/:id")
.get((req, res) => {
  const id = parseInt(req.params.id);
  loadTodos((json) => {
    const todos = json.data;
    for (const t in todos) {
      const todo = todos[t];
      if (todo.id === id){
        return res.json(todo)
      }
    }
    return res.send("Nah todas found");
  });
})
.put((req, res) => {
  const id = parseInt(req.params.id);
  loadTodos((json) => {
    const todos = json.data;
    for(const i = 0; i < todos.length; i++){
      if (i === id){
        todos[i].completed = req.body.completed;
        todos[i].text = req.body.text;
      }
    }
    fs.writeFile("./todos.json", JSON.stringify(json), (err) => {
      if (err) throw err;
      res.status(200).end();
    });
  });
})
.delete((req, res) => {
  const id = parseInt(req.params.id);
  loadTodos((json) => {
    const todos = json.data;
    var hunted = todos.filter((check) =>{
      return check.id != id;<commit_msg>changed const to let in for<commit_after>'use strict';

const express = require("express");
const fs = require("fs");
const port = 3000;
const bodyParser = require("body-parser")
const app = express();

app.use(bodyParser.json());

function loadTodos(callback) {
  return fs.readFile("./todos.json", (err, data) => {
    if (err) throw err;
    callback(JSON.parse(data))
  });
}

app.route("/todos")
.get((req, res) => {
  loadTodos((json) => {
    res.json(json.data);
  });
})
.post((req, res) => {
  let newTodo = req.body;
  newTodo.completed = false;
  console.log(newTodo);
  loadTodos((json) =>{
    json.data.push(newTodo);
    json.lastId++;
    newTodo.id = json.lastId;
    fs.writeFile("./todos.json", JSON.stringify(json, null, " "), (err) => {
      if (err) throw err;
      res.status(200).end();
    });
  });
});

app.route("/todos/:id")
.get((req, res) => {
  const id = parseInt(req.params.id);
  loadTodos((json) => {
    const todos = json.data;
    for (const t in todos) {
      const todo = todos[t];
      if (todo.id === id){
        return res.json(todo)
      }
    }
    return res.send("Nah todas found");
  });
})
.put((req, res) => {
  const id = parseInt(req.params.id);
  loadTodos((json) => {
    const todos = json.data;
    for(let i = 0; i < todos.length; i++){
      if (i === id){
        todos[i].completed = req.body.completed;
        todos[i].text = req.body.text;
      }
    }
    fs.writeFile("./todos.json", JSON.stringify(json), (err) => {
      if (err) throw err;
      res.status(200).end();
    });
  });
})
.delete((req, res) => {
  const id = parseInt(req.params.id);
  loadTodos((json) => {
    const todos = json.data;
    var hunted = todos.filter((check) =>{
      return check.id != id;
{'fraction_non_alphanumeric': 0.2060849598163031, 'fraction_numerical': 0.006314580941446613, 'mean_word_length': 2.779826464208243, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3916933', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1306, 'n_words': 260}