<commit_before>db = require('../helpers/db_connect_helper').db_connect()
keys = require '../lib/encryption'

# POST /user/
module.exports.create = (req, res, next) ->
    delete req.body._attachments
    if req.params.id
        db.get req.params.id, (err, doc) -> # this GET needed because of cache
            if doc
                err = new Error "The document exists"
                err.status = 409
                next err
            else
                db.save req.params.id, req.body, (err, response) ->
                    if err
                        err = new Error "The document exists"
                        err.status = 409
                        next err
                    else
                        res.send 201, _id: response.id
    else
        db.save req.body, (err, response) ->
            if err
                console.log "[Create] err: " + JSON.stringify err
                console.log err.error
                next new Error err.error
            else
                res.send 201, _id: response.id

# PUT /user/merge/:id
module.exports.merge = (req, res, next) ->
    # this version don't take care of conflict (erase DB with the sent value)
    delete body._attachments
    db.merge req.params.id, req.body, (err, response) ->
        if err
            # oops unexpected error !
            console.log "[Merge] err: " + JSON.stringify err
            next new Error err.error
        else
            res.send 200, success: true
            next()<commit_msg>Fixed: typo in variable name<commit_after>db = require('../helpers/db_connect_helper').db_connect()
keys = require '../lib/encryption'

# POST /user/
module.exports.create = (req, res, next) ->
    delete req.body?._attachments
    if req.params.id
        db.get req.params.id, (err, doc) -> # this GET needed because of cache
            if doc
                err = new Error "The document exists"
                err.status = 409
                next err
            else
                db.save req.params.id, req.body, (err, response) ->
                    if err
                        err = new Error "The document exists"
                        err.status = 409
                        next err
                    else
                        res.send 201, _id: response.id
    else
        db.save req.body, (err, response) ->
            if err
                console.log "[Create] err: " + JSON.stringify err
                console.log err.error
                next new Error err.error
            else
                res.send 201, _id: response.id

# PUT /user/merge/:id
module.exports.merge = (req, res, next) ->
    # this version don't take care of conflict (erase DB with the sent value)
    delete req.body?._attachments
    db.merge req.params.id, req.body, (err, response) ->
        if err
            # oops unexpected error !
            console.log "[Merge] err: " + JSON.stringify err
            next new Error err.error
        else
            res.send 200, success: true
            next()
{'fraction_non_alphanumeric': 0.09501814582645991, 'fraction_numerical': 0.009897723523589575, 'mean_word_length': 1.3613707165109035, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '3492933', 'n_tokens_mistral': 845, 'n_tokens_neox': 788, 'n_words': 261}