Most of our backend api requests are related to users, so before the request function is run, we get the current user from the database and make the user data available in the request and following functions. The problem is that we are passing around the user data in a serialized schema GetUserDto and instead we should be using the pure UserEntity schema/types, for all internal functions. GetUserDto schema should only be used to serialize user data before returning the response, i.e. in the controller
Describe a solution:
Remove user from the request context - we are aiming to use userEntity instead - see FirebaseAuthGuard.tsx and getUserByFirebaseId function in user.service.ts
Replace all uses of req['user'] in controllers, instead using req['userEntity']
Remove all uses of GetUserDto from our functions/service files, instead using UserEntity type
Fix any related issues - running yarn test and yarn lint will help discover issues
You should also run Cypess tests to ensure this doesn't break anything in the frontend.
This is a large issue so you may want to break down into smaller issues
This is the first step (see #454) in improving the maintainability and performance of the API and how it handles users. The cleaner typing will help future contributors understand the code!
Additional context and resources:
Tests may need to be fixed following this update - run to check failing tests
Is your feature request related to a problem?
Most of our backend api requests are related to users, so before the request function is run, we get the current user from the database and make the user data available in the request and following functions. The problem is that we are passing around the user data in a serialized schema
GetUserDto
and instead we should be using the pureUserEntity
schema/types, for all internal functions.GetUserDto
schema should only be used to serialize user data before returning the response, i.e. in the controllerDescribe a solution:
user
from the request context - we are aiming to useuserEntity
instead - see FirebaseAuthGuard.tsx andgetUserByFirebaseId
function in user.service.tsreq['user']
in controllers, instead usingreq['userEntity']
GetUserDto
from our functions/service files, instead usingUserEntity
typeyarn test
andyarn lint
will help discover issuesThis is the first step (see #454) in improving the maintainability and performance of the API and how it handles users. The cleaner typing will help future contributors understand the code!
Additional context and resources:
Tests may need to be fixed following this update - run to check failing tests
Ticket breakdown
547
546
545