Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Add date validation on rentals #127

Closed
4 tasks done
AdamVig opened this issue Mar 18, 2017 · 3 comments
Closed
4 tasks done

Add date validation on rentals #127

AdamVig opened this issue Mar 18, 2017 · 3 comments
Assignees
Milestone

Comments

@AdamVig
Copy link
Collaborator

AdamVig commented Mar 18, 2017

Provides a second line of defense for the same validation in the frontend.

  • Check that startDate is not in the past
  • Check that endDate is after rent date by a preset minimum rental time (also checks that endDate is not in the past)
  • Prevent rentals from being created in the same time span
  • Add error handler for trigger errors to database service
@AdamVig AdamVig added this to the May 9 Sprint milestone May 1, 2017
@AdamVig
Copy link
Collaborator Author

AdamVig commented May 2, 2017

To check that a date is not in the past:
startDate >= current_date()
Source

To check that a date is at least a day after another date:
datediff(endDate, startDate) >= 1
Source

To check that a date span does not conflict with other date spans:

select * from rental
  where returnDate = null
  and not (testStartDate between startDate and endDate)
  and not (testEndDate between startDate and endDate)

Source

@AdamVig AdamVig self-assigned this May 3, 2017
@AdamVig
Copy link
Collaborator Author

AdamVig commented May 3, 2017

Currently blocked on this because Knex.js does not pass through the message from the trigger as its own property on the error object:

code: "ER_SIGNAL_EXCEPTION",
errno: 1644,
index: 0,
sqlState: "45000",
message: "insert into `rental` (`endDate`, `itemID`, `organizationID`, `startDate`, `userID`) values ('2017-05-10', '5', 37, '2017-05-02', 60) - ER_SIGNAL_EXCEPTION: Rental start date must not be in the past"

The message that I want is at the end of the actual message property.

@AdamVig
Copy link
Collaborator Author

AdamVig commented May 6, 2017

Waiting on mysqljs/1714 to be merged. This will add a sqlMessage property containing the message associated with the sqlState, allowing direct pass-through of messages from triggers or procedures to end users.

@AdamVig AdamVig modified the milestones: May 9 Sprint, May 15 Sprint May 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant