У меня есть метод post на api nodejs и клиентское приложение на angular, когда я тестирую метод post на почтальоне, эта работа, но когда я отправляю данные из клиентского приложения, это не работает:
это мой код 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;
и это мой сервис на 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});
}
}
когда я выполняю этот сервис, появляется эта ошибка на консолина сервере:
(node:11340) DeprecationWarning: collection.findAndModify is deprecated. Use findOneAndUpdate, findOneAndReplace or findOneAndDelete instead.