tRPC
Taking a look inside the ./packages/api/src folder we find something like this:
Each folder corresponds to a set of tRPC procedures that handles one major feature.
Within each subfolder, we find 2-4 .ts files that looks something like this:
- The
router.tsfile contains tRPC procedures that exported via the tRPC router. - The
services.tsfile contains helper functions that are used in the tRPC procedures mentioned above - The files with extension
.test.tscontain tests that run when runningturbo test. See creating tests for more information. - For our tRPC functions, we use Zod to define and validate schemas for input variables at runtime.
We will now go into detail about each individual tRPC procedure.
Dishes
Procedures
dish/get (getDishProcedure)
Queries the dishes table for a dish
- Input:
string(dishId)
dish/rate (RateDishProcedure)
Updates the rating of a given dish when users submit a rating
- Input:
RatingSchema
Services
upsertDish
Attempts to insert one dish entry into the dishes table, along with its NutritionInfo and DietRestrictions. Upon conflict with dishes.id, the old entry is updated with new info.
- Input:
DishWithRelations - Returns upserted dish on success
upsertDishToMenu
Attempts to insert a relation in the dishesToMenu table. Upon conflict with (dishesId, menusId) the old relation is updated.
- Input:
DishToMenu
Events
Procedures
event/upcoming
Queries the events table for all events that are happening today or later.
- Input: None
Services
upsertEvent
Attempts to insert one event entry into the events table. Upon conflict with (events.title, events.start, events.restaurantId), the old entry is updated with new info.
- Input:
Event
upsertEvents
Attempts to insert multiple events into the events table. Upon conflict old entries are updated.
- Input:
DishToMenu - Returns list of successfully upserted events
Menus
Services
upsertMenu
Attempts to insert one menu entry into the menus table. Upon conflict with menus.id, the old entry is updated with new info.
- Input:
Menu
Periods
Services
upsertPeriod
Attempts to insert one period entry into the periods table. Upon conflict with periods.id, the old entry is updated with new info.
- Input:
Period
Ratings
Services
upsertRatings
Attempts to insert one rating entry into the ratings table. Upon conflict with (ratings.userId, ratings.dishId), the old entry is updated with new info.
- Input:
Rating
Restaurants
Services
upsertRestaurant
Attempts to insert one restaurant entry into the restaurants table. Upon conflict with restaurants.id, the old entry is updated with new info.
- Input:
Restaurant
getRestaurantsByDate
Queries the database for information on both restaurants corresponding to a given date.
- Input:
Date - Returns:
ZotmealData
Stations
Services
upsertStation
Attempts to insert one station entry into the stations table. Upon conflict with stations.id, the old entry is updated with new info.
- Input:
Station
Users
Services
getUser
Queries the users table for a user along with their ratings and pins
- Input:
string(userId) - Returns: {
User,Pin[],Rating[]}
upsertUser
Attempts to insert one user entry into the users table. Upon conflict with users.id, the old entry is updated with new info.
- Input:
User
You may also notice there is api/src/server subfolder in this directory. This subfolder contains components relating the the Lambda serverless functions this app performs (see Serverless Functions)