<commit_before>/**
  Users Controller
*/

// 3rd party modules
const _ = require('lodash');

// Own modules
const DefaultController = require('./');


class UsersController extends DefaultController {
  constructor() {
    super('User');
  }
  deleteSettings(req, res) { // eslint-disable-line class-methods-use-this
    const namespace = req.params.Namespace;
    const doc = {$unset: {}};
    doc.$unset[`settings.${namespace}`] = 1;
    req.User.update(doc)
      .catch(error => res.status(500).json({error: error.message}))
      .then((resp) => {
        if (resp.nModified === 1) {
          res.json({});
        } else {
          res.status(404).json({error: resp.message});
        }
      });
  }
  getSettings(req, res) { // eslint-disable-line class-methods-use-this
    const namespace = req.params.Namespace;
    const key = `settings.${namespace}`;
    const value = _.get(req.User, key);
    if (value) {
      const settings = _.get(req.User, key);
      res.json(settings);
    } else {
      res.status(404).json({error: `No settings for ${namespace}`});
    }
  }
  updateSettings(req, res) { // eslint-disable-line class-methods-use-this
    const namespace = req.params.Namespace;
    const doc = {};<commit_msg>empty object when get non existing user settings<commit_after>/**
  Users Controller
*/

// 3rd party modules
const _ = require('lodash');

// Own modules
const DefaultController = require('./');


class UsersController extends DefaultController {
  constructor() {
    super('User');
  }
  deleteSettings(req, res) { // eslint-disable-line class-methods-use-this
    const namespace = req.params.Namespace;
    const doc = {$unset: {}};
    doc.$unset[`settings.${namespace}`] = 1;
    req.User.update(doc)
      .catch(error => res.status(500).json({error: error.message}))
      .then((resp) => {
        if (resp.nModified === 1) {
          res.json({});
        } else {
          res.status(404).json({error: resp.message});
        }
      });
  }
  getSettings(req, res) { // eslint-disable-line class-methods-use-this
    const namespace = req.params.Namespace;
    const key = `settings.${namespace}`;
    const value = _.get(req.User, key);
    if (value) {
      const settings = _.get(req.User, key);
      res.json(settings);
    } else {
      // no settings stored under that namespace - give empty object
      res.json({});
    }
  }
  updateSettings(req, res) { // eslint-disable-line class-methods-use-this
    const namespace = req.params.Namespace;
    const doc = {};
{'fraction_non_alphanumeric': 0.16383062920459043, 'fraction_numerical': 0.008310249307479225, 'mean_word_length': 2.723122238586156, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4976683', 'n_tokens_mistral': 792, 'n_tokens_neox': 776, 'n_words': 170}