Constructor
new BookingsModel(id, sessionId, userId, created)
Parameters:
| Name | Type | Description |
|---|---|---|
id |
number | null | Booking identifier. |
sessionId |
string | Session identifier. |
userId |
number | User identifier. |
created |
string | Date | Booking creation timestamp. |
- Source:
Classes
Methods
(async, static) create(booking) → {Promise.<(OkPacket|{affectedRows: 0, duplicate: true})>}
Create a booking with a generated identifier.
Parameters:
| Name | Type | Description |
|---|---|---|
booking |
BookingsModel | Booking to create. |
- Source:
Returns:
Insert result or duplicate marker.
- Type
- Promise.<(OkPacket|{affectedRows: 0, duplicate: true})>
(static) createWithExistingID(booking) → {Promise.<OkPacket>}
Create a booking with a caller-provided identifier.
Parameters:
| Name | Type | Description |
|---|---|---|
booking |
BookingsModel | Booking to create. |
- Source:
Returns:
Database result.
- Type
- Promise.<OkPacket>
(static) delete(id) → {Promise.<OkPacket>}
Delete a booking by its identifier.
Parameters:
| Name | Type | Description |
|---|---|---|
id |
number | Booking identifier. |
- Source:
Returns:
Database result.
- Type
- Promise.<OkPacket>
(static) deleteBySessionId(sessionId) → {Promise.<OkPacket>}
Delete every booking belonging to one session.
Parameters:
| Name | Type | Description |
|---|---|---|
sessionId |
number | Session identifier. |
- Source:
Returns:
Database result.
- Type
- Promise.<OkPacket>
(async, static) existsForSessionUser(sessionId, userId) → {Promise.<boolean>}
Check whether a user already booked a session.
Parameters:
| Name | Type | Description |
|---|---|---|
sessionId |
number | string | Session identifier. |
userId |
number | User identifier. |
- Source:
Returns:
Whether the matching booking exists.
- Type
- Promise.<boolean>
(async, static) getAll() → {Promise.<Array.<BookingsModel>>}
Retrieve all bookings.
- Source:
Returns:
Stored bookings.
- Type
- Promise.<Array.<BookingsModel>>
(async, static) getById(id) → {Promise.<BookingsModel>}
Retrieve a booking by its identifier.
Parameters:
| Name | Type | Description |
|---|---|---|
id |
number | Booking identifier. |
- Source:
Throws:
-
"not found" when no booking matches the identifier.
- Type
- string
Returns:
Matching booking.
- Type
- Promise.<BookingsModel>
(async, static) getBySessionId(sessionId) → {Promise.<Array.<BookingsModel>>}
Retrieve bookings belonging to one session.
Parameters:
| Name | Type | Description |
|---|---|---|
sessionId |
number | Session identifier. |
- Source:
Returns:
The session's bookings.
- Type
- Promise.<Array.<BookingsModel>>
(async, static) getByUserId(userId) → {Promise.<Array.<BookingsModel>>}
Retrieve bookings belonging to one user.
Parameters:
| Name | Type | Description |
|---|---|---|
userId |
number | User identifier. |
- Source:
Returns:
The user's bookings.
- Type
- Promise.<Array.<BookingsModel>>
(static) tableToModel(row) → {BookingsModel}
Convert a database row into a BookingsModel instance.
Parameters:
| Name | Type | Description |
|---|---|---|
row |
Object | Database row. |
- Source:
Returns:
Mapped booking.
- Type
- BookingsModel
(static) update(booking) → {Promise.<OkPacket>}
Update an existing booking.
Parameters:
| Name | Type | Description |
|---|---|---|
booking |
BookingsModel | Booking to update. |
- Source:
Returns:
Database result.
- Type
- Promise.<OkPacket>