<commit_before>const express = require('express');
const router = express.Router();

const mongoose = require('mongoose');
const Couple = require('../models/couple');
const User = require('../models/user');

const Promise = require('bluebird');
const jwt = require('jsonwebtoken');
const jwtConfig = require('../jwt_config');

const jwtVerifyAsync = Promise.promisify(jwt.verify, { context: jwt });

const NO_COUPLE_ERROR = 'no couple';
const NOT_IN_COUPLE_ERROR = 'not in couple';

function isJwtError(err) {
  return err.name && err.name == 'JsonWebTokenError';
}

router.post('/create', (req, res) => {
  const decodedToken = isValidToken(req.headers.authorization);
  if (!decodedToken) {
    res.status(401).send();
    return;
  }

  const coupleName = req.body.name;
  if (!coupleName) {
    res.status(400).send();
    return;
  }

  // if it was a valid token, it's a valid user
  Couple.create({ name: coupleName, users: [decodedToken.userId] })
    .then(couple => {
      return User.findByIdAndUpdate(decodedToken.userId, {
        couple: couple._id
      });
    })
    .then(() => {
      res.status(200).send();
    })
    .catch(e => {
      console.error(e);
      res.status(400).send();
    });
});

router.post('/:id', (req, res) => {
  const token = req.headers.authorization;
  jwtVerifyAsync(token, jwtConfig.key)
    .then(decodedToken => {
      const coupleId = req.params.id;

      if (coupleId != decodedToken.coupleId) {
        throw new Error(NOT_IN_COUPLE_ERROR);
      }

      return Couple.findOne({ _id: coupleId })
        .populate('users')
        .then(couple => {
          if (!couple) {
            throw new Error(NO_COUPLE_ERROR);
          }
          const thisUserIndex = couple.users.findIndex(
            user => user.id == decodedToken.userId
          );
          const thisUser = couple.users[thisUserIndex];
          const otherUser = couple.users[(thisUserIndex + 1) % 2];

          res.json({
            id: couple._id,
            thisUser: {
              id: thisUser._id,
              username: thisUser.username,
              color: thisUser.color
            },<commit_msg>Fixed GET couple actually being POST<commit_after>const express = require('express');
const router = express.Router();

const mongoose = require('mongoose');
const Couple = require('../models/couple');
const User = require('../models/user');

const Promise = require('bluebird');
const jwt = require('jsonwebtoken');
const jwtConfig = require('../jwt_config');

const jwtVerifyAsync = Promise.promisify(jwt.verify, { context: jwt });

const NO_COUPLE_ERROR = 'no couple';
const NOT_IN_COUPLE_ERROR = 'not in couple';

function isJwtError(err) {
  return err.name && err.name == 'JsonWebTokenError';
}

router.post('/create', (req, res) => {
  const decodedToken = isValidToken(req.headers.authorization);
  if (!decodedToken) {
    res.status(401).send();
    return;
  }

  const coupleName = req.body.name;
  if (!coupleName) {
    res.status(400).send();
    return;
  }

  // if it was a valid token, it's a valid user
  Couple.create({ name: coupleName, users: [decodedToken.userId] })
    .then(couple => {
      return User.findByIdAndUpdate(decodedToken.userId, {
        couple: couple._id
      });
    })
    .then(() => {
      res.status(200).send();
    })
    .catch(e => {
      console.error(e);
      res.status(400).send();
    });
});

router.get('/:id', (req, res) => {
  const token = req.headers.authorization;
  jwtVerifyAsync(token, jwtConfig.key)
    .then(decodedToken => {
      const coupleId = req.params.id;

      if (coupleId != decodedToken.coupleId) {
        throw new Error(NOT_IN_COUPLE_ERROR);
      }

      return Couple.findOne({ _id: coupleId })
        .populate('users')
        .then(couple => {
          if (!couple) {
            throw new Error(NO_COUPLE_ERROR);
          }
          const thisUserIndex = couple.users.findIndex(
            user => user.id == decodedToken.userId
          );
          const thisUser = couple.users[thisUserIndex];
          const otherUser = couple.users[(thisUserIndex + 1) % 2];

          res.status(200).json({
            id: couple._id,
            thisUser: {
              id: thisUser._id,
              username: thisUser.username,
              color: thisUser.color
            },
{'fraction_non_alphanumeric': 0.14777983348751156, 'fraction_numerical': 0.007169287696577244, 'mean_word_length': 2.577336641852771, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '940314', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1371, 'n_words': 283}