Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Session = require("../models/Session");
- module.exports = {
- async index(req, res) {
- const sessions = await Session.find();
- return res.json(sessions);
- },
- async store(req, res) {
- const { movie, desc, day, hour } = req.body;
- const session = await Session.create({
- movie,
- desc,
- day,
- hour
- });
- return res.json(session);
- }
- };
- const mongoose = require("mongoose");
- const SessionSchema = new mongoose.Schema({
- movie: String,
- desc: String,
- day: String,
- hour: String
- });
- module.exports = mongoose.model("Session", SessionSchema);
- const Theater = require("../models/Theater");
- const Session = require("../models/Session");
- module.exports = {
- async index(req, res) {
- const theaters = await Theater.find();
- return res.json(theaters);
- },
- async store(req, res) {
- const { session_id } = req.params;
- const { name, city } = req.body;
- const theater = await Theater.create({
- session: session_id,
- name,
- city
- });
- await theater.populate("session").execPopulate();
- return res.json(theater);
- }
- };
- const mongoose = require("mongoose");
- const TheaterSchema = new mongoose.Schema(
- {
- name: String,
- city: String,
- session: {
- type: mongoose.Schema.Types.ObjectId,
- ref: "Session"
- }
- },
- {
- toJSON: {
- virtuals: true
- }
- }
- );
- module.exports = mongoose.model("Theater", TheaterSchema);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement