0

i have an method post on api nodejs, and a client app on angular, when i test the method post on postman this work but when i send the data from client app it doesn't work:

this is my code nodejs api:

'use strict'

var historial = require('../models/historial');

var controller={

    saveHistorial: function(req, res){
        console.log("entro")
        var Historial = new historial();

        var params = req.body;
        Historial.nombre= params.nombre;
        Historial.cantidad= params.cantidad;
        Historial.unidadMedida= params.unidadMedida;
        Historial.fecha= params.fecha;
        Historial.costo= params.costo

        Historial.save((err, HistorialStored)=>{
            if(err)return res.status(500).send({message: 'error en la peticion'});
            if(!HistorialStored) return res.status(404).send({message: 'no se ha podido guardar'});

            return res.status(200).send({Historial: HistorialStored});
        });
    },

    getHistorial: function(req, res){
        historial.find({}).exec((err, Historial)=> {
            if(err) return res.status(500).send({message: 'error al devolver los datos'});
            if(!Historial) return res.status(404).send({message:'No hay Historials'});
            return res.status(200).send({Historial});
        });
    },

};

module.exports = controller;

and this is my service on angular:

import { Injectable } from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {Observable} from 'rxjs/Observable';
import {historial} from '../models/historial';
import {Global} from './global';


@Injectable({
  providedIn: 'root'
})
export class HistorialService {
public url: string; 

  constructor(private _httpclient:HttpClient ) { 

    this.url= Global.url;
  }

  saveRegistro(_historial:historial): Observable<any>{
      let params = JSON.stringify(_historial);
      let headers = new HttpHeaders().set('Content-Type', 'application/json');
      debugger
      return this._httpclient.post(this.url + 'save-registro', params, {headers: headers});
   }


   getHistorial():Observable<any>{
      let headers = new HttpHeaders().set('Content-Type', 'application/json');

      return this._httpclient.get(this.url+'historial', {headers:headers});
   }
}

when i execute this service appear this error on the console in the server:

(node:11340) DeprecationWarning: collection.findAndModify is deprecated. Use findOneAndUpdate, findOneAndReplace or findOneAndDelete instead.
  • Possible duplicate of [DeprecationWarning: collection.findAndModify is deprecated. Use findOneAndUpdate, findOneAndReplace or findOneAndDelete instead?](https://stackoverflow.com/questions/52572852/deprecationwarning-collection-findandmodify-is-deprecated-use-findoneandupdate) – Shashank Vivek Feb 19 '19 at 03:41
  • in this link say that i must put mongoose.set('useNewUrlParser', true); mongoose.set('useFindAndModify', false); mongoose.set('useCreateIndex', true); and :"mongoose.connect(uri, { useNewUrlParser: true });" but it doesn't work – Estivet Giraldo Feb 19 '19 at 20:12

0 Answers0