<commit_before>var express = require('express');
var router = express.Router();
var admin = require("firebase-admin");

router.post('/', function(req, res, next) {
  const id = req.session.userId; // Todo: Should be "req.session.userId" after naver login complete
  admin.database().ref('users').orderByChild('id').equalTo(id).once('value')
    .then((user) => {
      if (user.val() === null) {
        throw new Error("No matching user");
      }
      const key = Object.keys(user.val());
      const newRef = admin.database().ref('transactions').push();
      const newKey = newRef.key;
      const transactionObj = {
        id: newKey,
        userId: key[0],
        seller: req.body.seller,
        value: req.body.value,
        regDate: Date.now()
      };
      return newRef.set(transactionObj)
    })
    .then(() => {
      res.status(200).json({ message: "success adding transaction info"});
    })
    .catch((err) => {
      res.status(400).json({ err_msg: err.message });
    });
});

router.get('/:period', function(req, res, next) {
  const id = "-KqCstYTIIxeecYJa8-n"; // Todo: Should be "req.session.userId" after naver login complete
  const now = Date.now();
  const defaultFrom = now - (7*24*60*60);
  const period = req.params.period || defaultFrom + ":" + now;
  const from = period.split(':')[0];
  const to = period.split(':')[1];
  admin.database().ref('transactions').orderByChild('userId').equalTo(id).once('value')
    .then((transactions) => {
      return transactions.val()
        .orderByChild('regDate')
        .startAt(from).endAt(to).once('value');
    })
    .then(() => {
      res.status(200).json(transactions);
    })
    .catch((err) => {
      res.status(400).json({ err_msg: err.message });
    });
});

router.post('/update', function(req, res, next) {
  const tid = req.body.id;
  admin.database().ref('transactions').orderByChild('id').equalTo(tid).once('value')
    .then((transaction) => {
      if (transaction.val() === null) {
        throw new Error("No matching transaction");
      }
      const vals = Object.keys(transaction.val())
        .map((key) => transaction.val()[key]);
      return vals[0];
    })
    .then((val) => {
      const transactionObj = {
        id: tid,
        userId: val.userId,
        seller: val.seller,
        value: val.value,
        regDate: val.regDate,
        image: req.body.image,
        keyword: req.body.keyword
      };
      return admin.database().ref('transactions').child(tid).set(transactionObj)
    })
    .then(() => {
      res.status(200).json({ message: "success updating transaction info"});
    })
    .catch((err) => {
      res.status(400).json({ err_msg: err.message });
    });
});

module.exports = router;
<commit_msg>Update transaction list<commit_after>var express = require('express');
var router = express.Router();
var admin = require("firebase-admin");

router.post('/', function(req, res, next) {
  const id = req.session.userId; // Todo: Should be "req.session.userId" after naver login complete
  admin.database().ref('users').orderByChild('id').equalTo(id).once('value')
    .then((user) => {
      if (user.val() === null) {
        throw new Error("No matching user");
      }
      const key = Object.keys(user.val());
      const newRef = admin.database().ref('transactions').push();
      const newKey = newRef.key;
      const transactionObj = {
        id: newKey,
        userId: key[0],
        seller: req.body.seller,
        value: req.body.value,
        regDate: Date.now()
      };
      return newRef.set(transactionObj)
    })
    .then(() => {
      res.status(200).json({ message: "success adding transaction info"});
    })
    .catch((err) => {
      res.status(400).json({ err_msg: err.message });
    });
});

router.get('/', function(req, res, next) {
  const id = "-KqCstYTIIxeecYJa8-n"; // Todo: Should be "req.session.userId" after naver login complete
  const now = Date.now();
  const defaultFrom = now - (7*24*60*60);
  const period = defaultFrom + ":" + now;
  const from = period.split(':')[0];
  const to = period.split(':')[1];
  admin.database().ref('transactions').orderByChild('userId').equalTo(id).once('value')
    .then((transactions) => {
      res.status(200).json(transactions);
    })
    .catch((err) => {
      res.status(400).json({ err_msg: err.message });
    });
});

router.post('/update', function(req, res, next) {
  const tid = req.body.id;
  admin.database().ref('transactions').orderByChild('id').equalTo(tid).once('value')
    .then((transaction) => {
      if (transaction.val() === null) {
        throw new Error("No matching transaction");
      }
      const vals = Object.keys(transaction.val())
        .map((key) => transaction.val()[key]);
      return vals[0];
    })
    .then((val) => {
      const transactionObj = {
        id: tid,
        userId: val.userId,
        seller: val.seller,
        value: val.value,
        regDate: val.regDate,
        image: req.body.image,
        keyword: req.body.keyword
      };
      return admin.database().ref('transactions').child(tid).set(transactionObj)
    })
    .then(() => {
      res.status(200).json({ message: "success updating transaction info"});
    })
    .catch((err) => {
      res.status(400).json({ err_msg: err.message });
    });
});

module.exports = router;

{'fraction_non_alphanumeric': 0.18881381381381382, 'fraction_numerical': 0.01126126126126126, 'mean_word_length': 2.8091493924231594, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 24, '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': '7461813', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1698, 'n_words': 334}