Skip to content

Commit

Permalink
5, 6
Browse files Browse the repository at this point in the history
  • Loading branch information
NolaDodd committed Jun 4, 2024
1 parent 7c9c044 commit a7a04a7
Show file tree
Hide file tree
Showing 17 changed files with 844 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ exports.up = function (knex) {
table.date("reservation_date")
table.time("reservation_time")
table.integer("people")
table.string("status")
table.timestamps(true, true);
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ exports.up = function(knex) {
table.increments("table_id").primary();
table.string("table_name")
table.integer("capacity")
table.integer("reservation_id")
table.foreign("reservation_id")
.references("reservation_id")
.inTable("reservations")
table.timestamps(true, true);
});
};

exports.down = function(knex) {
return knex.schema.dropTable("tables")
.then(() => console.log("Dropped Table Table"))
.then(() => console.log("Dropped Tables Table"))
};
97 changes: 92 additions & 5 deletions back-end/src/db/seeds/00-reservations.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"reservation_date": "2020-12-31",
"reservation_time": "20:00:00",
"people": 6,
"status": "Booked",
"created_at": "2020-12-10T08:30:32.326Z",
"updated_at": "2020-12-10T08:30:32.326Z"
},
Expand All @@ -16,6 +17,7 @@
"reservation_date": "2020-12-30",
"reservation_time": "20:00",
"people": 1,
"status": "Booked",
"created_at": "2020-12-10T08:31:32.326Z",
"updated_at": "2020-12-10T08:31:32.326Z"
},
Expand All @@ -26,6 +28,7 @@
"reservation_date": "2020-12-30",
"reservation_time": "18:00",
"people": 1,
"status": "Booked",
"created_at": "2020-12-10T08:31:32.326Z",
"updated_at": "2020-12-10T08:31:32.326Z"
},
Expand All @@ -36,6 +39,7 @@
"reservation_date": "2025-12-30",
"reservation_time": "18:00",
"people": 3,
"status": "Booked",
"created_at": "2020-12-10T08:31:32.326Z",
"updated_at": "2020-12-10T08:31:32.326Z"
},
Expand All @@ -46,57 +50,140 @@
"reservation_date": "2026-12-30",
"reservation_time": "18:00",
"people": 2,
"status": "Booked",
"created_at": "2020-12-10T08:31:32.326Z",
"updated_at": "2020-12-10T08:31:32.326Z"
},
{
"first_name": "Clark",
"last_name": "Kent",
"mobile_number": "620-346-4852",
"reservation_date": "2024-05-30",
"reservation_date": "2024-05-31",
"reservation_time": "18:00",
"people": 2,
"status": "Booked",
"created_at": "2024-05-29T08:31:32.326Z",
"updated_at": "2024-05-29T08:31:32.326Z"
},
{
"first_name": "Bruce",
"last_name": "Wayne",
"mobile_number": "212-453-4792",
"reservation_date": "2024-05-31",
"reservation_date": "2024-06-01",
"reservation_time": "13:00",
"people": 1,
"status": "Booked",
"created_at": "2024-05-29T08:31:32.326Z",
"updated_at": "2024-05-29T08:31:32.326Z"
},
{
"first_name": "Peter",
"last_name": "Parker",
"mobile_number": "215-147-9053",
"reservation_date": "2024-06-01",
"reservation_date": "2024-06-02",
"reservation_time": "10:40",
"people": 4,
"status": "Booked",
"created_at": "2024-05-29T08:31:32.326Z",
"updated_at": "2024-05-29T08:31:32.326Z"
},
{
"first_name": "Diana",
"last_name": "Prince",
"mobile_number": "808-333-4819",
"reservation_date": "2024-06-02",
"reservation_date": "2024-06-03",
"reservation_time": "14:00",
"people": 3,
"status": "Booked",
"created_at": "2024-05-29T08:31:32.326Z",
"updated_at": "2024-05-29T08:31:32.326Z"
},
{
"first_name": "Mickey",
"last_name": "Mouse",
"mobile_number": "714-222-2468",
"reservation_date": "2024-06-03",
"reservation_date": "2024-06-04",
"reservation_time": "12:00",
"people": 6,
"status": "Booked",
"created_at": "2024-05-29T08:31:32.326Z",
"updated_at": "2024-05-29T08:31:32.326Z"
},
{
"first_name": "Bugs",
"last_name": "Bunny",
"mobile_number": "714-808-5623",
"reservation_date": "2024-06-05",
"reservation_time": "14:00",
"people": 5,
"status": "Booked",
"created_at": "2024-06-01T08:31:32.326Z",
"updated_at": "2024-06-01T08:31:32.326Z"
},
{
"first_name": "Daffy",
"last_name": "Duck",
"mobile_number": "714-238-1167",
"reservation_date": "2024-06-05",
"reservation_time": "15:00",
"people": 1,
"status": "Booked",
"created_at": "2024-06-01T08:31:32.326Z",
"updated_at": "2024-06-01T08:31:32.326Z"
},
{
"first_name": "Mario",
"last_name": "Luigi",
"mobile_number": "714-808-5623",
"reservation_date": "2024-06-06",
"reservation_time": "11:00",
"people": 2,
"status": "Booked",
"created_at": "2024-06-01T08:31:32.326Z",
"updated_at": "2024-06-01T08:31:32.326Z"
},
{
"first_name": "Ninja",
"last_name": "Turtles",
"mobile_number": "714-808-5623",
"reservation_date": "2024-06-06",
"reservation_time": "16:00",
"people": 4,
"status": "Booked",
"created_at": "2024-06-01T08:31:32.326Z",
"updated_at": "2024-06-01T08:31:32.326Z"
},
{
"first_name": "Barbie",
"last_name": "Ken",
"mobile_number": "205-900-1093",
"reservation_date": "2024-06-07",
"reservation_time": "12:00",
"people": 2,
"status": "Booked",
"created_at": "2024-06-01T08:31:32.326Z",
"updated_at": "2024-06-01T08:31:32.326Z"
},
{
"first_name": "Elle",
"last_name": "Woods",
"mobile_number": "808-356-1276",
"reservation_date": "2024-06-07",
"reservation_time": "18:00",
"people": 10,
"status": "Booked",
"created_at": "2024-06-01T08:31:32.326Z",
"updated_at": "2024-06-01T08:31:32.326Z"
},
{
"first_name": "Indiana",
"last_name": "Jones",
"mobile_number": "750-547-0378",
"reservation_date": "2024-06-08",
"reservation_time": "15:00",
"people": 4,
"status": "Booked",
"created_at": "2024-06-01T08:31:32.326Z",
"updated_at": "2024-06-01T08:31:32.326Z"
}
]
12 changes: 8 additions & 4 deletions back-end/src/db/seeds/01-tables.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
[
{
"table_name": "Bar #1",
"capacity": 1
"capacity": 1,
"reservation_id": null
},
{
"table_name": "Bar #2",
"capacity": 1
"capacity": 1,
"reservation_id": null
},
{
"table_name": "#1",
"capacity": 6
"capacity": 6,
"reservation_id": null
},
{
"table_name": "#2",
"capacity": 6
"capacity": 6,
"reservation_id": null
}
]
66 changes: 54 additions & 12 deletions back-end/src/reservations/reservations.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const moment = require("moment-timezone")

