Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

US01 + Dashboard Table #194

Closed
wants to merge 14 commits into from
2 changes: 2 additions & 0 deletions back-end/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ const cors = require("cors");
const errorHandler = require("./errors/errorHandler");
const notFound = require("./errors/notFound");
const reservationsRouter = require("./reservations/reservations.router");
const tablesRouter = require("./tables/tables.router")

const app = express();

app.use(cors());
app.use(express.json());

app.use("/reservations", reservationsRouter);
app.use("/tables", tablesRouter);

app.use(notFound);
app.use(errorHandler);
Expand Down
22 changes: 22 additions & 0 deletions back-end/src/db/migrations/20230510185048_updateReservations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

exports.up = function(knex) {
return knex.schema.alterTable("reservations", (table) => {
table.string("first_name")
table.string("last_name")
table.string("mobile_number")
table.date("reservation_date")
table.time("reservation_time")
table.integer("people")
});
};

exports.down = function(knex) {
return knex.schema.alterTable("reservations", (table) => {
table.dropColumn("first_name")
table.dropColumn("last_name")
table.dropColumn("mobile_number")
table.dropColumn("reservation_date")
table.dropColumn("reservation_time")
table.dropColumn("people")
});
};
12 changes: 12 additions & 0 deletions back-end/src/db/migrations/20230516181649_createTables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
exports.up = function(knex) {
return knex.schema.createTable("tables", (table) => {
table.increments("table_id").primary();
table.string("table_name");
table.integer("capacity");
table.timestamps(true, true);
});
};

exports.down = function(knex) {
return knex.schema.dropTable("tables");
};
12 changes: 12 additions & 0 deletions back-end/src/db/migrations/20230517134649_tableStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

exports.up = function(knex) {
return knex.schema.alterTable("tables", (table) => {
table.string("status").defaultTo('Free')
});
};

exports.down = function(knex) {
return knex.schema.alterTable("tables", (table) => {
table.dropColumn("status")
});
};
13 changes: 13 additions & 0 deletions back-end/src/db/migrations/20230518171903_tableResStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

exports.up = function(knex) {
return knex.schema.alterTable("tables", (table) => {
table.integer("reservation_id")
table.foreign("reservation_id").references("reservation_id").inTable("reservations")
});
};

exports.down = function(knex) {
return knex.schema.alterTable("tables", (table) => {
table.dropColumn("reservation_id")
});
};
12 changes: 12 additions & 0 deletions back-end/src/db/migrations/20230521182006_reservationStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

exports.up = function(knex) {
return knex.schema.alterTable("reservations", (table) => {
table.string("status").defaultTo("booked")
})
};

exports.down = function(knex) {
return knex.schema.alterTable("reservations", (table) => {
table.dropColumn("status")
})
};
59 changes: 57 additions & 2 deletions back-end/src/db/seeds/00-reservations.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,58 @@
exports.seed = function (knex) {
return knex.raw("TRUNCATE TABLE reservations RESTART IDENTITY CASCADE");
exports.seed = function(knex) {
// Deletes ALL existing entries
return knex.raw("TRUNCATE TABLE reservations RESTART IDENTITY CASCADE")
.then(function () {
// Inserts seed entries
return knex('reservations').insert([
{
"first_name": "Rick",
"last_name": "Sanchez",
"mobile_number": "202-555-0164",
"reservation_date": "2020-12-31",
"reservation_time": "20:00:00",
"people": 6,
"created_at": "2020-12-10T08:30:32.326Z",
"updated_at": "2020-12-10T08:30:32.326Z"
},
{
"first_name": "Frank",
"last_name": "Palicky",
"mobile_number": "202-555-0153",
"reservation_date": "2020-12-30",
"reservation_time": "20:00",
"people": 1,
"created_at": "2020-12-10T08:31:32.326Z",
"updated_at": "2020-12-10T08:31:32.326Z"
},
{
"first_name": "Bird",
"last_name": "Person",
"mobile_number": "808-555-0141",
"reservation_date": "2020-12-30",
"reservation_time": "18:00",
"people": 1,
"updated_at": "2020-12-10T08:31:32.326Z"
},
{
"first_name": "Tiger",
"last_name": "Lion",
"mobile_number": "808-555-0140",
"reservation_date": "2025-12-30",
"reservation_time": "18:00",
"people": 3,
"created_at": "2020-12-10T08:31:32.326Z",
"updated_at": "2020-12-10T08:31:32.326Z"
},
{
"first_name": "Anthony",
"last_name": "Charboneau",
"mobile_number": "620-646-8897",
"reservation_date": "2026-12-30",
"reservation_time": "18:00",
"people": 2,
"created_at": "2020-12-10T08:31:32.326Z",
"updated_at": "2020-12-10T08:31:32.326Z"
}
]);
});
};
14 changes: 14 additions & 0 deletions back-end/src/db/seeds/tables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

exports.seed = function(knex) {
// Deletes ALL existing entries
return knex.raw("TRUNCATE TABLE tables RESTART IDENTITY CASCADE")
.then(function () {
// Inserts seed entries
return knex('tables').insert([
{table_name: 'Bar #1', capacity: 1, status: "Free"},
{table_name: 'Bar #2', capacity: 1, status: "Free"},
{table_name: '#1', capacity: 6, status: "Free"},
{table_name: '#2', capacity: 6, status: "Free"},
]);
});
};
16 changes: 16 additions & 0 deletions back-end/src/errors/asyncErrorBoundary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function asyncErrorBoundary(delegate, defaultStatus ) {
return (request, response, next) => {
Promise.resolve()
.then(() => delegate(request, response, next))
.catch((error) => {
const { status = defaultStatus, message = error } = error || {};
next({
status,
message,
});
});
};
}

module.exports = asyncErrorBoundary

9 changes: 9 additions & 0 deletions back-end/src/errors/methodNotAllowed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function methodNotAllowed(req, res, next) {
next({
status: 405,
message: `${req.method} not allowed for ${req.originalUrl}`,
});
}

module.exports = methodNotAllowed;

Loading