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

implement booking history collections #735

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion server/src/data-layer/adapters/FirestoreCollections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import "dotenv/config"
import {
Booking,
BookingHistoryEvent,
BookingSlot,
UserAdditionalInfo
} from "data-layer/models/firebase"
Expand Down Expand Up @@ -29,7 +30,8 @@ const firestore = Object.assign(
const db = {
users: firestore.collection<UserAdditionalInfo>("users"),
bookings: firestore.collection<Booking>("bookings"),
bookingSlots: firestore.collection<BookingSlot>("booking_slots")
bookingSlots: firestore.collection<BookingSlot>("booking_slots"),
bookingHistory: firestore.collection<BookingHistoryEvent>("booking_history")
} as const

export default db
87 changes: 87 additions & 0 deletions server/src/data-layer/models/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,90 @@ export interface Event {
*/
max_occupancy?: number
}

/**
* Base type to be able to log events that admins perform on booking related resources in the admin view
*/
interface BookingHistory {
/**
* The time which the booking operation was performed. MUST be in UTC format
*/
timestamp: Timestamp

/**
* The start of the operated on date range
*/
start_date: Timestamp

/**
* The end of the operated on date range
*/
end_date: Timestamp

/**
* The type of event that the admin performed, used for parsing on the front-end
*
* Each of these are associated with the following:
*
* - `"added_user_to_booking"`: {@link BookingAddedEvent}
* - `"removed_user_from_booking"`: {@link BookingDeletedEvent}
* - `"changed_date_availability"`: {@link BookingAvailabilityChangeEvent}
*/
event_type:
| "added_user_to_booking"
| "removed_user_from_booking"
| "changed_date_availability"
}

/**
* Event used to track a user being **manually** added to a booking (only possible via admin view)
*
* @extends BookingHistory {@link BookingHistory}
*/
export interface BookingAddedEvent extends BookingHistory {
/**
* The id corresponding to the user who had a **manually** added booking
*/
uid: string
event_type: "added_user_to_booking"
}

/**
* Event used to track the removal of a user from a date range (only possible via admin view)
*
* @extends BookingHistory {@link BookingHistory}
*/
export interface BookingDeletedEvent extends BookingHistory {
/**
* The id corresponding to the user who had a **manually** deleted booking
*/
uid: string
event_type: "removed_user_from_booking"
}

/**
* Event used to track the history of the availability of dates changing
*
* @extends BookingHistory {@link BookingHistory}
*/
export interface BookingAvailabilityChangeEvent extends BookingHistory {
/**
* The **signed** difference between the newly available slots and the previously available slots.
*
* For example, if the original available slots was 32, and the availability was set to 0,
* the `change` in the slots needs to be **0 - 32 = -32**
*
* And vice versa, if the original available slots was 16, and the availability was set to 32,
* the `change` would be **32 - 16 = 16**
*/
change: number
event_type: "changed_date_availability"
}

/**
* Helper type to specify the possible datastruces for the booking history
*/
export type BookingHistoryEvent =
| BookingAddedEvent
| BookingDeletedEvent
| BookingAvailabilityChangeEvent
Loading