How to pass the variable _id to the path of the url to consume an update service?

1

I have a problem trying to update a record to my database from a web page, I'm using mongodb and a microservice in Nodejs, the problem is that on the web page when sending the _id for the form it does not reach the path of the url so you can not make the put, and I do not know how to get the id to the factory, for the delete I pass it by path also in the following way:
localhost: 8765 / nodejs / transaction /: transaction /: _ id.
And this way it works but in the update it gives me an error saying that the value of _id can not be read.
I share my code so that they can help me in that I am failing:

This is the driver part:

app.controller('TransaccionUpdateController',

['$scope', 'TransaccionUpdateResource',

    function ($scope, TransaccionUpdateResource) {

        $scope.updatetransaccion = {
            _id: null,
            id: null,
            fecha: null,
            cantidad1: null,
            cantidad2: null
        };

        var location
        $scope.actu = function () {
            console.log("Transaccion:"+JSON.stringify($scope.updatetransaccion));
            console.log("_id:" +$scope.transaccion._id);

            var successCallback = function (response) {
                console.log("result persona update:" + JSON.stringify(response));

            };
            var errorCallback = function (response) {
                console.log("error transaction update:" + JSON.stringify(response));
            };

            TransaccionUpdateResource.update($scope.updatetransaccion, successCallback, errorCallback);
        };

    }]);

This is the model part (factory):

app.factory('TransaccionUpdateResource',

function ($resource) {

    var baseURL = "http://localhost:8765/nodejs/";

    var resource = $resource(baseURL,

        {},
    {
            update: {
                url: baseURL + 'transaction/:updatetransaccion/:_id',
                method: 'PUT',
                isArray: false,
                transformResponse: function (data) {

                    var itemsConverted = null;
                    var redirect = false;

                   try {
                        itemsConverted = angular.fromJson(data)
                    } catch (e) {
                        if (typeof data === 'string') {
                            if (data.indexOf instanceof Function) {
                                if (data.indexOf('<div class="login-form">') !== -1) {
                                    redirect = true;
                                }
                            }
                        } else {
                            itemsCoverted = null;
                        }
                    }

                   var result = {
                        items: itemsConverted,
                        redirectToLogin: redirect
                    };


                    console.log("parse:" + JSON.stringify(result));
                    return result;
                }

            }
        });

    return resource;
});

And this is the part of the view, in which the first input is where the _id happened that should reach the path of the url:

<div class="wrapper-md"
 ng-controller="TransaccionUpdateController">
<div class="panel panel-default">
    <div class="panel-heading">
        Update transacciones
    </div>

    <div class="panel-body">
        <div class="row">
            <div class="col-md-12">

                <form name="festud" class="form-horizontal">
                    <div class="form-group">
                        <div class="col-lg-1">
                            <label class="col-lg-1 control-label">_ID a Actualizar</label>
                        </div>
                        <div class="col-lg-10">
                            <input type="text" class="form-control" placeholder="_ID"
                                   ng-model="updatetransaccion._id" >
                        </div>
                    </div>


                    <div class="form-group">
                        <div class="col-lg-1">
                            <label class="col-lg-1 control-label">Id</label>
                        </div>
                        <div class="col-lg-10">
                            <input type="text" class="form-control" placeholder="Id"
                                   ng-model="updatetransaccion.id" >
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-lg-1">
                            <label class="col-lg-1 control-label">fecha</label>
                        </div>
                        <div class="col-lg-10">
                            <input type="date" class="form-control" placeholder="Fecha"
                                   ng-model="updatetransaccion.fecha" >
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-lg-1">
                            <label class="col-lg-1 control-label">Producto1</label>
                        </div>
                        <div class="col-lg-10">
                            <input type="text" class="form-control" placeholder="Cantidad"
                                   ng-model="updatetransaccion.cantidad1" >
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-lg-1">
                            <label class="col-lg-1 control-label">Producto2</label>
                        </div>
                        <div class="col-lg-10">
                            <input type="text" class="form-control" placeholder="Cantidad"
                                   ng-model="updatetransaccion.cantidad2" >
                        </div>
                    </div>
                     <div class="row">
                        <div class="col-md-12">
                            <div class="form-group">
                                <div class="col-lg-12">
                                    <button type="submit" class="btn btn-success pull-right"
                                            ng-click="actu()">

                                        Actualizar
                                    </button>

                                </div>
                            </div>
                        </div>
                    </div>
    
asked by pablo rustrian 10.11.2017 в 09:36
source

0 answers