Closed AdamVig closed 7 years ago
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)
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.
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.
Provides a second line of defense for the same validation in the frontend.
startDate
is not in the pastendDate
is after rent date by a preset minimum rental time (also checks thatendDate
is not in the past)