<commit_before>import { normalize } from 'normalizr';

import sectorSchema from '_utils/sectorSchema';
import { LIST_SECTORES, GET_SECTOR, DELETE_SECTOR } from '_store/sectores/constants';

let collection;

export function init(db) {
  collection = db.collection('sectores');
  return Promise.resolve();
}

export function listSectores() {
  return collection.find({}, { idSector: 1, descrCorta: 1, descr: 1, _id: 0 }).toArray();
}

export function getSector({ idSector }) {
  return collection
    .find({ _id: idSector })
    .next()
    .then(response => normalize(response, sectorSchema));
}

export function deleteSectores({ idSectores }) {
  return collection.deleteMany({ idSector: { $in: idSectores } });
}

export default db =>
  init(db).then(() => ({
    [LIST_SECTORES]: listSectores,
    [GET_SECTOR]: getSector,
    [DELETE_SECTOR]: deleteSectores,
  }));<commit_msg>works both via rest and webSockets<commit_after>import { LIST_SECTORES, GET_SECTOR, DELETE_SECTOR, ADD_SECTOR } from '_store/sectores/constants';

import * as sectores from '../dbOperations/sectores';

export function listSectores() {
  return sectores.listSectores();
}

export function getSector({ idSector }) {
  return sectores.getSector(idSector);
}

export function deleteSectores({ idSectores }) {
  return sectores.deleteSectores(idSectores);
}

export function addSector(sector) {
  return sectores.addSector(sector);
}

export default db =>
  sectores.init(db).then(() => ({
    [LIST_SECTORES]: listSectores,
    [GET_SECTOR]: getSector,
    [DELETE_SECTOR]: deleteSectores,
    [ADD_SECTOR]: addSector,
  }));
{'fraction_non_alphanumeric': 0.13670411985018727, 'fraction_numerical': 0.0024968789013732834, 'mean_word_length': 5.071969696969697, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '2474254', 'n_tokens_mistral': 550, 'n_tokens_neox': 540, 'n_words': 120}