async function list(req, res, next) {
const {date} = req.query
console.log("list date", date)
let reservations

if (date){
Expand All @@ -31,7 +30,7 @@ async function create (req, res){
}

function correctTimesOnly(req, res, next){
const {data} = req.body // Define 'data' here
const {data = {}} = req.body

// Parse the reservation date and time in the server's time zone
const reservationDateTime = moment.tz(`${data.reservation_date}T${data.reservation_time}`, 'America/Los_Angeles');
Expand All @@ -58,21 +57,19 @@ function correctTimesOnly(req, res, next){
}




async function read(req, res){
const data = res.locals.reservation_id
const data = res.locals.reservation
res.json({data})
}

function reservationExists(req, res, next){
service.read(req.params.reservation_id)
service.read(req.params.reservationId)
.then((reservation) => {
if(reservation){
res.locals.reservation = reservation
return next()
}
next({status: 404, message: 'Reservation cannot be found'})
next({status: 404, message: `Reservation ${req.params.reservationId} cannot be found`})
})
.catch(next)
}
Expand All @@ -89,15 +86,15 @@ function propertiesExist(req, res, next){
return next({status: 400, message: "Data is required"});
}

const { first_name, last_name, mobile_number, reservation_date, reservation_time, people } = data;
const { first_name, last_name, mobile_number, reservation_date, reservation_time, status, people } = data;

console.log(data);
console.log("propertiesExist", data);

if (!first_name || first_name === ""){
if (!first_name || first_name.trim() === ""){
return next({status: 400, message: "Reservation must include a first_name"});
}

if (!last_name || last_name === ""){
if (!last_name || last_name.trim() === ""){
return next({status: 400, message: "Reservation must include a last_name"});
}

Expand All @@ -121,9 +118,54 @@ function propertiesExist(req, res, next){
}


async function updateStatus(req, res, next){
const updatedReservation = {
...req.body.data,
reservation_id: res.locals.reservation.reservation_id,
}

const data = await service.updateStatus(updatedReservation)
console.log("status Updated", data)

res.status(200).json({data: data[0]})
}

function reservationStatusCheck(req, res, next){
const { data = {} } = req.body;

if (Object.keys(data).length === 0){
return next({status: 400, message: "Data is required"});
}

const { first_name, last_name, mobile_number, reservation_date, reservation_time, status, people } = data;

console.log("reservationStatusCheck", data);
const validStatus = ["booked", "seated"]

if (status.toLowerCase() === "seated" || status.toLowerCase() === "finished"){
return next({status: 400, message: "Reservation status cannot be `seated` or `finished`."})
}

if (status.toLowerCase() === "finished"){
return next({status: 400, message: "This reservation is already finished and cannot be updated"})
}

if (!status || status === undefined || status === null){
return next({status: 400, message: "The reservation status is missing"})
}

if (!validStatus.includes(status.toLowerCase())){
return next({status: 400, message: "This reservation status is unknown and must be a valid status."})
}

next();
}



module.exports = {
list: [asyncErrorBoundary(list)],
create: [propertiesExist, correctTimesOnly, asyncErrorBoundary(create)],
read: [asyncErrorBoundary(read)]
read: [reservationExists, asyncErrorBoundary(read)],
updateStatus: [reservationExists, reservationStatusCheck, asyncErrorBoundary(updateStatus)]
};
8 changes: 8 additions & 0 deletions back-end/src/reservations/reservations.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ router.route("/")
.post(controller.create)
.all(methodNotAllowed)

router.route("/:reservationId")
.get(controller.read)
.all(methodNotAllowed)

router.route("/:reservationId/status")
.put(controller.updateStatus)
.all(methodNotAllowed)

module.exports = router;
Loading

0 comments on commit a7a04a7

Please sign in to comment.