-
Notifications
You must be signed in to change notification settings - Fork 2
Backend Architecture
We will be using express as the main framework and tsoa as a framework to abstract away some manual processes such as:
- Route creation (All done in controllers)
- Authentication middleware
- Request validation
- Documentation (Done through annotations)
This means that for the backend we will need to focus on writing:
response-models
: Typescript interfaces which describe what response data will be returned
request-models
: Typescript interfaces which describe what data is expected in the request
models
of DTOs
: Typescript interfaces which describe the shape of data
services
: Typescript classes which perform operations that are consumed by controllers
controllers
: Typescript classes annotated using tsoa to describe the behavior of routes
Please be aware that ALL dates should be stored as UTC midnight - i.e if you want to store the date 27/04/2022
you must first remove the local timezone offset and then set the time to exactly midnight on every level of precision.
Due to the way readonly props are serialized, the nanoseconds
and seconds
fields in Timestamp
are prefixed with an underscore (_
) keep this in mind when writing tests etc.
Please also be aware that timestamps converted from dates may not have their helper functions that some Firestore functionalities requires. Timestamp.fromDate
is a safe way to ensure that the timestamps are correct.
We have booking_slots
which refer to the date and has a max_bookings
. The way we calculate the availability is:
- check how many slots there are in the bookings collection - which refers to individual bookings made, no date data is stored in there, instead it has a field that refers to an id of a
booking_slot
- the available slots for a
booking_slot
is: themax_bookings
minus the amount of bookings pointing to abooking_slot
in case of displaying availability to the user we also minus off the amount of checkout sessions that have thatbooking_slot
's id in its metadata - The way we use this with stripe is when we create a checkout session we add an array of dates pointing to the
booking_slot
id (serialised as a string withJSON.stringify
) to the metadata.