<commit_before>const express = require('express');
const Course = require('../models/coursemodel');

module.exports = function(app) {
  let processResultWith = (req, res) => {
    return (err, data) => {
      if (err) {
        res.send(err);
      } else {
        res.json(data);
      }
    };
  };

  app.get('/api/courses/', function(req, res) {
    let query = req.query;
    let page = Number(query.page) || 1;

    // TODO refactor to Promises
    Course.count((err, count) => {
      if (err) {
        res.json(err);
        return;
      }

      Course.find((err, courses) => {
              if (err) {
                res.json(err);
                return;
              }

              res.json({
                count: count,
                courses: courses
              });
            })
            .limit(10)
            .skip((page - 1) * 10)
            .sort({"card.title": 1});
    });
  });

  app.post('/api/courses/', function(req, res) {
    let course = new Course(req.body);
    course.save(processResultWith(req, res));
  });

  app.get('/api/courses/:id', function(req, res) {
    Course
    .findOne({_id: req.params.id}, processResultWith(req, res));
  });

  app.put('/api/courses/:id', function(req, res) {
    Course
    .findOneAndUpdate({_id: req.params.id},
      // update data
      {
        card: req.body
      },
      processResultWith(req, res)
    );

  });
};
<commit_msg>Fix create course API<commit_after>const express = require('express');
const Course = require('../models/coursemodel');

module.exports = function(app) {
  let processResultWith = (req, res) => {
    return (err, data) => {
      if (err) {
        res.send(err);
      } else {
        res.json(data);
      }
    };
  };

  app.get('/api/courses/', function(req, res) {
    let query = req.query;
    let page = Number(query.page) || 1;

    // TODO refactor to Promises
    Course.count((err, count) => {
      if (err) {
        res.json(err);
        return;
      }

      Course.find((err, courses) => {
              if (err) {
                res.json(err);
                return;
              }

              res.json({
                count: count,
                courses: courses
              });
            })
            .limit(10)
            .skip((page - 1) * 10)
            .sort({"card.title": 1});
    });
  });

  app.post('/api/courses/', function(req, res) {
    let course = new Course({
      card: req.body
    });

    course.save(processResultWith(req, res));
  });

  app.get('/api/courses/:id', function(req, res) {
    Course
    .findOne({_id: req.params.id}, processResultWith(req, res));
  });

  app.put('/api/courses/:id', function(req, res) {
    Course
    .findOneAndUpdate({_id: req.params.id},
      // update data
      {
        card: req.body
      },
      processResultWith(req, res)
    );

  });
};

{'fraction_non_alphanumeric': 0.17054532823897187, 'fraction_numerical': 0.004862799583188607, 'mean_word_length': 1.6568265682656826, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, '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': '5748521', 'n_tokens_mistral': 951, 'n_tokens_neox': 919, 'n_words': 177}