     db.remove params.id, @doc.rev, (err, res) ->
         if err
             # oops unexpected error !
-            console.log "[Delete] err: #{err}"
+            console.log "[DeleteAccount] err: #{err}"
         else
             # Doc is removed from indexation
             client.del "index/#{params.id}/", (err, res, resbody) ->

# helpers
encryptPassword = (callback)->
    if @body.password
        console.log app.crypto.masterKey
        console.log app.crypto.slaveKey
        slaveKey = crypto.decrypt app.crypto.masterKey, app.crypto.slaveKey
        newPwd = crypto.encrypt slaveKey, @body.password
        @body.password = newPwd
        @body.docType = "Account"
        callback true
    else
        callback false


#PUT /account/:id
action 'updateAccount', ->
    @body = body
    encryptPassword (pwdExist, err) ->
        if err
            console.log "[updateAccount] err: #{err}"
            send 500
        else
            if pwdExist
                db.save params.id, @body, (err, res) ->
                    if err
                        # oops unexpected error !
                        console.log "[Update] err: #{err}"
                        send 500
                    else
                        send 200
            else
                send 401


#PUT /account/merge/:id
action 'mergeAccount', ->
    @body = body
    encryptPassword (pwdExist, err) ->
        if err
            console.log "[mergeAccount] err: #{err}"
            send 500
        else
            db.merge params.id, @body, (err, res) ->
                if err
                    # oops unexpected error !
                    console.log "[Merge] err: #{err}"
                    send 500
                else
                    send 200


#PUT /account/upsert/:id
action 'upsertAccount', ->
    @body = body
    encryptPassword (pwdExist, err) ->
        if pwdExist and not err
            db.get params.id, (err, doc) ->
                db.save params.id, body, (err, res) ->
                    if err
