Угловые сообщения выборки не работают после того, как mongoose настроен с mongodb

webfreaker спросил: 07 октября 2018 в 12:07 в: angular

Я установил mongoose и mongodb и пытаюсь получить сообщения. что-то идет не так Я подключаюсь к базе данных, но не могу понять это после того, как пытаюсь отправить заказ. Я включил файл app.js и файл post.js ниже. Я использую общую находку, но боюсь, что меня смущает Post и app.js post model и моя модель бронирования. Возможно, я Я путаю некоторые из имен. Я не уверен, потому что я потерян.

const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');const Post = require('./models/post')const app = express();
mongoose.connect("mongodb+srv://john:jdhdhdhsh@cluster0-yusts.mongodb.net/node-angular?retryWrites=true")
.then (() => {
  console.log('connected to db')
})
.catch(() => {
  console.log('connection failed');
});app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false}));app.use((req, res, next) => {
  res.setHeader("Access-Control-Allow-Origin", "*");
  res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  res.setHeader("Access-Control-Allow-Methods", "GET, POST, PATCH, DELETE, OPTIONS");
  next();
});app.post("/api/bookings", (req, res, next) => {
  const booking = new Post({
    bookingDate: req.body.bookingDate,
    agent: req.body.agent,
    agentDepartment: req.body.agentDepartment,
    clientName: req.body.clientName,
    projectTitle: req.body.projectTitle,
    clientService: req.body.clientService,
    rate: req.body.rate,
    perDiem: req.body.perDiem,
    startDate: req.body.startDate,
    endDate: req.body.endDate,
    numberOfEpisodes: req.body.numberOfEpisodes,
    numberOfDays: req.body.numberOfDays,
    credit: req.body.credit,
    location: req.body.location,
    travel: req.body.travel,
    dressingRoom: req.body.dressingRoom,
    lodging: req.body.lodging,
    exclusivity: req.body.exclusivity,
    bumps: req.body.bumps,
    options: req.body.options,
    buyer: req.body.buyer,
    buyerType: req.body.buyerType,
    productionCompany: req.body.productionCompany,
    network: req.body.network,
    accountingName: req.body.accountingName,
    accountingEmail: req.body.accountingEmail,
    notes: req.body.notes
  });
  post.save();
  res.status(201).json({
    message: 'Booking added succesfully!'
  });
});app.get('/api/bookings',(req, res, next) => {
  Post.find().then(documents => {
    res.status(200).json({
      message: 'booking fetched successfully!',
      posts: documents
    });
  });
});module.exports = app;const mongoose = require('mongoose');const postSchema = mongoose.Schema({
  bookingDate: {type: Date, required: true },
    agent: {type: String, required: true },
    agentDepartment: {type: String, required: true },
    clientName: {type: String, required: true },
    projectTitle: {type: String, required: true },
    clientService: {type: String, required: true },
    rate: {type: String, required: true },
    perDiem: {type: String },
    startDate: {type: Date },
    endDate: {type: Date },
    numberOfEpisodes: {type: String },
    numberOfDays: {type: String },
    credit: {type: String },
    location: {type: String },
    travel: {type: String },
    dressingRoom: {type: String },
    lodging: {type: String },
    exclusivity: {type: String },
    bumps: {type: String },
    options: {type: String },
    buyer: {type: String },
    buyerType: {type: String },
    productionCompany: {type: String },
    network: {type: String },
    accountingName: {type: String },
    accountingEmail: {type: String },
    notes: {type: String, default: Date.now }
});module.exports = mongoose.model('Post', postSchema);

0 ответов