<commit_before>import { Router } from 'express';
import Connection from './Connection';

const route = Router();

route.get('/', (req, resp) => {
    Connection.pool.query(
        'SELECT setting,value FROM settings WHERE user_id=?;',
        [req.session.userData.user_id],
        (err, results) => {
            if (err) {
                resp.status(500).send(err);
            } else {
                resp.send(results.reduce((a, b) => {
                    // Convert array of {key:x,value:y} to a single object {x:y}...
                    const x = {};
                    x[b.setting] = b.value;
                    return Object.assign(x, a);
                }, {}));
            }
        }
    );
});

route.post("/", (req, resp) => {
    const setting = req.body;
    Connection.pool.query(
        'REPLACE INTO settings (user_id, setting, value) VALUES (?,?,?);',
        [req.session.userData.user_id, setting.key, setting.setting],
        err => {
            if (err) {
                resp.status(500).send(err);
            } else {
                resp.sendStatus(201);
            }
        });<commit_msg>#85 Fixed setting<commit_after>import { Router } from 'express';
import Connection from './Connection';

const route = Router();

route.get('/', (req, resp) => {
    Connection.pool.query(
        'SELECT setting,value FROM settings WHERE user_id=?;',
        [req.session.userData.user_id],
        (err, results) => {
            if (err) {
                resp.status(500).send(err);
            } else {
                resp.send(results.reduce((a, b) => {
                    // Convert array of {key:x,value:y} to a single object {x:y}...
                    const x = {};
                    x[b.setting] = b.value;
                    return Object.assign(x, a);
                }, {}));
            }
        }
    );
});

route.post("/", (req, resp) => {
    const setting = req.body;
    Connection.pool.query(
        'REPLACE INTO settings (user_id, setting, value) VALUES (?,?,?);',
        [req.session.userData.user_id, setting.key, setting.value],
        err => {
            if (err) {
                resp.status(500).send(err);
            } else {
                resp.sendStatus(201);
            }
        });
{'fraction_non_alphanumeric': 0.1603356890459364, 'fraction_numerical': 0.0088339222614841, 'mean_word_length': 1.5083056478405317, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4844255', 'n_tokens_mistral': 690, 'n_tokens_neox': 657, 'n_words': 140}