Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require('express');
const mongoose = require('mongoose');
// const usersSchema = import('/models/users');
const User = require('./models/User');
const Booking = require('./models/Booking')
require('dotenv').config()
const app = express();
const port = process.env.PORT || 5001;
Expand Down Expand Up @@ -63,6 +64,46 @@ app.get('/users', (req, res) => {

//sherin - end

//Taylor - begin

//endpoint for new booking - gonna need to bind this into a form once we have the react side up and running

app.get('/bookings', (req, res) => {
Bookings.find({})
.then(docs => res.send(docs))
.catch(err => res.send(err))
})

app.post('/bookings/new', (req, res) => {
const {
term,
week,
day,
block_start,
block_end,
approval_pending,
booked_by,
location,
instrument
} = req.body;

const booking = new Booking({
term,
week,
day,
block_start,
block_end,
approval_pending,
booked_by,
location,
instrument
});

booking.save()
.then(res.send(booking));
});

//Taylor End

app.get('/', (req, res) => {
res.send('hi from api');
Expand Down
16 changes: 16 additions & 0 deletions api/models/Booking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const mongoose = require('mongoose');
const schema = mongoose.Schema;

const bookingSchema = new schema({
term = String,
week = String,
day = String,
block_start = Number,
block_end = Number,
approval_pending = Boolean,
booked_by = String,
location = String,
instrument = String
})

module.exports = mongoose.model('bookings', bookingSchema);