-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
240 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,5 @@ | ||
# Restaurant Reservation Backend Application | ||
# Capstone: Restaurant Reservation System Backend | ||
|
||
This starter code for the backend of the capstone project in the Thinkful curriculum. | ||
|
||
## Existing files | ||
|
||
As you work through the Node.js, Express & PostgreSQL module, you will be writing code that allows your controllers to connect to and query your PostgreSQL database via [Knex](http://knexjs.org/). The table below describes the files and folders in the starter code: | ||
|
||
| Folder/file path | Description | | ||
| ---------------- | -------------------------------------------------------------------------------- | | ||
| `src/app.js` | Directs requests to the appropriate routers. | | ||
| `src/server.js` | Starts the server on `localhost:5000` by default. | | ||
| `src/db/` | A folder where you will add migration and seed files for your database later on. | | ||
| `src/errors/` | A folder where you will find several functions for handle various errors | | ||
| `.env.sample` | A sample environment configuration file | | ||
|
||
This starter code closely follows the best practices and patterns established in the Robust Server Structure module. | ||
|
||
## Database setup | ||
|
||
1. Set up three new ElephantSQL database instance - development, test, and production - by following the instructions in the "PostgreSQL: Creating & Deleting Databases" checkpoint. | ||
1. After setting up your database instances, connect DBeaver to your new database instances by following the instructions in the "PostgreSQL: Installing DBeaver" checkpoint. | ||
|
||
## Installation | ||
|
||
1. Fork and clone this repository. | ||
1. Run `cp .env.sample .env`. | ||
1. Update your `.env` file with a connection URL to your ElephantSQL database instance. | ||
1. Run `npm install` to install project dependencies. | ||
1. Run `npm run start:dev` to start your server in development mode. | ||
|
||
If you have trouble getting the server to run, reach out for assistance. | ||
See [../README.md](../README.md) for detailed instructions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# Capstone: Restaurant Reservation System Frontend | ||
|
||
Used by restaurant personnel when a customer calls to request a reservation. | ||
No online access by the customer at this point. | ||
This starter code for the backend of the capstone project in the Thinkful curriculum. | ||
|
||
There are no user stories for deployment, it is expected that you will deploy the application to production after you finish a user story. | ||
See [../README.md](../README.md) for detailed instructions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
const dateFormat = /\d\d\d\d-\d\d-\d\d/; | ||
const timeFormat = /\d\d:\d\d/; | ||
|
||
/** | ||
* Formats a Date object as YYYY-MM-DD. | ||
* | ||
* This function is *not* exported because the UI should generally avoid working directly with Date instance. | ||
* You may export this function if you need it. | ||
* | ||
* @param date | ||
* an instance of a date object | ||
* @returns {string} | ||
* the specified Date formatted as YYYY-MM-DD | ||
*/ | ||
function asDateString(date) { | ||
return `${date.getFullYear().toString(10)}-${(date.getMonth() + 1) | ||
.toString(10) | ||
.padStart(2, "0")}-${date.getDate().toString(10).padStart(2, "0")}`; | ||
} | ||
|
||
/** | ||
* Format a date string in ISO-8601 format (which is what is returned from PostgreSQL) as YYYY-MM-DD. | ||
* @param dateString | ||
* ISO-8601 date string | ||
* @returns {*} | ||
* the specified date string formatted as YYYY-MM-DD | ||
*/ | ||
export function formatAsDate(dateString) { | ||
return dateString.match(dateFormat)[0]; | ||
} | ||
|
||
/** | ||
* Format a time string in HH:MM:SS format (which is what is returned from PostgreSQL) as HH:MM. | ||
* @param timeString | ||
* HH:MM:SS time string | ||
* @returns {*} | ||
* the specified time string formatted as YHH:MM. | ||
*/ | ||
export function formatAsTime(timeString) { | ||
return timeString.match(timeFormat)[0]; | ||
} | ||
|
||
/** | ||
* Today's date as YYYY-MM-DD. | ||
* @returns {*} | ||
* the today's date formatted as YYYY-MM-DD | ||
*/ | ||
export function today() { | ||
return asDateString(new Date()); | ||
} | ||
|
||
/** | ||
* Subtracts one day to the specified date and return it in as YYYY-MM-DD. | ||
* @param currentDate | ||
* a date string in YYYY-MM-DD format (this is also ISO-8601 format) | ||
* @returns {*} | ||
* the date one day prior to currentDate, formatted as YYYY-MM-DD | ||
*/ | ||
export function previous(currentDate) { | ||
const date = new Date(...currentDate.split("-")); | ||
date.setMonth(date.getMonth() - 1); | ||
date.setDate(date.getDate() - 1); | ||
return asDateString(date); | ||
} | ||
|
||
/** | ||
* Adds one day to the specified date and return it in as YYYY-MM-DD. | ||
* @param currentDate | ||
* a date string in YYYY-MM-DD format (this is also ISO-8601 format) | ||
* @returns {*} | ||
* the date one day after currentDate, formatted as YYYY-MM-DD | ||
*/ | ||
export function next(currentDate) { | ||
const date = new Date(...currentDate.split("-")); | ||
date.setMonth(date.getMonth() - 1); | ||
date.setDate(date.getDate() + 1); | ||
return asDateString(date); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
const dateFormat = /\d\d\d\d-\d\d-\d\d/; | ||
import { formatAsDate } from "./date-time"; | ||
|
||
function formatReservationDate(reservations = []) { | ||
/** | ||
* Formats the reservation_date property for each reservation in an array of reservations. | ||
* @param reservations | ||
* @returns {[reservation]} | ||
* the specified reservations array with each reservation_date property formatted as YYYY-MM-DD. | ||
*/ | ||
function formatReservationsDate(reservations = []) { | ||
return reservations.map((reservation) => { | ||
reservation.reservation_date = reservation.reservation_date.match( | ||
dateFormat | ||
)[0]; | ||
reservation.reservation_date = formatAsDate(reservation.reservation_date); | ||
return reservation; | ||
}); | ||
} | ||
|
||
module.exports = formatReservationDate; | ||
module.exports = formatReservationsDate; |
Oops, something went wrong.